Commit Graph

31 Commits

Author SHA1 Message Date
Casey Dahlin
60b4980753 Revert "Add support for dynamic commands"
This was meant to go to a pull request, not straight on to master.

This reverts commit 997ea521c4.
2022-05-16 22:50:53 -07:00
Casey Dahlin
997ea521c4 Add support for dynamic commands
This patch adds support for commands which the parser may not know about
until runtime. This could be useful if we'd like to discover subcommands
at runtime, e.g. we're using a plugin system and have to enumerate our
plugin repository to know what commands are available.
2022-05-16 22:47:28 -07:00
Erick Tryzelaar
8a7319a9b4 Fix clippy lints; return errors rather than panic
This cleans up clippy lints, both in the library itself, and in the
generated code. As part of this change, it changes a few locations where
we would have panicked on values passed in by the user to instead return
an error.

However, I left one place that unwraps in the generated code. After we have
parsed all the arguments, we check that all of the required arguments. If
not, we return an error. It's unfortunately a little difficult to prove
to rust that we've handled all the arguments. I left the unwrap()s in place
in case there's a logic error we have in handling this, and annotated the
code with `#[allow(clippy::unwrap_in_result)]` to allow for this case.

Closes #114
2021-12-15 15:32:50 -05:00
Erick Tryzelaar
5676ea11fe Fix redacting Vec<T> options
This changes argh_derive to handle redacting types like:

```
struct Cmd {
    #[argh(option)]
    /// fooey
    arg: Vec<String>,
}
```

Fixes #111
2021-12-08 13:49:23 -05:00
Erick Tryzelaar
3a363a6ae4 Use arg_name for redacted positionals
This changes redacted positional arguments from using the field name to
using the arg name. This allows the field name to be changed without
impacting the redaction.

In addition, this fixes all the outstanding warnings.
2021-12-08 13:49:23 -05:00
Amin Yahyaabadi
4f7f8918f1 Print help for positional arguments 2021-12-07 13:42:41 -05:00
Leonardo Razovic
1e71aa1e4b Remove unneeded into 2021-09-02 11:37:13 -07:00
Leonardo Razovic
1f86793fad Remove unneeded clone 2021-09-02 11:37:13 -07:00
Erick Tryzelaar
00a3542c89 Revert back to using license
I didn't realize that `license-file` was for nonstandard licenses.

Closes #101
2021-09-02 07:42:04 -07:00
Erick Tryzelaar
4680f75a89 Prepping for release 2021-09-02 07:42:04 -07:00
Kafji
617fb6ff20 Make positional arg honor arg_name 2021-08-30 16:55:06 -07:00
Otavio Salvador
e4ce5d2f3e Use std::result::Result to avoid expanding to type aliases
Fixes: #97
Signed-off-by: Otavio Salvador <otavio@ossystems.com.br>
2021-08-20 10:57:44 -07:00
Erick Tryzelaar
329890897a Use license-file to point at license 2021-07-08 11:02:05 -07:00
Erick Tryzelaar
0b0d80a4a7 Format with rustfmt 1.4.37-stable (2a3635d5 2021-05-04) 2021-07-08 11:02:05 -07:00
Erick Tryzelaar
ea19834969 Prep for release
This patch:

* Converts argh into using a workspace
* Moves `argh` files into `argh/`.
* Changes each crate to include the license and README.md
2021-07-08 11:02:05 -07:00
Erick Tryzelaar
d98b6be239 Address comments
* Renames some functions
* Flesh out docstrings for `from_args` and `redact_arg_values`
* Rename `<<<arg0>>>` to `program-name`
2021-07-07 17:06:39 -07:00
Erick Tryzelaar
4ddfde0f1b Rename FromArgs::redact to FromArgs::redact_arg_values 2021-07-07 17:06:39 -07:00
Erick Tryzelaar
99cacc08d9 Use short names when redacting 2021-07-07 17:06:39 -07:00
Erick Tryzelaar
ad3d91a653 Add support for redacting command line arguments
This enables safe analytics tracking of command-line arguments while
redacting user-specified values.
2021-07-07 17:06:39 -07:00
Erick Tryzelaar
40b10fcdc0 Migrate core struct parsing to argh
This moves much of the functionality that used to be defined in
the derived `FromArgs::from_args` and into a shared function. This helps
to shave off some shared code.
2021-07-07 17:06:39 -07:00
Mikhail Katychev
8a7f939c05 added arg_name override 2021-04-12 12:29:55 -07:00
Eli Lipsitz
dffc91d430 Don't process '--help' after option delimiter '--'
The option `--` acts as an "option delimiter" -- all arguments
which come after that point are treated as position arguments,
even if they begin with `-`. This functionality was added in #60.

However, there was a slight issue. Because the `--help` flag is
parsed separately from the rest of the arguments, `--help` would
trigger the early-exit help message, even after `--`.
2021-04-12 12:26:08 -07:00
Erick Tryzelaar
66e44a7acd Add myself to more authors lists 2020-10-27 11:15:44 -07:00
Erick Tryzelaar
c2fc87d8da Bump versions to 0.1.4 2020-10-27 11:12:18 -07:00
Eli Lipsitz
9022148be9 Add support for option delimiter "--"
Following the Fuchsia CLI Tool Rubric
(https://fuchsia.dev/fuchsia-src/concepts/api/cli#option_delimiter),
this adds support for "--", which denotes the end of the options list.
All arguments that come after this point will be treated as positional,
even if they begin with "-".

Closes #58. Closes #59.
2020-10-06 16:56:17 -07:00
Ben Brittain
5b0c45fdd4 Allow kebab-case in long names 2020-07-11 11:00:33 -04:00
Ben Brittain
e59f2c8c78 fix default value error message 2020-06-28 10:56:17 -04:00
Benjamin Brittain
7dff45baae correct Cargo.toml license field 2020-01-31 09:13:07 -05:00
Benjamin Brittain
23293d9937 add LICENSE to sub-crates
Updates cargo.toml to use SPDX identifiers
2020-01-31 09:02:48 -05:00
Benjamin Brittain
cef9a6b7d8 pin versions 2020-01-31 08:56:54 -05:00
Benjamin Brittain
c752b5f504 Migrate code into into stand-alone repo
Adds Cargo.toml files
2020-01-30 16:16:19 -05:00