2020-02-04 09:51:37 +00:00
|
|
|
// https://github.com/TeXitoi/structopt/issues/{NUMBER}
|
|
|
|
|
2021-11-30 15:36:53 +00:00
|
|
|
use crate::utils;
|
2020-02-04 09:51:37 +00:00
|
|
|
|
2022-02-10 17:51:40 +00:00
|
|
|
use clap::{ArgGroup, Args, Parser, Subcommand};
|
2020-01-07 10:17:23 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-06-01 15:31:23 +00:00
|
|
|
fn issue_151_groups_within_subcommands() {
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Args, Debug)]
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(group = ArgGroup::new("verb").required(true).multiple(true))]
|
2020-01-07 10:17:23 +00:00
|
|
|
struct Opt {
|
2022-09-02 20:37:23 +00:00
|
|
|
#[arg(long, group = "verb")]
|
2022-06-01 15:31:23 +00:00
|
|
|
foo: Option<String>,
|
2022-09-02 20:37:23 +00:00
|
|
|
#[arg(long, group = "verb")]
|
2022-06-01 15:31:23 +00:00
|
|
|
bar: Option<String>,
|
2020-01-07 10:17:23 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, Parser)]
|
2020-01-07 10:17:23 +00:00
|
|
|
struct Cli {
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(flatten)]
|
2020-01-07 10:17:23 +00:00
|
|
|
a: Opt,
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:54:25 +00:00
|
|
|
assert!(Cli::try_parse_from(["test"]).is_err());
|
|
|
|
assert!(Cli::try_parse_from(["test", "--foo=v1"]).is_ok());
|
|
|
|
assert!(Cli::try_parse_from(["test", "--bar=v2"]).is_ok());
|
|
|
|
assert!(Cli::try_parse_from(["test", "--zebra=v3"]).is_err());
|
|
|
|
assert!(Cli::try_parse_from(["test", "--foo=v1", "--bar=v2"]).is_ok());
|
2020-01-07 10:17:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_289() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser)]
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(infer_subcommands = true)]
|
2020-01-07 10:17:23 +00:00
|
|
|
enum Args {
|
2021-07-13 17:39:46 +00:00
|
|
|
SomeCommand {
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(subcommand)]
|
2021-07-13 17:39:46 +00:00
|
|
|
sub: SubSubCommand,
|
|
|
|
},
|
2020-01-07 10:17:23 +00:00
|
|
|
AnotherCommand,
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Subcommand)]
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(infer_subcommands = true)]
|
2020-01-07 10:17:23 +00:00
|
|
|
enum SubSubCommand {
|
|
|
|
TestCommand,
|
|
|
|
}
|
|
|
|
|
2022-11-24 13:54:25 +00:00
|
|
|
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-01-07 10:17:23 +00:00
|
|
|
}
|
2020-02-04 09:51:37 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn issue_324() {
|
|
|
|
fn my_version() -> &'static str {
|
|
|
|
"MY_VERSION"
|
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser)]
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(version = my_version())]
|
|
|
|
#[command(help_template = utils::FULL_TEMPLATE)]
|
2020-02-04 09:51:37 +00:00
|
|
|
struct Opt {
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(subcommand)]
|
2021-11-04 15:15:04 +00:00
|
|
|
_cmd: SubCommand,
|
2020-02-04 09:51:37 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Subcommand)]
|
2020-02-04 09:51:37 +00:00
|
|
|
enum SubCommand {
|
|
|
|
Start,
|
|
|
|
}
|
|
|
|
|
2021-11-30 15:36:53 +00:00
|
|
|
let help = utils::get_long_help::<Opt>();
|
2020-02-04 09:51:37 +00:00
|
|
|
assert!(help.contains("MY_VERSION"));
|
|
|
|
}
|
2021-10-06 18:22:56 +00:00
|
|
|
|
2021-10-25 21:28:23 +00:00
|
|
|
#[test]
|
|
|
|
fn issue_418() {
|
|
|
|
#[derive(Debug, Parser)]
|
|
|
|
struct Opts {
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(subcommand)]
|
2021-10-25 21:28:23 +00:00
|
|
|
/// The command to run
|
|
|
|
command: Command,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
|
|
enum Command {
|
|
|
|
/// Reticulate the splines
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(visible_alias = "ret")]
|
2021-10-25 21:28:23 +00:00
|
|
|
Reticulate {
|
|
|
|
/// How many splines
|
|
|
|
num_splines: u8,
|
|
|
|
},
|
|
|
|
/// Frobnicate the rest
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(visible_alias = "frob")]
|
2021-10-25 21:28:23 +00:00
|
|
|
Frobnicate,
|
|
|
|
}
|
|
|
|
|
2021-11-30 15:36:53 +00:00
|
|
|
let help = utils::get_long_help::<Opts>();
|
2021-10-25 21:28:23 +00:00
|
|
|
assert!(help.contains("Reticulate the splines [aliases: ret]"));
|
|
|
|
}
|
|
|
|
|
2021-10-06 18:22:56 +00:00
|
|
|
#[test]
|
|
|
|
fn issue_490() {
|
2021-07-13 17:50:55 +00:00
|
|
|
use clap::Parser;
|
2021-10-06 18:22:56 +00:00
|
|
|
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!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, Debug)]
|
2021-10-06 18:22:56 +00:00
|
|
|
struct Opt {
|
|
|
|
opt_vec: Vec<u16>,
|
2022-09-02 20:37:23 +00:00
|
|
|
#[arg(long)]
|
2021-10-06 18:22:56 +00:00
|
|
|
opt_opt_vec: Option<Vec<u16>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assert that it compiles
|
|
|
|
}
|