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
1
vote
1 answer

cannot move out of *** which is behind a shared reference (Clap)

I'm learning rust and would like to better understand what is happening here. I have the following declared: pub struct SomeHandler {} impl SomeHandler { pub fn configure(&self, app: &App) { app.subcommand( …
Manthan Dave
  • 153
  • 1
  • 11
1
vote
1 answer

How to create a StructOpt command where all subcomands are optional

I want to arrange subcommands like: mycmd status : Prints a short status - NOT WORKING mycmd status full : Prints verbose status - OK mycmd status dump : Dumps full debug status to a file - OK I'm unable to achieve the simple mycmd status because…
nolandda
  • 2,254
  • 3
  • 17
  • 19
1
vote
1 answer

How to use unspecified arguments with clap

I want to create a CLI application using the clap library. The problem I have is that I want to use my application like this : ./my_app file.txt read2.txt -d The objective is that I can recover in my program in the form of Vec with file.txt…
Rayder-_-
  • 199
  • 1
  • 2
  • 13
1
vote
1 answer

Include long options without short options for help and version

I would like to include --help and --version long options without the -h and -V short options. Is this possible? I'm using clap with yaml. The closest I've been able to come up with is to use hidden (unused) args that mask the short options. #…
snapshoe
  • 13,454
  • 1
  • 24
  • 28
1
vote
1 answer

The trait `std::convert::From` is not implemented

I try to create a simple application parsing command line arguments using clap library and converting them to a Config custom structure. I implemented From trait for my structure, however, when I try to call from function, I receive the following…
Yury
  • 20,618
  • 7
  • 58
  • 86
1
vote
0 answers

StructOpt: How to use subcommand enum's fields in clap::arg attribute methods?

I have the following setup: use structopt::StructOpt; #[derive(Debug, StructOpt)] struct CliArgs { #[structopt(short, long)] aisle: Option, #[structopt(short, long)] shelf: Option, #[structopt(subcommand)] …
1
vote
0 answers

How do I make clap's argument's value_names optional?

I am trying to make a date clone from coreutils. The man describes that the command -r can have different value "types": -r seconds Print the date and time represented by seconds, where seconds is the number of seconds since the Epoch …
1
vote
1 answer

How do I use STDIN if no positional arguments are given with clap?

I have a clap App like this: let m = App::new("test") .arg( Arg::with_name("INPUT") .help("a string to be frobbed") .multiple(true), ) .get_matches(); I want to read the arguments as an iterable of…
Scott Colby
  • 1,370
  • 12
  • 25
1
vote
1 answer

How can I display help after calling Clap's get_matches?

I'm having the same problem as Is there any straightforward way for Clap to display help when no command is provided?, but the solution proposed in that question is not good enough for me. .setting(AppSettings::ArgRequiredElseHelp) stops the program…
Omar Abid
  • 15,753
  • 28
  • 77
  • 108
1
vote
1 answer

Is it possible to configure argument groups of unknown size with Clap?

I'm building a CLI which can call other underlying programs, that have their own options and arguments. I'd like to be able to pass those options to a program through the CLI. $ cli --program [PROGRAM] --programOpts[OPT1, OPT2, ...] Example: $ cli…
Pascal Precht
  • 8,803
  • 7
  • 41
  • 53
1
vote
1 answer

How do I pass a String to a method accepting Into<&str>?

I'm trying to pass a String to clap's builder methods: extern crate clap; // 2.32.0 use clap::App; const NAME: &'static str = "example"; const DESC_PART_1: &'static str = "desc"; const DESC_PART_2: &'static str = "ription"; fn main() { let…
JMAA
  • 1,730
  • 13
  • 24
1
vote
1 answer

How to specify a default value for an argument for clap_app! macro?

I want to use clap_app! macro to define an argument which should have a default value. Unfortunately, there is nothing in the docs, and my naive attempt didn't work: #[macro_use] extern crate clap; fn main() { let matches = clap_app!(myapp => …
George Shuklin
  • 6,952
  • 10
  • 39
  • 80
0
votes
0 answers

How to output a different help text depending on the outer subcommand?

I am making a Rust CLI program that uses Clap to parse arguments. I made something like this. #[derive(Subcommand)] enum SubType { /// Operate on entries Operate(Entries), /// Generate entries …
decipher
  • 11
  • 2
0
votes
0 answers

Using clap with multiple commands sharing subcommand syntax/common args

I've been using Clap to write a command line tool in Rust. The design that makes most sense for this project is to have multiple commands, each containing roughly the same subcommands that have different flags, but some overlap of "common args." For…
0
votes
0 answers

Global CLI argument is being required twice

I'm writing a CLI application in order to automate some tasks within Gitlab, in order to interact with the Gitlab API an access token is required as part of my request headers. Within my CLI I want for this value to be available at the top level of…
Jeremy
  • 1,447
  • 20
  • 40