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 write tests for command line tool built with structopt

So I built a small Rust CLI tool with structopt and now want to add some tests but didn't find any useful docs/ examples about how to write it use structopt::StructOpt; #[derive(Debug, StructOpt)] #[structopt(name = "example")] struct Cli { …
Thong Nguyen
  • 143
  • 3
  • 10
0
votes
0 answers

Better performance with clap in package autocompletion

I make an CLI that gets the packages from yay (AUR package manager) and suggest, but I have a big problem with the clap lib: fn package_completion() -> Result, String> { let command = process::Command::new("yay") …
DevAles
  • 11
  • 2
0
votes
1 answer

How to eval program output in PowerShell

I've written a command line utility in Rust, with argument completion provided by the clap_complete crate. This generates Bash and PowerShell completion scripts: $ ex --completion=bash _ex() { local i cur prev opts cmd COMPREPLY=() …
Huw Walters
  • 1,888
  • 20
  • 20
0
votes
1 answer

Rust clap re-use same arguments in different subcommand

Rust Noob here :) using rust clap 3.2.23 I have to 2 subcommands: generate (This is responsible for generating item based on input parameters & storing in a backend DB) #[derive(Args,…
alwaysAStudent
  • 2,110
  • 4
  • 24
  • 47
0
votes
1 answer

Rust Clap Allow value from selected list

I have a variable #[clap( group = "abc", long = "attribute1", value_name = "ATTRIBUTE1" )] attribute1: Option, I want to enforce the users attribute1 can only provided a value from within an acceptable…
alwaysAStudent
  • 2,110
  • 4
  • 24
  • 47
0
votes
0 answers

rust clap vector of vector/tuple/fixed-sized array

I am using rust clap (Version: 3.2.25) to parse and validate command line input to script I am developing. One of the inputs would be list of pair of start & end dates (in epoch format) e.g. [(123,345) (346,567) (658,857)] I am currently trying the…
alwaysAStudent
  • 2,110
  • 4
  • 24
  • 47
0
votes
1 answer

Programmatic Access to Clap Derive Arg Attribute Properties

Given a struct defined as follows: use clap::Parser; use validator::Validate; #[derive(Parser, Debug, Validate)] #[command(author="", version="0.0.1", about="Utility to split files", long_about = None)] pub struct TestArgs { #[arg(short, long,…
jrf
  • 41
  • 4
0
votes
2 answers

Taking a list of command line parameters using Rust's CLAP Parser trait

I am trying to have a CLI tool that redacts files according to some specified regexes. In debugging, as an example: cargo run -- folder ./tests/test_files -t emails ip Or in production, as an example: raf folder ./tests/test_files -t emails…
Jim
  • 450
  • 2
  • 10
0
votes
1 answer

Using an optional struct with clap

I have a number of arguments that when specified require that a specific argument is provided. In the below example when b or c is specified it requires that a is specified. Ideally this would be implemented like: Playground use…
Jonathan Woollett-light
  • 2,813
  • 5
  • 30
  • 58
0
votes
0 answers

Mismatch between definition and access of clap argument

I'm trying to create a command option repo, and make it an Option type: #[derive(Clone, Debug)] pub enum ImageRepository { repoA, repoB, repoC, } fn format_repo(repo: &str) -> Result> { let repo =…
xx11
  • 1
  • 1
0
votes
1 answer

How can I make clap ignore flags after a certain subcommand?

Let's say I'm writing a command-line program called foo, using clap as the arguments parser: #[derive(Debug, Parser)] struct Cli { #[command(subcommand)] pub command: Commands, } #[derive(Debug, Subcommand)] enum Commands { Run { …
0
votes
0 answers

how to define with `clap`'s `derive` feature a list of dependently available optional arguments

I am seeking to use clap to derive the parsing for the following argument syntax: program [arg1 [arg2]] Here arg1 is optional but if present arg2 becomes possible but is optional. I am using clap for training purposes as well as to allow for growth…
George
  • 2,451
  • 27
  • 37
0
votes
0 answers

Clap subcommand requires fromstr

I'm trying to add subcommands to my CLI tool in rust, using the clap library. When I copy the subcommand example from the docs #[derive(clap::Parser)] struct Args { #[command(subcommand)] action: Action, } #[derive(clap::Subcommand)] enum…
Simon Berens
  • 554
  • 4
  • 11
0
votes
1 answer

Clap - "Unknown option" after clap has already read args?

I'm trying to read command line args using clap, then use the parsed results to drive a backened whose progress is displayed by a gtk App (just using the app as the easiest way to display a changing graphical window, maybe there's a better…
Edward Peters
  • 3,623
  • 2
  • 16
  • 39
0
votes
1 answer

How to stop warnings about parentheses required by clap macros?

With this code: #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] struct Args { #[arg(short, long, default_value_t = ("/dev/ttyUSB3".to_string()))] modem_path: String, ... } I get a warning: warning:…
fadedbee
  • 42,671
  • 44
  • 178
  • 308