Skip to content

Commit 9334c85

Browse files
committed
[docs] Add note for default_value hack only working with positional args
@jchidley noted in #11 that the default_value hack for omitting the "-" st ring doesn't work with optional args. Updated the docs to highlight this. Also updated usages of #[clap(...)] to #[arg(...)] as that seems to be the new macro name for clap attributes
1 parent d86df0c commit 9334c85

File tree

6 files changed

+10
-8
lines changed

6 files changed

+10
-8
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,9 @@ $ .example myfile.txt
103103
```
104104

105105
## Reading from Stdin without special characters
106-
When using [`MaybeStdin`] or [`FileOrStdin`], you can allow your users to omit the "-" character to read from `stdin` by providing a `default_value` to clap. This works with positional and optional args:
106+
When using [`MaybeStdin`] or [`FileOrStdin`], you can allow your users to omit the "-" character to read from `stdin` by providing a `default_value` to clap.
107+
108+
**NOTE:** This only works with positional args, since clap requires optional args (E.g. using #[arg(long, short)]) to have a value to parse.
107109

108110
```rust,no_run
109111
use clap::Parser;
@@ -112,7 +114,7 @@ use clap_stdin::FileOrStdin;
112114
113115
#[derive(Debug, Parser)]
114116
struct Args {
115-
#[clap(default_value = "-")]
117+
#[arg(default_value = "-")]
116118
input: FileOrStdin,
117119
}
118120

examples/parse_with_serde.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl FromStr for User {
3939
#[derive(Debug, Parser)]
4040
struct Args {
4141
/// Parsed user from json, provided via a filepath (or leave blank to read from stdin)
42-
#[clap(default_value = "-")]
42+
#[arg(default_value = "-")]
4343
user: FileOrStdin<User>,
4444
}
4545

tests/fixtures/file_or_stdin_optional_arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clap_stdin::FileOrStdin;
55
#[derive(Debug, Parser)]
66
struct Args {
77
first: String,
8-
#[clap(short, long)]
8+
#[arg(short, long)]
99
second: Option<FileOrStdin<u32>>,
1010
}
1111

tests/fixtures/file_or_stdin_positional_arg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use clap_stdin::FileOrStdin;
44

55
#[derive(Debug, Parser)]
66
struct Args {
7-
#[clap(default_value = "-")]
7+
#[arg(default_value = "-")]
88
first: FileOrStdin,
9-
#[clap(short, long)]
9+
#[arg(short, long)]
1010
second: Option<String>,
1111
}
1212

tests/fixtures/maybe_stdin_optional_arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clap_stdin::MaybeStdin;
55
#[derive(Debug, Parser)]
66
struct Args {
77
first: String,
8-
#[clap(short, long)]
8+
#[arg(short, long)]
99
second: Option<MaybeStdin<u32>>,
1010
}
1111

tests/fixtures/maybe_stdin_positional_arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clap_stdin::MaybeStdin;
55
#[derive(Debug, Parser)]
66
struct Args {
77
first: MaybeStdin<String>,
8-
#[clap(short, long)]
8+
#[arg(short, long)]
99
second: Option<String>,
1010
}
1111

0 commit comments

Comments
 (0)