37
37
//! it will have your modules loaded into the vm.
38
38
#![ allow( clippy:: needless_doctest_main, clippy:: unnecessary_wraps) ]
39
39
40
- #[ macro_use]
41
40
extern crate clap;
42
41
extern crate env_logger;
43
42
#[ macro_use]
68
67
#[ cfg( feature = "flame-it" ) ]
69
68
let main_guard = flame:: start_guard ( "RustPython main" ) ;
70
69
env_logger:: init ( ) ;
71
- let app = App :: new ( "RustPython" ) ;
72
- let matches = parse_arguments ( app) ;
70
+ let matches = parse_arguments ( ) ;
73
71
let settings = create_settings ( & matches) ;
74
72
75
73
// don't translate newlines (\r\n <=> \n)
@@ -160,125 +158,125 @@ fn flush_std(vm: &VirtualMachine) {
160
158
}
161
159
}
162
160
163
- fn parse_arguments < ' a > ( app : App < ' a , ' _ > ) -> ArgMatches < ' a > {
164
- let app = app
161
+ fn parse_arguments ( ) -> ArgMatches {
162
+ let app = App :: new ( "RustPython" )
165
163
. setting ( AppSettings :: TrailingVarArg )
166
- . version ( crate_version ! ( ) )
167
- . author ( crate_authors ! ( ) )
164
+ . version ( env ! ( "CARGO_PKG_VERSION" ) )
165
+ . author ( env ! ( "CARGO_PKG_AUTHORS" ) )
168
166
. about ( "Rust implementation of the Python language" )
169
- . usage ( "rustpython [OPTIONS] [-c CMD | -m MODULE | FILE] [PYARGS]..." )
167
+ . override_usage ( "rustpython [OPTIONS] [-c CMD | -m MODULE | FILE] [PYARGS]..." )
170
168
. arg (
171
- Arg :: with_name ( "script" )
169
+ Arg :: new ( "script" )
172
170
. required ( false )
173
171
. allow_hyphen_values ( true )
174
- . multiple ( true )
172
+ . multiple_values ( true )
175
173
. value_name ( "script, args" )
176
174
. min_values ( 1 ) ,
177
175
)
178
176
. arg (
179
- Arg :: with_name ( "c" )
180
- . short ( "c" )
177
+ Arg :: new ( "c" )
178
+ . short ( 'c' )
181
179
. takes_value ( true )
182
180
. allow_hyphen_values ( true )
183
- . multiple ( true )
181
+ . multiple_values ( true )
184
182
. value_name ( "cmd, args" )
185
183
. min_values ( 1 )
186
184
. help ( "run the given string as a program" ) ,
187
185
)
188
186
. arg (
189
- Arg :: with_name ( "m" )
190
- . short ( "m" )
187
+ Arg :: new ( "m" )
188
+ . short ( 'm' )
191
189
. takes_value ( true )
192
190
. allow_hyphen_values ( true )
193
- . multiple ( true )
191
+ . multiple_values ( true )
194
192
. value_name ( "module, args" )
195
193
. min_values ( 1 )
196
194
. help ( "run library module as script" ) ,
197
195
)
198
196
. arg (
199
- Arg :: with_name ( "install_pip" )
197
+ Arg :: new ( "install_pip" )
200
198
. long ( "install-pip" )
201
199
. takes_value ( true )
202
200
. allow_hyphen_values ( true )
203
- . multiple ( true )
201
+ . multiple_values ( true )
204
202
. value_name ( "get-pip args" )
205
203
. min_values ( 0 )
206
204
. help ( "install the pip package manager for rustpython; \
207
205
requires rustpython be build with the ssl feature enabled."
208
206
) ,
209
207
)
210
208
. arg (
211
- Arg :: with_name ( "optimize" )
212
- . short ( "O" )
213
- . multiple ( true )
209
+ Arg :: new ( "optimize" )
210
+ . short ( 'O' )
211
+ . multiple_occurrences ( true )
214
212
. help ( "Optimize. Set __debug__ to false. Remove debug statements." ) ,
215
213
)
216
214
. arg (
217
- Arg :: with_name ( "verbose" )
218
- . short ( "v" )
219
- . multiple ( true )
215
+ Arg :: new ( "verbose" )
216
+ . short ( 'v' )
217
+ . multiple_occurrences ( true )
220
218
. help ( "Give the verbosity (can be applied multiple times)" ) ,
221
219
)
222
- . arg ( Arg :: with_name ( "debug" ) . short ( "d" ) . help ( "Debug the parser." ) )
220
+ . arg ( Arg :: new ( "debug" ) . short ( 'd' ) . help ( "Debug the parser." ) )
223
221
. arg (
224
- Arg :: with_name ( "quiet" )
225
- . short ( "q" )
222
+ Arg :: new ( "quiet" )
223
+ . short ( 'q' )
226
224
. help ( "Be quiet at startup." ) ,
227
225
)
228
226
. arg (
229
- Arg :: with_name ( "inspect" )
230
- . short ( "i" )
227
+ Arg :: new ( "inspect" )
228
+ . short ( 'i' )
231
229
. help ( "Inspect interactively after running the script." ) ,
232
230
)
233
231
. arg (
234
- Arg :: with_name ( "no-user-site" )
235
- . short ( "s" )
232
+ Arg :: new ( "no-user-site" )
233
+ . short ( 's' )
236
234
. help ( "don't add user site directory to sys.path." ) ,
237
235
)
238
236
. arg (
239
- Arg :: with_name ( "no-site" )
240
- . short ( "S" )
237
+ Arg :: new ( "no-site" )
238
+ . short ( 'S' )
241
239
. help ( "don't imply 'import site' on initialization" ) ,
242
240
)
243
241
. arg (
244
- Arg :: with_name ( "dont-write-bytecode" )
245
- . short ( "B" )
242
+ Arg :: new ( "dont-write-bytecode" )
243
+ . short ( 'B' )
246
244
. help ( "don't write .pyc files on import" ) ,
247
245
)
248
246
. arg (
249
- Arg :: with_name ( "ignore-environment" )
250
- . short ( "E" )
247
+ Arg :: new ( "ignore-environment" )
248
+ . short ( 'E' )
251
249
. help ( "Ignore environment variables PYTHON* such as PYTHONPATH" ) ,
252
250
)
253
251
. arg (
254
- Arg :: with_name ( "isolate" )
255
- . short ( "I" )
252
+ Arg :: new ( "isolate" )
253
+ . short ( 'I' )
256
254
. help ( "isolate Python from the user's environment (implies -E and -s)" ) ,
257
255
)
258
256
. arg (
259
- Arg :: with_name ( "implementation-option" )
260
- . short ( "X" )
257
+ Arg :: new ( "implementation-option" )
258
+ . short ( 'X' )
261
259
. takes_value ( true )
262
- . multiple ( true )
260
+ . multiple_occurrences ( true )
263
261
. number_of_values ( 1 )
264
262
. help ( "set implementation-specific option" ) ,
265
263
)
266
264
. arg (
267
- Arg :: with_name ( "warning-control" )
268
- . short ( "W" )
265
+ Arg :: new ( "warning-control" )
266
+ . short ( 'W' )
269
267
. takes_value ( true )
270
- . multiple ( true )
268
+ . multiple_occurrences ( true )
271
269
. number_of_values ( 1 )
272
270
. help ( "warning control; arg is action:message:category:module:lineno" ) ,
273
271
)
274
272
. arg (
275
- Arg :: with_name ( "bytes-warning" )
276
- . short ( "b" )
277
- . multiple ( true )
273
+ Arg :: new ( "bytes-warning" )
274
+ . short ( 'b' )
275
+ . multiple_occurrences ( true )
278
276
. help ( "issue warnings about using bytes where strings are usually expected (-bb: issue errors)" ) ,
279
277
) . arg (
280
- Arg :: with_name ( "unbuffered" )
281
- . short ( "u" )
278
+ Arg :: new ( "unbuffered" )
279
+ . short ( 'u' )
282
280
. help (
283
281
"force the stdout and stderr streams to be unbuffered; \
284
282
this option has no effect on stdin; also PYTHONUNBUFFERED=x",
@@ -287,13 +285,13 @@ fn parse_arguments<'a>(app: App<'a, '_>) -> ArgMatches<'a> {
287
285
#[ cfg( feature = "flame-it" ) ]
288
286
let app = app
289
287
. arg (
290
- Arg :: with_name ( "profile_output" )
288
+ Arg :: new ( "profile_output" )
291
289
. long ( "profile-output" )
292
290
. takes_value ( true )
293
291
. help ( "the file to output the profiling information to" ) ,
294
292
)
295
293
. arg (
296
- Arg :: with_name ( "profile_format" )
294
+ Arg :: new ( "profile_format" )
297
295
. long ( "profile-format" )
298
296
. takes_value ( true )
299
297
. help ( "the profile format to output the profiling information in" ) ,
@@ -609,7 +607,7 @@ fn run_rustpython(vm: &VirtualMachine, matches: &ArgMatches) -> PyResult<()> {
609
607
} else {
610
608
println ! (
611
609
"Welcome to the magnificent Rust Python {} interpreter \u{1f631} \u{1f596} " ,
612
- crate_version! ( )
610
+ env! ( "CARGO_PKG_VERSION" )
613
611
) ;
614
612
shell:: run_shell ( vm, scope) ?;
615
613
}
0 commit comments