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
3
votes
2 answers

How to parse common subcommand arguments with Clap in Rust?

I trying to build cli which should take as first argument, as last argument and options in between, so call in console would look like this: programm command_one --option True file.txt I have setup like this: //…
Archirk
  • 427
  • 7
  • 25
3
votes
1 answer

Why is this branch always true using clap 4?

I would like to have a command line in Rust using clap 4 which allows this: app --wait If --wait is present start a function. If is NOT present do nothing. I'm trying the below code with no luck: the if command.contains_id("wait") is always true!…
Fred Hors
  • 3,258
  • 3
  • 25
  • 71
3
votes
1 answer

how to change .multiple in upgrade to rust clap v4

I am trying to upgrade rust code from clap v3.22.2 to v4.0.8 and faced the problem how to change Arg::multiple. This is piece of code: Arg::new("relfs") required(true) multiple(true) So I get an error error[E0599]: no method named…
tardis3
  • 37
  • 6
3
votes
2 answers

Clap subcommands over multiple rs files

Situation I want to build a more complex CLI tool. For the purposes of this question, let's say I want to build my own implementation of an AWS Cli tool. I want to split up the logic in the different services (like EC2, S3, sns, etc) and be able…
Arend-Jan
  • 53
  • 4
3
votes
2 answers

How to provide multiple line help message with Clap?

Is there a way for us to have line breaks in clap's help message? I tried multiple line comments, also tried inserting \n in the mix. But neither works. #[derive(Parser, Debug)] #[clap(author, version, about)] struct Args { /// The input…
Yuchen
  • 30,852
  • 26
  • 164
  • 234
3
votes
1 answer

How to make clap ignore a specific field in a struct?

I'm building my Rust CLI with clap. I have one struct with all the command line options. This struct is passed through to a lot of functions. Now I would like to add a field to this struct, but not surface this field as a command line argument. I…
Cornelius Roemer
  • 3,772
  • 1
  • 24
  • 55
3
votes
1 answer

How to pipe string into a Rust app parsing args with Clap?

I'm Brand new to Rust and I have been writing some practice apps. I am trying to accept command-line arguments using Clap. The code below takes a string and a number and prints them back out, as such: $ cargo run "this is a test" -n11 this is a…
sf11
  • 31
  • 2
3
votes
1 answer

Using clap 3 derive macros, how do I specify that at least one argument of a group must be present?

I have a clap struct as follows: #[derive(Clap)] #[clap( version = "0.1.0", author = "..." )] pub struct Cli { #[clap(long)] arg_a: Option, #[clap(long)] arg_b: Option, #[clap(long)] arg_c:…
3
votes
1 answer

Getting relative order of different command line options using clap & structopt

The Problem I have a command that takes different options and the relative order of those options is important to the semantics of the command. For example, in command --config A --some-option --config-file B --random-option --config C…
milend
  • 61
  • 4
3
votes
1 answer

Use more than one letter in short-value

I'm using clap to parse arguments. I want to use the single dash (-) and more than one character in the argument, like -Fmin 1. Adding long("Fmin") gives me that but with two dashes (--). I'm aware that using a single dash and single character…
kometen
  • 6,536
  • 6
  • 41
  • 51
3
votes
0 answers

structops - how to make argument optional based on boolean flag

I have program that accepts 2 boolean flags -d for decode and -e for encode. However, if -e is specified, additional message string needs to be provided (message to encode). This string should not be present if -d is specified. How can I accomplish…
Ach113
  • 1,775
  • 3
  • 18
  • 40
3
votes
0 answers

Is there a way to change OUT_DIR for a build.rs

Currently I'm trying to write a build.rs that creates a bunch of autocompletion scripts for a cli app. // build.rs fn main() { let outdir = match std::env::var_os("OUT_DIR") { None => return, Some(outdir) => outdir, }; …
3
votes
1 answer

How can I access a runtime-defined variable in stuctopt definitions?

I would like to be able to use the value of a variable (or better yet, the return of a function(arg)) as the about string for a CLI program defined using structopt. The end goal is a fully localized CLI that detects the system language or an ENV var…
Caleb
  • 5,084
  • 1
  • 46
  • 65
3
votes
0 answers

CLI arguments that take their own arguments with Clap

My program takes several file names as command line arguments, for example: ./myProgram -F file1 file2 This simple case works fine with Clap, in fact it's the doc example of Arg::multiple(). However, I'd also like each file to take arguments of…
Morten Lohne
  • 383
  • 2
  • 11
3
votes
1 answer

Clap arg group containing arguments with different requirements and conflicts

I am trying to write a CLI in Rust with the help of Clap and YAML. My input will require one argument (file path) and one of the flags -s, -r, or -g. The flags -s and -r will require one of the two flags -t and -m, but the flag -g conflicts with…
1 2
3
9 10