2020-02-04 09:51:37 +00:00
|
|
|
// https://github.com/TeXitoi/structopt/issues/{NUMBER}
|
|
|
|
|
|
|
|
mod utils;
|
|
|
|
use utils::*;
|
|
|
|
|
2020-02-08 19:36:00 +00:00
|
|
|
use clap::{AppSettings, ArgGroup, Clap};
|
2020-01-07 10:17:23 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_151() {
|
|
|
|
#[derive(Clap, Debug)]
|
2020-05-14 20:50:56 +00:00
|
|
|
#[clap(group = ArgGroup::new("verb").required(true).multiple(true))]
|
2020-01-07 10:17:23 +00:00
|
|
|
struct Opt {
|
|
|
|
#[clap(long, group = "verb")]
|
|
|
|
foo: bool,
|
|
|
|
#[clap(long, group = "verb")]
|
|
|
|
bar: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clap)]
|
|
|
|
struct Cli {
|
|
|
|
#[clap(flatten)]
|
|
|
|
a: Opt,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert!(Cli::try_parse_from(&["test"]).is_err());
|
|
|
|
assert!(Cli::try_parse_from(&["test", "--foo"]).is_ok());
|
|
|
|
assert!(Cli::try_parse_from(&["test", "--bar"]).is_ok());
|
|
|
|
assert!(Cli::try_parse_from(&["test", "--zebra"]).is_err());
|
2019-12-21 12:20:57 +00:00
|
|
|
assert!(Cli::try_parse_from(&["test", "--foo", "--bar"]).is_ok());
|
2020-01-07 10:17:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_289() {
|
|
|
|
#[derive(Clap)]
|
|
|
|
#[clap(setting = AppSettings::InferSubcommands)]
|
|
|
|
enum Args {
|
2021-07-13 17:39:46 +00:00
|
|
|
SomeCommand {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
sub: SubSubCommand,
|
|
|
|
},
|
2020-01-07 10:17:23 +00:00
|
|
|
AnotherCommand,
|
|
|
|
}
|
|
|
|
|
2020-02-08 19:36:00 +00:00
|
|
|
// FIXME (@CreepySkeleton): current implementation requires us to
|
|
|
|
// derive IntoApp here while we don't really need it
|
2020-01-07 10:17:23 +00:00
|
|
|
#[derive(Clap)]
|
|
|
|
#[clap(setting = AppSettings::InferSubcommands)]
|
|
|
|
enum SubSubCommand {
|
|
|
|
TestCommand,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert!(Args::try_parse_from(&["test", "some-command", "test-command"]).is_ok());
|
|
|
|
assert!(Args::try_parse_from(&["test", "some", "test-command"]).is_ok());
|
|
|
|
assert!(Args::try_parse_from(&["test", "some-command", "test"]).is_ok());
|
|
|
|
assert!(Args::try_parse_from(&["test", "some", "test"]).is_ok());
|
|
|
|
}
|
2020-02-04 09:51:37 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_324() {
|
|
|
|
fn my_version() -> &'static str {
|
|
|
|
"MY_VERSION"
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clap)]
|
|
|
|
#[clap(version = my_version())]
|
|
|
|
struct Opt {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
_cmd: Option<SubCommand>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clap)]
|
|
|
|
enum SubCommand {
|
|
|
|
Start,
|
|
|
|
}
|
|
|
|
|
|
|
|
let help = get_long_help::<Opt>();
|
|
|
|
assert!(help.contains("MY_VERSION"));
|
|
|
|
}
|
2021-10-06 18:22:56 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_490() {
|
|
|
|
use clap::Clap;
|
|
|
|
use std::iter::FromIterator;
|
|
|
|
use std::str::FromStr;
|
|
|
|
|
|
|
|
struct U16ish;
|
|
|
|
impl FromStr for U16ish {
|
|
|
|
type Err = ();
|
|
|
|
fn from_str(_: &str) -> Result<Self, Self::Err> {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
impl<'a> FromIterator<&'a U16ish> for Vec<u16> {
|
|
|
|
fn from_iter<T: IntoIterator<Item = &'a U16ish>>(_: T) -> Self {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clap, Debug)]
|
|
|
|
struct Opt {
|
|
|
|
opt_vec: Vec<u16>,
|
|
|
|
#[clap(long)]
|
|
|
|
opt_opt_vec: Option<Vec<u16>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assert that it compiles
|
|
|
|
}
|