2
2
#![ allow( clippy:: multiple_crate_versions) ]
3
3
#![ forbid( unsafe_code) ]
4
4
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 } ;
6
7
7
8
use crate :: config:: Config ;
8
9
use crate :: state:: State ;
@@ -27,12 +28,33 @@ mod workflow;
27
28
fn main ( ) -> Result < ( ) > {
28
29
color_eyre:: install ( ) . expect ( "Could not set up error handling with color_eyre" ) ;
29
30
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
+
30
44
let Config {
31
45
workflows,
32
46
jira,
33
47
github,
34
48
} = 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
+
36
58
let state = State :: new ( jira, github) ;
37
59
workflow:: run_workflow ( workflow, state)
38
60
}
0 commit comments