Commit Graph

55 Commits

Author SHA1 Message Date
topjohnwu
f0ca7d9d7f Remove help message generation 2023-08-17 21:20:42 -07:00
Erick Tryzelaar
e8efc8285f Change from_str_fn to take expression paths
This changes `from_str_fn` to take expression paths, rather than simple
idents. This makes it easier to use functions from external modules,
or with static methods.
2023-08-08 15:06:55 -07:00
Erick Tryzelaar
a05e92f2f1 Bump version 2023-08-07 17:21:48 -07:00
Matthew Maurer
543d15e89d Update to syn-2 2023-08-07 13:11:18 -07:00
Clayton Wilkinson
75ccf47dc4 Adding ArgsInfo derive trait
The ArgsInfo trait exposes the information about the
arguments defined using the argh attributes. This is
intended to be used for uses that benefit from inspecting
the command line arguments exposed via a structured interface
for example, help documentation generation and CLI compatibility
detection.
2023-08-03 11:35:42 -07:00
Clayton Wilkinson
3f34ca6fc5 Adding ArgsInfo derive trait
The ArgsInfo trait exposes the information about the
arguments defined using the argh attributes. This is
intended to be used for uses that benefit from inspecting
the command line arguments exposed via a structured interface
for example, help documentation generation and CLI compatibility
detection.
2023-08-03 11:35:42 -07:00
Rich Kadel
888a633465 Bump version to 0.1.10 2023-01-11 09:55:45 -08:00
Aleksey Kladov
728d143e26 validate implicit flag names 2022-11-09 17:18:31 -08:00
Aleksey Kladov
5b6148d68d reduce dependencies
heck encodes the knowledge of what constitutes a unicode word, but we
don't actually need that here, we just want to repaces underscores with
dashes
2022-11-09 17:18:31 -08:00
Alexandre Courbot
d1552ca611 Allow #[argh(switch)] on Option<bool> fields
It can be useful to use Option<bool> in a configuration struct, in
particular if that struct can be built from another source (e.g.
deserialized from a configuration file) where boolean switches can be
explicitly set to false and we want to differenciate between the flag
being negated explicitly from it not being specified.

Thus, allow the `switch` parameters to be used on Option<bool> fields.
The field will be `None` if the switch was not specified, and
`Some(true)` if it was.
2022-11-08 11:16:21 -08:00
Casey Dahlin
d09a0d9b35 Remove leading and trailing underscores from positional argument meta
Closes #149
2022-11-08 11:14:38 -08:00
Casey Dahlin
2390617828 Fix some lints from updated clippy 2022-11-08 11:14:38 -08:00
Amin Yahyaabadi
1dae49a800
Add support for an hidden_help attribute
Co-authored-by: Bruce Guenter <bruce@untroubled.org>
2022-11-03 17:29:48 -07:00
Megan Batty
adc704cd29 Bump version to 0.1.9 2022-09-22 11:42:51 -07:00
Megan Batty
fa20b09dc1 Add 'remainder': greedy positional arguments
This adds a new variant of positional arguments that, once they start
processing, consume all arguments after as part of the positional
argument, as if they always had '--' in front or behind them.
2022-09-22 11:33:39 -07:00
Megan Batty
b82615aea9 Support generic structs and enums in derive(FromArgs)
This removes the restriction against deriving a struct with
FromArgs that takes generic arguments, and adds a test to make sure
it works correctly. There isn't really a good reason for this
constraint as far as I can tell, and it's surprising if you
run into it.
2022-09-21 13:33:46 -07:00
Basti Ortiz
d28aafa570
Chore: move use to top level 2022-08-10 18:07:15 +08:00
Basti Ortiz
4d151f71cc
Deps: update heck to 0.4 2022-08-08 18:31:02 +08:00
Anton Romanov
5b42a7fd9c Fix clippy lint 2022-07-28 15:12:26 -07:00
Anton Romanov
d0b6fa7a8b allow alphanumeric strings in long attribute
Argh already allows usage of field names such as `ac97` but not if
specified in `long` attribute
2022-07-28 15:12:26 -07:00
Erick Tryzelaar
878ff1b2f2 prevent duplicate short and long names
Closes #42
2022-07-28 15:10:02 -07:00
Kentrix (Edward)
ee3ca816f1 Added some docs on around how to debug expanded derive marcos. 2022-07-20 11:03:47 -07:00
Casey Dahlin
c96d491b67 Document dynamic commands and bump version 2022-06-25 15:45:54 -07:00
Casey Dahlin
4814be82ed 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-06-22 18:03:10 -04:00
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