Commit Graph

114 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
8e7cf4da46 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
3f3c29726a
Merge pull request #156 from richkadel/bump_argh_to_0.1.10
Bump version to 0.1.10
2023-01-11 10:33:13 -08: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
Aleksey Kladov
f43107fb7e Be more robust when weird arguments are passed in
Two cases here:

- invalid utf8 -- this can happen in somewhat reasonable circumstances,
  so returning a graceful error is warranted here
- empty `argv` -- this one is weird, I think various things across the
  stack try to actually patch that up to never bubble empty argv to an
  application, but it's not to hard to add extra error handling here
  <https://ryiron.wordpress.com/2013/12/16/argv-silliness/>
2022-11-09 14:16:25 -08:00
Aleksey Kladov
59e70b461f fix tests 2022-11-09 14:09:22 -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
Megan Batty
861ef2be70 Fix clippy lints
I don't think there's a useful way to break down the type it
complains about on argh/src/lib.rs:981, so just let it ignore
that one.
2022-09-21 13:33:46 -07:00
Casey Dahlin
660dc01e20
Merge pull request #139 from Some-Dood/deps/update-heck
Deps: update `heck` to `0.4`
2022-08-10 11:01:31 -07:00
Basti Ortiz
d28aafa570
Chore: move use to top level 2022-08-10 18:07:15 +08:00
Casey Dahlin
fc1667b063
Merge pull request #140 from Lioness100/patch-1
Fix macro typo
2022-08-09 22:23:31 -07:00
Lioness100
fb341a2ae3
Fix macro typo 2022-08-08 08:36:57 -04: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
Erick Tryzelaar
f68d472237 Fix the example, expand workflows 2022-07-20 11:03:47 -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
b9296f059e
Merge pull request #132 from sadmac7000/master
Document dynamic commands and bump version
2022-06-25 21:24:44 -07:00
Casey Dahlin
c96d491b67 Document dynamic commands and bump version 2022-06-25 15:45:54 -07:00
Amin Yahyaabadi
bd37ed1b34 Improve early exit error by mentioning --help 2022-06-22 18:15:39 -04: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
b2854ad9f1 Add tests to prove we won't panic 2021-12-15 15:32:50 -05: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
f1f85d2d89 Make sure we don't warn when fields are used
https://github.com/rust-lang/rust/pull/85200 changed rust to emit more
unused warnings if fields in a struct are ultimately never read. This
adds a test to make sure that we don't experience these warnings.
2021-12-08 13:49:23 -05:00
Erick Tryzelaar
317ddbedb6 Use #[allow(unused)] 2021-12-08 13:49:23 -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
Kafji
dcb261b4a6 Move tests into argh package
`cargo test` won't run the tests if it's located in the workspace root
dir.
2021-08-30 16:55:06 -07:00