@@ -61,7 +61,9 @@ def print_commands_help(cmds, help_key):
61
61
print ("See https://docs.micropython.org/en/latest/reference/mpremote.html" )
62
62
63
63
print ("\n List of commands:" )
64
- print_commands_help (_COMMANDS , lambda x : x [1 ]().description ) # extract description from argparse
64
+ print_commands_help (
65
+ _COMMANDS , lambda x : x [1 ]().description
66
+ ) # extract description from argparse
65
67
66
68
print ("\n List of shortcuts:" )
67
69
print_commands_help (_command_expansions , lambda x : x [2 ]) # (args, sub, help_message)
@@ -95,7 +97,9 @@ def _bool_flag(cmd_parser, name, short_name, default, description):
95
97
96
98
def argparse_connect ():
97
99
cmd_parser = argparse .ArgumentParser (description = "connect to given device" )
98
- cmd_parser .add_argument ("device" , nargs = 1 , help = "Either list, auto, id:x, port:x, or any valid device name/path" )
100
+ cmd_parser .add_argument (
101
+ "device" , nargs = 1 , help = "Either list, auto, id:x, port:x, or any valid device name/path"
102
+ )
99
103
return cmd_parser
100
104
101
105
@@ -133,7 +137,9 @@ def argparse_repl():
133
137
required = False ,
134
138
help = "saves a copy of the REPL session to the specified path" ,
135
139
)
136
- cmd_parser .add_argument ("--inject-code" , type = str , required = False , help = "code to be run when Ctrl-J is pressed" )
140
+ cmd_parser .add_argument (
141
+ "--inject-code" , type = str , required = False , help = "code to be run when Ctrl-J is pressed"
142
+ )
137
143
cmd_parser .add_argument (
138
144
"--inject-file" ,
139
145
type = str ,
@@ -151,14 +157,18 @@ def argparse_eval():
151
157
152
158
def argparse_exec ():
153
159
cmd_parser = argparse .ArgumentParser (description = "execute the string" )
154
- _bool_flag (cmd_parser , "follow" , "f" , True , "follow output until the expression completes (default)" )
160
+ _bool_flag (
161
+ cmd_parser , "follow" , "f" , True , "follow output until the expression completes (default)"
162
+ )
155
163
cmd_parser .add_argument ("expr" , nargs = 1 , help = "expression to execute" )
156
164
return cmd_parser
157
165
158
166
159
167
def argparse_run ():
160
168
cmd_parser = argparse .ArgumentParser (description = "run the given local script" )
161
- _bool_flag (cmd_parser , "follow" , "f" , True , "follow output until the script completes (default)" )
169
+ _bool_flag (
170
+ cmd_parser , "follow" , "f" , True , "follow output until the script completes (default)"
171
+ )
162
172
cmd_parser .add_argument ("path" , nargs = 1 , help = "path to script to execute" )
163
173
return cmd_parser
164
174
@@ -179,15 +189,21 @@ def argparse_filesystem():
179
189
None ,
180
190
"enable verbose output (defaults to True for all commands except cat)" ,
181
191
)
182
- cmd_parser .add_argument ("command" , nargs = 1 , help = "filesystem command (e.g. cat, cp, ls, rm, touch)" )
192
+ cmd_parser .add_argument (
193
+ "command" , nargs = 1 , help = "filesystem command (e.g. cat, cp, ls, rm, touch)"
194
+ )
183
195
cmd_parser .add_argument ("path" , nargs = "+" , help = "local and remote paths" )
184
196
return cmd_parser
185
197
186
198
187
199
def argparse_mip ():
188
- cmd_parser = argparse .ArgumentParser (description = "install packages from micropython-lib or third-party sources" )
200
+ cmd_parser = argparse .ArgumentParser (
201
+ description = "install packages from micropython-lib or third-party sources"
202
+ )
189
203
_bool_flag (cmd_parser , "mpy" , "m" , True , "download as compiled .mpy files (default)" )
190
- cmd_parser .add_argument ("--target" , type = str , required = False , help = "destination direction on the device" )
204
+ cmd_parser .add_argument (
205
+ "--target" , type = str , required = False , help = "destination direction on the device"
206
+ )
191
207
cmd_parser .add_argument (
192
208
"--index" ,
193
209
type = str ,
@@ -330,10 +346,10 @@ def argparse_none(description):
330
346
for port_num in range (4 ):
331
347
for prefix , port in [("a" , "/dev/ttyACM" ), ("u" , "/dev/ttyUSB" ), ("c" , "COM" )]:
332
348
if port_num == 0 and port == "COM" :
333
- continue # skip COM0 as it does not exist
334
- _BUILTIN_COMMAND_EXPANSIONS [f" { prefix } { port_num } " ] = {
335
- "command" : f "connect { port } { port_num } " ,
336
- "help" : f 'connect to serial port "{ port } { port_num } "' ,
349
+ continue # skip COM0 as it does not exist on Windows
350
+ _BUILTIN_COMMAND_EXPANSIONS ["{}{}" . format ( prefix , port_num ) ] = {
351
+ "command" : "connect {}{}" . format ( port , port_num ) ,
352
+ "help" : 'connect to serial port "{}{ }"' . format ( port , port_num ) ,
337
353
}
338
354
339
355
@@ -357,7 +373,6 @@ def load_user_config():
357
373
break
358
374
if not path :
359
375
return config
360
-
361
376
config_file = os .path .join (path , "config.py" )
362
377
# Check if config file exists.
363
378
if not os .path .exists (config_file ):
@@ -514,7 +529,9 @@ def main():
514
529
cmd_parser = parser_func ()
515
530
cmd_parser .prog = cmd
516
531
# Catch all for unhandled positional arguments (this is the next command).
517
- cmd_parser .add_argument ("next_command" , nargs = argparse .REMAINDER , help = f"Next { _PROG } command" )
532
+ cmd_parser .add_argument (
533
+ "next_command" , nargs = argparse .REMAINDER , help = f"Next { _PROG } command"
534
+ )
518
535
args = cmd_parser .parse_args (command_args )
519
536
520
537
# Execute command.
0 commit comments