@@ -96,13 +96,13 @@ impl BuildKind {
9696
9797fn parse_args ( ) -> Args {
9898 use clap:: { App , Arg , ArgGroup } ;
99+ use std:: iter:: FromIterator ;
99100 let version = option_env ! ( "CARGO_PKG_VERSION" ) . unwrap_or ( "unknown" ) ;
100101 let about = r#"Compiles and runs a Rust script."# ;
101102
102103 let app = App :: new ( consts:: PROGRAM_NAME )
103104 . version ( version)
104105 . setting ( clap:: AppSettings :: TrailingVarArg )
105- . setting ( clap:: AppSettings :: AllowLeadingHyphen )
106106 . about ( about)
107107 . arg ( Arg :: new ( "script" )
108108 . index ( 1 )
@@ -117,12 +117,7 @@ fn parse_args() -> Args {
117117 } else {
118118 & [ "list-templates" ]
119119 } )
120- )
121- . arg ( Arg :: new ( "script-args" )
122- . index ( 2 )
123- . about ( "Arguments for the script to execute." )
124120 . multiple_values ( true )
125- . min_values ( 0 )
126121 )
127122 . arg ( Arg :: new ( "expr" )
128123 . about ( "Execute <script> as a literal expression and display the result." )
@@ -213,7 +208,7 @@ fn parse_args() -> Args {
213208 . about ( "Generate the Cargo package, but don't compile or run it." )
214209 . long ( "gen-pkg-only" )
215210 . requires ( "script" )
216- . conflicts_with_all ( & [ "script-args" , " debug", "force" , "test" , "bench" ] )
211+ . conflicts_with_all ( & [ "debug" , "force" , "test" , "bench" ] )
217212 )
218213 . arg ( Arg :: new ( "pkg_path" )
219214 . about ( "Specify where to place the generated Cargo package." )
@@ -225,12 +220,12 @@ fn parse_args() -> Args {
225220 . arg ( Arg :: new ( "test" )
226221 . about ( "Compile and run tests." )
227222 . long ( "test" )
228- . conflicts_with_all ( & [ "bench" , "debug" , "script-args" , " force"] )
223+ . conflicts_with_all ( & [ "bench" , "debug" , "force" ] )
229224 )
230225 . arg ( Arg :: new ( "bench" )
231226 . about ( "Compile and run benchmarks. Requires a nightly toolchain." )
232227 . long ( "bench" )
233- . conflicts_with_all ( & [ "test" , "debug" , "script-args" , " force"] )
228+ . conflicts_with_all ( & [ "test" , "debug" , "force" ] )
234229 )
235230 . arg ( Arg :: new ( "template" )
236231 . about ( "Specify a template to use for expression scripts." )
@@ -281,9 +276,24 @@ fn parse_args() -> Args {
281276 . unwrap_or_default ( )
282277 }
283278
279+ let script_and_args: Option < Vec < & str > > = m. values_of ( "script" ) . map ( |o| o. collect ( ) ) ;
280+ let script;
281+ let script_args: Vec < String > ;
282+ if let Some ( script_and_args) = script_and_args {
283+ script = script_and_args. get ( 0 ) . map ( |s| s. to_string ( ) ) ;
284+ script_args = if script_and_args. len ( ) > 1 {
285+ Vec :: from_iter ( script_and_args[ 1 ..] . iter ( ) . map ( |s| s. to_string ( ) ) )
286+ } else {
287+ Vec :: new ( )
288+ } ;
289+ } else {
290+ script = None ;
291+ script_args = Vec :: new ( ) ;
292+ }
293+
284294 Args {
285- script : m . value_of ( "script" ) . map ( Into :: into ) ,
286- script_args : owned_vec_string ( m . values_of ( "script-args" ) ) ,
295+ script,
296+ script_args,
287297 features : m. value_of ( "features" ) . map ( Into :: into) ,
288298
289299 expr : m. is_present ( "expr" ) ,
0 commit comments