Create a separate test for from_global
@@ -162,7 +162,7 @@ fn test_tuple_commands() {
}
#[test]
-fn external_subcommand() {
+fn global_passed_down() {
#[derive(Debug, PartialEq, Clap)]
struct Opt {
#[clap(global = true, long)]
@@ -174,10 +174,7 @@ fn external_subcommand() {
#[derive(Debug, PartialEq, Clap)]
enum Subcommands {
Add,
- Remove,
Global(GlobalCmd),
- #[clap(external_subcommand)]
- Other(Vec<String>),
}
#[derive(Debug, PartialEq, Clap)]
@@ -187,34 +184,49 @@ fn external_subcommand() {
}
assert_eq!(
- Opt::parse_from(&["test", "add"]),
+ Opt::parse_from(&["test", "global"]),
Opt {
global: false,
- sub: Subcommands::Add
+ sub: Subcommands::Global(GlobalCmd { global: false })
}
);
assert_eq!(
- Opt::parse_from(&["test", "remove"]),
+ Opt::parse_from(&["test", "global", "--global"]),
Opt {
- global: false,
- sub: Subcommands::Remove
+ global: true,
+ sub: Subcommands::Global(GlobalCmd { global: true })
}
);
+}
+
+#[test]
+fn external_subcommand() {
+ #[derive(Debug, PartialEq, Clap)]
+ struct Opt {
+ #[clap(subcommand)]
+ sub: Subcommands,
+ }
+
+ #[derive(Debug, PartialEq, Clap)]
+ enum Subcommands {
+ Add,
+ Remove,
+ #[clap(external_subcommand)]
+ Other(Vec<String>),
+ }
assert_eq!(
- Opt::parse_from(&["test", "global"]),
+ Opt::parse_from(&["test", "add"]),
Opt {
- global: false,
- sub: Subcommands::Global(GlobalCmd { global: false })
+ sub: Subcommands::Add
}
);
assert_eq!(
- Opt::parse_from(&["test", "global", "--global"]),
+ Opt::parse_from(&["test", "remove"]),
Opt {
- global: true,
- sub: Subcommands::Global(GlobalCmd { global: true })
+ sub: Subcommands::Remove
}
);
@@ -223,7 +235,6 @@ fn external_subcommand() {
assert_eq!(
Opt::try_parse_from(&["test", "git", "status"]).unwrap(),
Opt {
- global: false,
sub: Subcommands::Other(vec!["git".into(), "status".into()])
}
);
