-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
subcommands are all or nothing, allow hybrid #20
Labels
Comments
Use an option on the subcommand: extern crate structopt;
#[macro_use]
extern crate structopt_derive;
use structopt::StructOpt;
#[derive(StructOpt, Debug)]
enum SubCommand {
#[structopt(name = "fetch")]
/// fetch branches from remote repository
Fetch {
#[structopt(long = "dry-run")]
dry_run: bool,
#[structopt(long = "all")]
all: bool,
#[structopt(default_value = "origin")]
repository: String
},
}
#[derive(StructOpt, Debug)]
struct Opt {
/// Disassemble the function at the given address
#[structopt(short = "a", long = "address")]
address_filter: Option<String>,
/// The binary to disassemble
binary: Option<String>,
#[structopt(subcommand)]
subcommand: Option<SubCommand>,
}
fn main() {
let opt = Opt::from_args();
println!("{:?}", opt);
}
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Basically, I want to be able to integrate subcommands into an existing CLI framework, without forcing the original commands to now be under a subcommand.
Afaics (please correct me if I'm wrong, or add an appropriate example), structopt forces the user to either use regular command line with no subcommands, or all only subcommands.
E.g. something like this (do not take this as a suggestion for syntax, or a functioning example, etc.):
which would work via the following invocations:
E.g., I can add subcommands in gradually to an existing framework; or, perhaps subcommands are rarely used, but a good separation of tasks in the tool when they are used, so an explicit subcommand is nice, but otherwise the other command line arguments without any subcommand also work.
Another way of putting it, is basically how cargo works right now; it technically has a mixture of subcommands and "raw" non-subcommand commands, like
--color
or--explain
.So is something like this possible?
The text was updated successfully, but these errors were encountered: