Skip to content

Commit 87cf8cf

Browse files
authored
Merge pull request #145 from suntomi/umegaya/fix-clap
fix clap option configuration
2 parents 7a14fd0 + d03fe5b commit 87cf8cf

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ target
22
.env*
33
.deplo
44
.secrets
5-
payload.json
5+
payload*.json

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"request": "launch",
103103
"program": "${workspaceFolder}/target/debug/cli",
104104
"args": [
105-
"-v=3", "halt", "-r=nightly", "-w=integrate"
105+
"-v=3", "halt", "-p=payload.json"
106106
]
107107
},
108108
{

core/src/args.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,7 @@ pub trait Args : Sized {
1515
fn values_of(&self, name: &str) -> Option<Vec<&str>>;
1616
fn command_path(&self) -> &Vec<&str>;
1717
fn get_flag(&self, name: &str) -> bool;
18-
fn value_of(&self, name: &str) -> Option<&str> {
19-
match self.values_of(name) {
20-
Some(v) => if v.len() > 0 { Some(v[0]) } else { None },
21-
None => None
22-
}
23-
}
18+
fn value_of(&self, name: &str) -> Option<&str>;
2419
fn value_or_die(&self, name: &str) -> &str {
2520
self.value_of(name).expect(&format!("missing cli arg '{}'", name))
2621
}

core/src/args/clap.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ fn run_command_options(
144144
.help("only works with --remote, don't wait for finishing remote job")
145145
.long("async")
146146
.conflicts_with("follow_dependency")
147+
.action(clap::ArgAction::SetTrue)
147148
.required(false))
148149
.arg(Arg::new("follow_dependency")
149150
.help("if set, not only run the specified job but run dependent jobs first")
@@ -261,8 +262,11 @@ lazy_static! {
261262
)
262263
)
263264
.subcommand(
264-
Command::new("halt")
265-
.about("halt and cleanup deplo workflow")
265+
workflow_command_options(
266+
"halt",
267+
"halt deplo workflow",
268+
None
269+
)
266270
)
267271
.subcommand(
268272
run_command_options(
@@ -506,10 +510,22 @@ impl<'a> args::Args for Clap<'a> {
506510
fn get_flag(&self, name: &str) -> bool {
507511
return self.matches.get_flag(name);
508512
}
513+
fn value_of(&self, name: &str) -> Option<&str> {
514+
match self.matches.try_get_one::<String>(name) {
515+
Ok(v) => match v {
516+
Some(v) => Some(v.as_str()),
517+
None => None
518+
}
519+
Err(_) => None
520+
}
521+
}
509522
fn values_of(&self, name: &str) -> Option<Vec<&str>> {
510-
match self.matches.get_many::<String>(name) {
511-
Some(it) => Some(it.map(|s| s.as_str()).collect()),
512-
None => None
523+
match self.matches.try_get_many::<String>(name) {
524+
Ok(vs) => match vs {
525+
Some(vs) => Some(vs.map(|v| v.as_str()).collect()),
526+
None => None
527+
}
528+
Err(_) => None
513529
}
514530
}
515531
fn command_path(&self) -> &Vec<&str> {

0 commit comments

Comments
 (0)