@@ -178,8 +178,8 @@ def main( # pylint: disable=too-many-locals
178178 else (cpy_version , board_id )
179179 )
180180 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
183183 )
184184 )
185185 try :
@@ -406,31 +406,53 @@ def install(
406406
407407@main .command ()
408408@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." )
409411@click .argument (
410- "examples" , required = True , nargs = - 1 , shell_complete = completion_for_example
412+ "examples" , required = False , nargs = - 1 , shell_complete = completion_for_example
411413)
412414@click .pass_context
413- def example (ctx , examples , overwrite ):
415+ def example (ctx , examples , op_list , rename , overwrite ):
414416 """
415417 Copy named example(s) from a bundle onto the device. Multiple examples
416418 can be installed at once by providing more than one example name, each
417419 separated by a space.
418420 """
419421
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+
420437 for example_arg in examples :
421438 available_examples = get_bundle_examples (
422439 get_bundles_list (), avoid_download = True
423440 )
424441 if example_arg in available_examples :
425442 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
426450
427451 if overwrite or not ctx .obj ["backend" ].file_exists (filename ):
428452 click .echo (
429453 f"{ 'Copying' if not overwrite else 'Overwriting' } : { filename } "
430454 )
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 = "" )
434456 else :
435457 click .secho (
436458 f"File: { filename } already exists. Use --overwrite if you wish to replace it." ,
0 commit comments