@@ -61,9 +61,7 @@ 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 (
65
- _COMMANDS , lambda x : x [1 ]().description
66
- ) # extract description from argparse
64
+ print_commands_help (_COMMANDS , lambda x : x [1 ]().description ) # extract description from argparse
67
65
68
66
print ("\n List of shortcuts:" )
69
67
print_commands_help (_command_expansions , lambda x : x [2 ]) # (args, sub, help_message)
@@ -97,9 +95,7 @@ def _bool_flag(cmd_parser, name, short_name, default, description):
97
95
98
96
def argparse_connect ():
99
97
cmd_parser = argparse .ArgumentParser (description = "connect to given device" )
100
- cmd_parser .add_argument (
101
- "device" , nargs = 1 , help = "Either list, auto, id:x, port:x, or any valid device name/path"
102
- )
98
+ cmd_parser .add_argument ("device" , nargs = 1 , help = "Either list, auto, id:x, port:x, or any valid device name/path" )
103
99
return cmd_parser
104
100
105
101
@@ -137,9 +133,7 @@ def argparse_repl():
137
133
required = False ,
138
134
help = "saves a copy of the REPL session to the specified path" ,
139
135
)
140
- cmd_parser .add_argument (
141
- "--inject-code" , type = str , required = False , help = "code to be run when Ctrl-J is pressed"
142
- )
136
+ cmd_parser .add_argument ("--inject-code" , type = str , required = False , help = "code to be run when Ctrl-J is pressed" )
143
137
cmd_parser .add_argument (
144
138
"--inject-file" ,
145
139
type = str ,
@@ -157,18 +151,14 @@ def argparse_eval():
157
151
158
152
def argparse_exec ():
159
153
cmd_parser = argparse .ArgumentParser (description = "execute the string" )
160
- _bool_flag (
161
- cmd_parser , "follow" , "f" , True , "follow output until the expression completes (default)"
162
- )
154
+ _bool_flag (cmd_parser , "follow" , "f" , True , "follow output until the expression completes (default)" )
163
155
cmd_parser .add_argument ("expr" , nargs = 1 , help = "expression to execute" )
164
156
return cmd_parser
165
157
166
158
167
159
def argparse_run ():
168
160
cmd_parser = argparse .ArgumentParser (description = "run the given local script" )
169
- _bool_flag (
170
- cmd_parser , "follow" , "f" , True , "follow output until the script completes (default)"
171
- )
161
+ _bool_flag (cmd_parser , "follow" , "f" , True , "follow output until the script completes (default)" )
172
162
cmd_parser .add_argument ("path" , nargs = 1 , help = "path to script to execute" )
173
163
return cmd_parser
174
164
@@ -189,21 +179,15 @@ def argparse_filesystem():
189
179
None ,
190
180
"enable verbose output (defaults to True for all commands except cat)" ,
191
181
)
192
- cmd_parser .add_argument (
193
- "command" , nargs = 1 , help = "filesystem command (e.g. cat, cp, ls, rm, touch)"
194
- )
182
+ cmd_parser .add_argument ("command" , nargs = 1 , help = "filesystem command (e.g. cat, cp, ls, rm, touch)" )
195
183
cmd_parser .add_argument ("path" , nargs = "+" , help = "local and remote paths" )
196
184
return cmd_parser
197
185
198
186
199
187
def argparse_mip ():
200
- cmd_parser = argparse .ArgumentParser (
201
- description = "install packages from micropython-lib or third-party sources"
202
- )
188
+ cmd_parser = argparse .ArgumentParser (description = "install packages from micropython-lib or third-party sources" )
203
189
_bool_flag (cmd_parser , "mpy" , "m" , True , "download as compiled .mpy files (default)" )
204
- cmd_parser .add_argument (
205
- "--target" , type = str , required = False , help = "destination direction on the device"
206
- )
190
+ cmd_parser .add_argument ("--target" , type = str , required = False , help = "destination direction on the device" )
207
191
cmd_parser .add_argument (
208
192
"--index" ,
209
193
type = str ,
@@ -341,13 +325,15 @@ def argparse_none(description):
341
325
"--version" : "version" ,
342
326
}
343
327
344
- # Add "a0", "a1", ..., "u0", "u1", ..., "c0 ", "c1 ", ... as aliases
328
+ # Add "a0", "a1", ..., "u0", "u1", ..., "c1 ", "c2 ", ... as aliases
345
329
# for "connect /dev/ttyACMn" (and /dev/ttyUSBn, COMn) etc.
346
330
for port_num in range (4 ):
347
331
for prefix , port in [("a" , "/dev/ttyACM" ), ("u" , "/dev/ttyUSB" ), ("c" , "COM" )]:
348
- _BUILTIN_COMMAND_EXPANSIONS ["{}{}" .format (prefix , port_num )] = {
349
- "command" : "connect {}{}" .format (port , port_num ),
350
- "help" : 'connect to serial port "{}{}"' .format (port , port_num ),
332
+ 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 } "' ,
351
337
}
352
338
353
339
@@ -361,16 +347,17 @@ def load_user_config():
361
347
path = os .getenv (env_var )
362
348
if not path :
363
349
continue
364
- if os .path .exists ( os .path .join (path ,".config" , _PROG , "config.py" )):
350
+ if os .path .exists (os .path .join (path , ".config" , _PROG , "config.py" )):
365
351
# Unix style
366
- path = os .path .join (path ,".config" , _PROG , "config.py" )
352
+ path = os .path .join (path , ".config" , _PROG , "config.py" )
367
353
break
368
- elif os .path .exists ( os .path .join (path , _PROG , "config.py" )):
354
+ elif os .path .exists (os .path .join (path , _PROG , "config.py" )):
369
355
# Windows style
370
- path = os .path .join (path , _PROG ,"config.py" )
356
+ path = os .path .join (path , _PROG , "config.py" )
371
357
break
372
358
if not path :
373
359
return config
360
+
374
361
config_file = os .path .join (path , "config.py" )
375
362
# Check if config file exists.
376
363
if not os .path .exists (config_file ):
@@ -386,7 +373,6 @@ def load_user_config():
386
373
config .__dict__ ["__file__" ] = config_file
387
374
exec (config_data , config .__dict__ )
388
375
os .chdir (prev_cwd )
389
-
390
376
return config
391
377
392
378
@@ -528,9 +514,7 @@ def main():
528
514
cmd_parser = parser_func ()
529
515
cmd_parser .prog = cmd
530
516
# Catch all for unhandled positional arguments (this is the next command).
531
- cmd_parser .add_argument (
532
- "next_command" , nargs = argparse .REMAINDER , help = f"Next { _PROG } command"
533
- )
517
+ cmd_parser .add_argument ("next_command" , nargs = argparse .REMAINDER , help = f"Next { _PROG } command" )
534
518
args = cmd_parser .parse_args (command_args )
535
519
536
520
# Execute command.
0 commit comments