Questions tagged [clap]

Clap is a command line argument parser for the Rust programming language.

Clap is a command line argument parser for the Rust programming language.

149 questions
2
votes
0 answers

How do you maintain the order of arguments?

I have a set of rust programs for which the order of arguments is important, e.g. mytool --foo this --bar that is not the same as mytool --bar that --foo this I'd really like to simply iterate the args from left to right, but clap does an…
Andy Jewell
  • 413
  • 3
  • 12
2
votes
1 answer

rust clap How to specify the type of command line arguments

I am using rust's clap to investigate command line arguments. is it possible to specify which one will be input as a command line argument in clap? Is it possible to specify the type like type=int in the following python code? parser =…
musako
  • 897
  • 2
  • 10
  • 26
2
votes
1 answer

clap - how to pass a default_value when returning ArgMatches<'static>

To reduce lines of code I moved my clap App to another file with something like this: playground use clap::{App, AppSettings, Arg, ArgMatches}; // 2.33.3 use std::path::Path; fn main() { let s3m_dir = Path::new("/tmp").join(".s3m"); let…
nbari
  • 25,603
  • 10
  • 76
  • 131
2
votes
1 answer

Rust Clap custom headings

I am using the rust Clap library to parse command line arguments. When displaying my help text I want to separate required arguments from optional arguments and put them under separate headings. Something along the lines of this: HELP: Example…
Joh1998
  • 85
  • 1
  • 5
2
votes
1 answer

How can I pass all command line arguments through Clap to another program?

I have a program foo that uses Clap to handle command argument parsing. foo invokes another program, bar. Recently, I decided that users of foo should be able to pass arguments to bar if they like. I added the bar command to Clap: let matches =…
HiDefender
  • 2,088
  • 2
  • 14
  • 31
2
votes
1 answer

Clap can not parse YAML file: failed to convert YAML String("1") value to a string

I use a YAML file to define my command line interface. I parse the file using Clap's load_yaml! macro, which worked out fine for some time: #[macro_use] extern crate clap; use clap::{App, ArgMatches}; fn main() { let yml =…
m00am
  • 5,910
  • 11
  • 53
  • 69
2
votes
3 answers

Is there a way to make clap treat -? the same way as -h?

The clap crate implements built-in behaviour for the -h option, but it doesn't seem to do the same for -?. Is there a way to tell it to do so?
Kağan Kayal
  • 2,303
  • 1
  • 19
  • 30
1
vote
1 answer

How to rename subcommand placeholder in clap_derive?

How can I rename the placeholder of a subcommand when using clap_derive? Here's an MRE: Cargo.toml [package] name = "clap_test_subcommand_placeholder" version = "0.1.0" edition = "2021" # See more keys and their definitions at…
Richard Neumann
  • 2,986
  • 2
  • 25
  • 50
1
vote
0 answers

Defining argument dependencies with the Rust CLAP crate

Is it possible to define argument dependencies for the Rust CLAP crate in the following way: The first argument is a mandatory thing which defines the type of struct to be created The arguments following this define the values of the struct…
FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
1
vote
1 answer

How to convert from Vec to Vec<&str> in clap value_parser function?

I want to make an CLI application with an package autocomplete. I use the function below to make it. fn package_completion() -> Result, String> { let command = process::Command::new("yay") .arg("-Pc") .output() …
DevAles
  • 11
  • 2
1
vote
1 answer

How do I require one of the two Clap options?

I am trying to write a CLI in Rust with the help of Clap. My command has 2 arguments, I want to make that just one or another can be specified, ex: command --command_a or command --command_b #[derive(Debug, clap::Args)] #[clap(name = "command")] pub…
Alex Bean
  • 493
  • 7
  • 19
1
vote
1 answer

Hide subcommand group

I have code like this: #[derive(Subcommand)] pub enum MyTool { Clean(CleanPackage), Compile(CompilePackage), #[clap(subcommand)] Coverage(coverage::CoveragePackage), #[clap(subcommand)] Show(show::ShowTool), …
Daniel Porteous
  • 5,536
  • 3
  • 25
  • 44
1
vote
1 answer

How can I define a default subcommand in Rust Clap?

I'm building a CLI in Rust to learn the language and I am using clap with the derive feature for the argument parsing. I would like to have a specific behavior of my CLI; specifically, it has some subcommands, and I want to execute one in particular…
0xFR
  • 108
  • 9
1
vote
1 answer

How to add long-form subcommand documentation in a clap CLI?

I'm using #[derive(Subcommand)] to introduce subcommands in my CLI: #[derive(Debug, Subcommand)] enum Commands { /// Create a new config file /// /// Line one /// Line two Init, } However, the documentation in long form help…
Peteris
  • 3,548
  • 4
  • 28
  • 44
1
vote
1 answer

How to create a custom derive macro for clap structs in rust?

I'm trying to create some sort of simple billing CLI application in rust for practice. It is kind a database application. I have many operations in which I need the user to be able to filter by the values of the columns which lines will be operated…
sbb
  • 144
  • 8