@@ -178,8 +178,8 @@ def main( # pylint: disable=too-many-locals
178
178
else (cpy_version , board_id )
179
179
)
180
180
click .echo (
181
- "Found device at {}, running CircuitPython {}." .format (
182
- device_path , cpy_version
181
+ "Found device {} at {}, running CircuitPython {}." .format (
182
+ board_id , device_path , cpy_version
183
183
)
184
184
)
185
185
try :
@@ -406,31 +406,53 @@ def install(
406
406
407
407
@main .command ()
408
408
@click .option ("--overwrite" , is_flag = True , help = "Overwrite the file if it exists." )
409
+ @click .option ("--list" , "-ls" , "op_list" , is_flag = True , help = "List available examples." )
410
+ @click .option ("--rename" , is_flag = True , help = "Install the example as code.py." )
409
411
@click .argument (
410
- "examples" , required = True , nargs = - 1 , shell_complete = completion_for_example
412
+ "examples" , required = False , nargs = - 1 , shell_complete = completion_for_example
411
413
)
412
414
@click .pass_context
413
- def example (ctx , examples , overwrite ):
415
+ def example (ctx , examples , op_list , rename , overwrite ):
414
416
"""
415
417
Copy named example(s) from a bundle onto the device. Multiple examples
416
418
can be installed at once by providing more than one example name, each
417
419
separated by a space.
418
420
"""
419
421
422
+ if op_list :
423
+ if examples :
424
+ click .echo ("\n " .join (completion_for_example (ctx , "" , examples )))
425
+ else :
426
+ click .echo ("Available example libraries:" )
427
+ available_examples = get_bundle_examples (
428
+ get_bundles_list (), avoid_download = True
429
+ )
430
+ lib_names = {
431
+ str (key .split (os .path .sep )[0 ]): value
432
+ for key , value in available_examples .items ()
433
+ }
434
+ click .echo ("\n " .join (sorted (lib_names .keys ())))
435
+ return
436
+
420
437
for example_arg in examples :
421
438
available_examples = get_bundle_examples (
422
439
get_bundles_list (), avoid_download = True
423
440
)
424
441
if example_arg in available_examples :
425
442
filename = available_examples [example_arg ].split (os .path .sep )[- 1 ]
443
+ install_metadata = {"path" : available_examples [example_arg ]}
444
+
445
+ filename = available_examples [example_arg ].split (os .path .sep )[- 1 ]
446
+ if rename :
447
+ if os .path .isfile (available_examples [example_arg ]):
448
+ filename = "code.py"
449
+ install_metadata ["target_name" ] = filename
426
450
427
451
if overwrite or not ctx .obj ["backend" ].file_exists (filename ):
428
452
click .echo (
429
453
f"{ 'Copying' if not overwrite else 'Overwriting' } : { filename } "
430
454
)
431
- ctx .obj ["backend" ].install_module_py (
432
- {"path" : available_examples [example_arg ]}, location = ""
433
- )
455
+ ctx .obj ["backend" ].install_module_py (install_metadata , location = "" )
434
456
else :
435
457
click .secho (
436
458
f"File: { filename } already exists. Use --overwrite if you wish to replace it." ,
0 commit comments