Skip to content

Commit d966d45

Browse files
committed
feat(cli): You can now pass the name of a workflow as an argument to Dobby to bypass the selection prompt (closes #24)
1 parent feea728 commit d966d45

File tree

3 files changed

+91
-2
lines changed

3 files changed

+91
-2
lines changed

Cargo.lock

+66
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ git-conventional = "0.9.1"
2828
markdown = "0.3.0"
2929
ureq = { version = "2.1.1", features = ["json"] }
3030
http = "0.2.4"
31+
clap = "2.33.3"
3132

3233
[dev-dependencies]
3334
tempfile = "3.2.0"

src/main.rs

+24-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#![allow(clippy::multiple_crate_versions)]
33
#![forbid(unsafe_code)]
44

5-
use color_eyre::eyre::{Result, WrapErr};
5+
use clap::{crate_authors, crate_description, crate_version, App, Arg};
6+
use color_eyre::eyre::{ContextCompat, Result, WrapErr};
67

78
use crate::config::Config;
89
use crate::state::State;
@@ -27,12 +28,33 @@ mod workflow;
2728
fn main() -> Result<()> {
2829
color_eyre::install().expect("Could not set up error handling with color_eyre");
2930

31+
let matches = App::new("Dobby")
32+
.version(crate_version!())
33+
.author(crate_authors!())
34+
.about(crate_description!())
35+
.arg(
36+
Arg::with_name("WORKFLOW")
37+
.help("Name a workflow to bypass the interactive select and just run it.")
38+
.index(1),
39+
)
40+
.get_matches();
41+
42+
let preselected_workflow = matches.value_of("WORKFLOW");
43+
3044
let Config {
3145
workflows,
3246
jira,
3347
github,
3448
} = Config::load("dobby.toml").wrap_err("Could not load config file at dobby.toml")?;
35-
let workflow = select(workflows, "Select a workflow")?;
49+
50+
let workflow = match preselected_workflow {
51+
None => select(workflows, "Select a workflow")?,
52+
Some(name) => workflows
53+
.into_iter()
54+
.find(|w| w.name == name)
55+
.wrap_err_with(|| format!("No workflow named {}", name))?,
56+
};
57+
3658
let state = State::new(jira, github);
3759
workflow::run_workflow(workflow, state)
3860
}

0 commit comments

Comments
 (0)