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
0
votes
1 answer

How to use global option when subcommands are defined when using Clap in Rust?

So I am trying to create a command line application with subcommands. The only problem now is I can't seem to get the main command to work after the subcommands has been defined. What I have thus far is this: use clap::{Parser, Subcommand,…
Finlay Weber
  • 2,989
  • 3
  • 17
  • 37
0
votes
0 answers

How to parse enum arguments in Rust

In the Rust CLI I'm developing with using Clap, I take some parameters from the end user, which is specified as a struct. args.rs use clap:: { Args, Parser, Subcommand }; #[derive(Debug, Parser)] #[clap(author, version, about)] pub…
Pavindu
  • 2,684
  • 6
  • 44
  • 77
0
votes
0 answers

Error E0434 from Rust when passing vector to possible_values parameter in clap structopt

I am new to Rust and clap, so I apologize if some of the terminology I use in my question isn't correct. I am writing a CLI tool in Rust which takes a parameter called property_name. This property_name has a list of possible values, and I want clap…
DanzanRyu
  • 1
  • 2
0
votes
0 answers

How to interactively parse a struct an enum in rust, ideally using clap

Okay here is an example of what I want to accomplish. I have a rigid, and complicated enum that must be parsed. The structure of the enum cant be changed. #[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema,…
ewoolsey
  • 91
  • 1
  • 7
0
votes
1 answer

How do I allow muti-option flags in Clap?

For my RUST program, I am using Clap to parse my command line arguments. I want to let users input flags like so: usage: file [-bhLs] [FILE...] my current struct is struct Args { /// option for check #[arg(default_value ="-h")] option: String, ///…
0
votes
0 answers

rust clap, use enum for separate flags

I have this example: use clap::Parser; #[derive(clap::ValueEnum, Clone, Debug)] enum InfoType { All, Headers, Metadata, } #[derive(Parser, Debug)] #[clap(version)] #[clap(about = "Prints out metadata for each file")] struct Args { …
binary01
  • 1,728
  • 2
  • 13
  • 27
0
votes
1 answer

What is the best way of handling error in rust? (CLI with clap)

I'm trying to develop a simple cli bill manager in rust using clap. I want to let the user add new bills by entering its name and value, remove some bills, and I also want to add undo and redo features. As it is my first project in rust, I called it…
sbb
  • 144
  • 8
0
votes
1 answer

How can I make multiple subcommands that do the same thing

#[derive(Parser)] struct Cli { #[clap(subcommand)] subcommand: Subcommand, } #[derive(clap::Subcommand)] enum Subcommand { Index { #[clap(parse(from_os_str))] path: path::PathBuf, }, Show { item:…
0
votes
1 answer

Why clap contains_id() always returns TRUE?

This is the code (I'm using clap 3.2.20): pub fn main() { let m = Command::new("foo") .arg( Arg::new("bar") .long("bar") .required(false) .action(ArgAction::SetTrue) ) .get_matches(); if…
yegor256
  • 102,010
  • 123
  • 446
  • 597
0
votes
1 answer

I can't seem to get my clap parser to take in a vector of string AND use flags

I've been trying to write my own GNU utils like mkdir, cd, ls, Etc. but I'm having trouble with Clap. I want to take in a vector of strings to use as paths for my mkdir function, which worked fine, but when I started trying to add flags to the…
Sarah
  • 33
  • 5
0
votes
1 answer

what is the correct way to get ownership of an argument with clap?

I would like to pass the options of my CLI program via a Config-struct that has ownership of its values, i.e. Strings of paths. The now deprecated ArgMatches::values_of_lossy() returned an owned String, however, ArgMatches::get_many() only returns a…
s1gsegv
  • 77
  • 3
0
votes
0 answers

How to make all arguments have the same number of values?

I'm building a CLI that will be used like this: $ my_cli command aa aa -- bb bb Arguments aa aa and bb bb will be collected into separated Vecs. Let's call them vec_a and vec_b. I need both vectors to be the same length. This is what I…
0
votes
0 answers

Is there a way to access clap arguments from everywhere?

I am building a command-line application using clap. I have many CLI arguments and many different parts of the application behave differently based on these arguments. It is a hassle to make them accessible in every part though, as either every…
leo848
  • 637
  • 2
  • 7
  • 24
0
votes
1 answer

Unable to build with rust clap with yaml feature

I am trying to build with the Clap Yaml feature, but it errors out here. Compiling clap v3.1.12 Building [========================> ] 44/47: clap, yaml-rust error: could not compile `clap` Caused by: process didn't exit successfully:…
Saqib Ali
  • 3,953
  • 10
  • 55
  • 100
0
votes
1 answer

How to Get Matches From a Parser Derived Struct?

The documentation has got me confused. I'm kind of stuck on how to get matches from a parser derived struct. How would I go about doing this? Here's what my argument struct looks like. #[derive(Parser)] #[clap(author, version, about, long_about =…
Lord of Grok
  • 323
  • 3
  • 12
1 2 3
9
10