11use clap:: { Args , Subcommand , ValueEnum } ;
2- use xshell:: cmd;
2+ use xshell:: { cmd, Cmd } ;
33
44use crate :: { sh, Result } ;
55
@@ -99,17 +99,21 @@ fn check_prerequisites() {
9999 }
100100}
101101
102+ fn append_options < ' a > ( command : Cmd < ' a > , execute : & bool , package : & Option < String > ) -> Cmd < ' a > {
103+ let command = if * execute { command. arg ( "--execute" ) } else { command } ;
104+ if let Some ( package) = package. as_deref ( ) {
105+ command. args ( [ "--package" , package] )
106+ } else {
107+ command. arg ( "--workspace" )
108+ }
109+ }
110+
102111fn prepare ( version : ReleaseVersion , execute : bool , package : Option < String > ) -> Result < ( ) > {
103112 let sh = sh ( ) ;
104- let cmd = cmd ! ( sh, "cargo release --no-publish --no-tag --no-push" ) ;
105113
106- let cmd = if let Some ( package) = package {
107- cmd. args ( [ "--package" , & package] )
108- } else {
109- cmd. arg ( "--workspace" )
110- } ;
114+ let cmd = cmd ! ( sh, "cargo release --no-publish --no-tag --no-push" ) ;
115+ let cmd = append_options ( cmd, & execute, & package) ;
111116
112- let cmd = if execute { cmd. arg ( "--execute" ) } else { cmd } ;
113117 let cmd = cmd. arg ( version. as_str ( ) ) ;
114118
115119 cmd. run ( ) ?;
@@ -129,30 +133,15 @@ fn publish(execute: bool, package: Option<String>) -> Result<()> {
129133 let sh = sh ( ) ;
130134
131135 let cmd = cmd ! ( sh, "cargo release tag" ) ;
132- let cmd = if execute { cmd. arg ( "--execute" ) } else { cmd } ;
133- let cmd = if let Some ( package) = package. as_deref ( ) {
134- cmd. args ( [ "--package" , package] )
135- } else {
136- cmd. arg ( "--workspace" )
137- } ;
136+ let cmd = append_options ( cmd, & execute, & package) ;
138137 cmd. run ( ) ?;
139138
140139 let cmd = cmd ! ( sh, "cargo release publish" ) ;
141- let cmd = if execute { cmd. arg ( "--execute" ) } else { cmd } ;
142- let cmd = if let Some ( package) = package. as_deref ( ) {
143- cmd. args ( [ "--package" , & package] )
144- } else {
145- cmd. arg ( "--workspace" )
146- } ;
140+ let cmd = append_options ( cmd, & execute, & package) ;
147141 cmd. run ( ) ?;
148142
149143 let cmd = cmd ! ( sh, "cargo release push" ) ;
150- let cmd = if execute { cmd. arg ( "--execute" ) } else { cmd } ;
151- let cmd = if let Some ( package) = package. as_deref ( ) {
152- cmd. args ( [ "--package" , & package] )
153- } else {
154- cmd. arg ( "--workspace" )
155- } ;
144+ let cmd = append_options ( cmd, & execute, & package) ;
156145 cmd. run ( ) ?;
157146
158147 Ok ( ( ) )
0 commit comments