-
Hi! I'm trying to use Clap in an app that takes only one (positional) argument. I've looked at the current documentation and derive reference, and didn't find any answer to my quest. How can this be done? I'm currently using:
use anyhow;
use clap::Parser;
#[derive(Debug, Parser)]
struct Foo {
bar: String,
}
fn main() -> anyhow::Result<()> {
let cli = Foo::parse();
println!("Hello, world!\n\t{}", cli.bar);
Ok(())
} |
Beta Was this translation helpful? Give feedback.
Answered by
epage
Feb 10, 2022
Replies: 1 comment 15 replies
-
You can declare the positional argument optional via If #[clap(value_name = "PATH", default_value = "-", parse(from_os_str))]
input: std::path::PathBuf, |
Beta Was this translation helpful? Give feedback.
15 replies
Answer selected by
x10an14
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can declare the positional argument optional via
bar: Option<String>
and key off of that for reading from stdin.If
bar
were a path, I would do