Questions tagged [structopt]

related to Rust crate StructOpt

related to Rust crate StructOpt which is used for structured command line arguments

30 questions
2
votes
1 answer

How to pass special characters as string argument using structopt?

I have a command line to search a word inside a file. I'm using StructOpt to get the word that the user wants to search. #[derive(Debug, StructOpt)] pub struct Command { pub word_to_search: Option, } The problem comes when you write…
Gober
  • 147
  • 2
  • 3
  • 12
2
votes
1 answer

Define a custom parser using structopt that changes based on another flag

I use structopt to parse the command-line arguments to my rust application. The flags in question are the following: query (positional), and case_sensitive (optional). #[derive(StructOpt, Debug)] pub struct Config { /// Query to search for. …
jonathanGB
  • 1,500
  • 2
  • 16
  • 28
2
votes
1 answer

proc-macro panic with structopt using required_unless and conflicts_with

I want to have two options that conflict with each other, but also one of them must be required: #[macro_use] extern crate structopt; use structopt::StructOpt; #[derive(StructOpt)] struct Opt { #[structopt( long = "foo", …
tshepang
  • 12,111
  • 21
  • 91
  • 136
1
vote
1 answer

structopt unable to find its Args parser when defined in a separate file

I'm starting on a command-line tool in Rust, and hitting a wall right from the get-go. I can parse command-line arguments using StructOpt if the Opt struct is defined in main.rs, but since I want to be able to pass the Opt struct into the library…
womble
  • 12,033
  • 5
  • 52
  • 66
1
vote
1 answer

Can you build a structopt parser that takes the rest of the command line (or multiple arguments)?

structopt has a neat feature where it can it accept a typed argument for Vec that will gobble the rest of the command line. #[structopt(long, short)] values: Vec, It also has the ability to accept a type you create, If the field type does…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
1
vote
1 answer

Does structopt support multi-contextual positional arguments?

I'm trying to port seq to structopt, how should I support, seq [OPTION]... LAST seq [OPTION]... FIRST LAST seq [OPTION]... FIRST INCREMENT LAST Notice, that the position of the LAST argument changes in the argument list, for completeness it would…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
1
vote
1 answer

Parse Structopt flag from anywhere in the input

I would like to be able to have 'universal' flags in my command line tool, which uses StructOpt. That is, if I have a flag (such as --debug) I want it to behave the same regardless of where that flag is in the input: $ mycli --debug alpha $ mycli…
Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
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
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
1 answer

How can I distinguish a multi-occurence option from a subsequent optional argument with structopt?

I am using structopt to define arguments that can be used mfe -s opt1 -s opt2 -s opt2 this_is_an_argument or mfe -s opt1 opt2 opt3 this_is_an_argument The problem is that the this_is_an_argument argument is parsed as an option. I know I could use…
user11069095
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
1 answer

When using structopt, how to test if the user provided an option or if it comes from the default value?

I'm using the structopt crate and I have the following struct: #[derive(Clone, StructOpt, Debug)] #[structopt(name = "test")] pub struct CommandlineOptions { #[structopt( long = "length", help = "The length of the the string to…
Just a learner
  • 26,690
  • 50
  • 155
  • 234
0
votes
1 answer

Rustlang structopt How to set the home directory

I am using the crate structopt for my cli program. I want to set home directory as default, if output dir in args not passed. Below is my code, please suggest me how i can implement. Command.rs pub enum Command { #[structopt(name =…
Nagaraj M
  • 387
  • 1
  • 5
  • 16
0
votes
1 answer

Is it possible to construct a StructOpt Args object without parsing command line params for testing?

I have a fn main that is parsing arguments via StructOpt .. Args::from_args. Is there a way to create this Args object without actually starting the executable for testing? Can I just create a Args object directly? Can I do this for example fn…
user855
  • 19,048
  • 38
  • 98
  • 162
-3
votes
1 answer

structopt: error[E0277]: the trait bound `String: From<&OsStr>`

I'm using Rust's structopt crate, but when I try to compile examples I'm getting the following error, error[E0277]: the trait bound `String: From<&OsStr>` is not satisfied --> bin/seq.rs:21:36 | 21 | #[structopt(short, long,…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
1
2