Referring to the "Git" example of StructOpt, I do not understand how I am then supposed to use the data from the arguments.
I am fairly new to Rust so I am guessing it is obvious. Unfortunately, all examples I can find with an enum only do a…
I'd like to make StructOpt work with enums such that every time a user passes -d sunday it'd parsed as a Day::Sunday:
#[macro_use]
extern crate structopt;
use std::path::PathBuf;
use structopt::StructOpt;
// My enum
enum Day {
Sunday,…
I have a command line tool that has two possible arguments:
--version (which will print out the version number and quit)
--out (which is the path to some output file into which magic is going to be poured).
If a user passes --version I do not care…
I have this code:
#[derive(StructOpt)]
pub struct Opt {
/// Data stream to send to the device
#[structopt(help = "Data to send", parse(try_from_str = "parse_hex"))]
data: Vec,
}
fn parse_hex(s: &str) -> Result {
…
clap allows you to provide list of accepted values using possible_values like this.
let mode_vals = ["fast", "slow"];
.possible_values(&mode_vals)
How to do this with structopt?
What I want to do is to access user-provided command-line arguments as a single string.
First, I did this as:
let lst: Vec = std::env::args().collect();
let res: String = lst[1..].join(" ");
But then I decided to try doing it with structopt…
I used to be able to run specific, named tests from the command-line interface like this: cargo test . But now this gives me the error
running 1 test
error: Found argument '' which wasn't expected, or isn't valid in this…
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…
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…
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,
};
…
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…
I'm trying to setup a simple CLI program in Rust, but I want it to display the version based on the info in git describe rather than whatever is it the Cargo.toml file.
I setup some basic dependencies:
[dependencies]
structopt =…
For example, running my application with
./app --foo=bar get
works well, but
./app get --foo=bar
Produces an error:
error: Found argument '--foo' which wasn't expected, or isn't valid in this context
USAGE:
app --foo get
Code:
use…
Introduction
I currently have subcommands working using structopt, similarly to this other answer. However I would like to have nested subcommands similarly of how docker works:
docker image ls
docker image pull
Current Code
main.rs
mod cli;
use…
I'm looking for a way to initialize a structopt Vec field with multiple items by default. I can do it for a single item with:
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
pub struct Cli {
#[structopt(default_value = "foo")]
foo:…