@@ -96,13 +96,13 @@ impl BuildKind {
96
96
97
97
fn parse_args ( ) -> Args {
98
98
use clap:: { App , Arg , ArgGroup } ;
99
+ use std:: iter:: FromIterator ;
99
100
let version = option_env ! ( "CARGO_PKG_VERSION" ) . unwrap_or ( "unknown" ) ;
100
101
let about = r#"Compiles and runs a Rust script."# ;
101
102
102
103
let app = App :: new ( consts:: PROGRAM_NAME )
103
104
. version ( version)
104
105
. setting ( clap:: AppSettings :: TrailingVarArg )
105
- . setting ( clap:: AppSettings :: AllowLeadingHyphen )
106
106
. about ( about)
107
107
. arg ( Arg :: new ( "script" )
108
108
. index ( 1 )
@@ -117,12 +117,7 @@ fn parse_args() -> Args {
117
117
} else {
118
118
& [ "list-templates" ]
119
119
} )
120
- )
121
- . arg ( Arg :: new ( "script-args" )
122
- . index ( 2 )
123
- . about ( "Arguments for the script to execute." )
124
120
. multiple_values ( true )
125
- . min_values ( 0 )
126
121
)
127
122
. arg ( Arg :: new ( "expr" )
128
123
. about ( "Execute <script> as a literal expression and display the result." )
@@ -213,7 +208,7 @@ fn parse_args() -> Args {
213
208
. about ( "Generate the Cargo package, but don't compile or run it." )
214
209
. long ( "gen-pkg-only" )
215
210
. requires ( "script" )
216
- . conflicts_with_all ( & [ "script-args" , " debug", "force" , "test" , "bench" ] )
211
+ . conflicts_with_all ( & [ "debug" , "force" , "test" , "bench" ] )
217
212
)
218
213
. arg ( Arg :: new ( "pkg_path" )
219
214
. about ( "Specify where to place the generated Cargo package." )
@@ -225,12 +220,12 @@ fn parse_args() -> Args {
225
220
. arg ( Arg :: new ( "test" )
226
221
. about ( "Compile and run tests." )
227
222
. long ( "test" )
228
- . conflicts_with_all ( & [ "bench" , "debug" , "script-args" , " force"] )
223
+ . conflicts_with_all ( & [ "bench" , "debug" , "force" ] )
229
224
)
230
225
. arg ( Arg :: new ( "bench" )
231
226
. about ( "Compile and run benchmarks. Requires a nightly toolchain." )
232
227
. long ( "bench" )
233
- . conflicts_with_all ( & [ "test" , "debug" , "script-args" , " force"] )
228
+ . conflicts_with_all ( & [ "test" , "debug" , "force" ] )
234
229
)
235
230
. arg ( Arg :: new ( "template" )
236
231
. about ( "Specify a template to use for expression scripts." )
@@ -281,9 +276,24 @@ fn parse_args() -> Args {
281
276
. unwrap_or_default ( )
282
277
}
283
278
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
+
284
294
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,
287
297
features : m. value_of ( "features" ) . map ( Into :: into) ,
288
298
289
299
expr : m. is_present ( "expr" ) ,
0 commit comments