1
1
#!/usr/bin/env python
2
+ # PYTHON_ARGCOMPLETE_OK
2
3
# Copyright FuseSoC contributors
3
4
# Licensed under the 2-Clause BSD License, see LICENSE for details.
4
5
# SPDX-License-Identifier: BSD-2-Clause
11
12
import warnings
12
13
from pathlib import Path
13
14
15
+ import argcomplete
16
+
14
17
try :
15
18
from fusesoc .version import version as __version__
16
19
except ImportError :
@@ -397,6 +400,41 @@ def update(fs, args):
397
400
fs .update_libraries (args .libraries )
398
401
399
402
403
+ class CoreCompleter :
404
+ def __call__ (self , parsed_args , ** kwargs ):
405
+ config = Config (parsed_args .config )
406
+ args_to_config (parsed_args , config )
407
+ fs = Fusesoc (config )
408
+ cores = fs .get_cores ()
409
+ return cores
410
+
411
+
412
+ class ToolCompleter :
413
+ def __call__ (self , parsed_args , ** kwargs ):
414
+ from edalize .edatool import get_edatool , walk_tool_packages
415
+
416
+ _tp = list (walk_tool_packages ())
417
+ tools = []
418
+ for tool_name in _tp :
419
+ try :
420
+ tool_class = get_edatool (tool_name )
421
+ if tool_class .get_doc (0 )["description" ]:
422
+ tools += [tool_name ]
423
+ # Ignore any misbehaving backends
424
+ except Exception :
425
+ pass
426
+ return tools
427
+
428
+
429
+ class GenCompleter :
430
+ def __call__ (self , parsed_args , ** kwargs ):
431
+ config = Config (parsed_args .config )
432
+ args_to_config (parsed_args , config )
433
+ fs = Fusesoc (config )
434
+ cores = fs .get_generators ()
435
+ return cores
436
+
437
+
400
438
def get_parser ():
401
439
parser = argparse .ArgumentParser ()
402
440
subparsers = parser .add_subparsers ()
@@ -448,7 +486,9 @@ def get_parser():
448
486
parser_core_show = core_subparsers .add_parser (
449
487
"show" , help = "Show information about a core"
450
488
)
451
- parser_core_show .add_argument ("core" , help = "Name of the core to show" )
489
+ parser_core_show .add_argument (
490
+ "core" , help = "Name of the core to show"
491
+ ).completer = CoreCompleter ()
452
492
parser_core_show .set_defaults (func = core_info )
453
493
454
494
# tool subparser
@@ -470,7 +510,7 @@ def get_parser():
470
510
parser_core_info = subparsers .add_parser (
471
511
"core-info" , help = "Display details about a core"
472
512
)
473
- parser_core_info .add_argument ("core" )
513
+ parser_core_info .add_argument ("core" ). completer = CoreCompleter ()
474
514
parser_core_info .set_defaults (func = core_info )
475
515
476
516
# gen subparser
@@ -490,7 +530,9 @@ def get_parser():
490
530
parser_gen_show = gen_subparsers .add_parser (
491
531
"show" , help = "Show information about a generator"
492
532
)
493
- parser_gen_show .add_argument ("generator" , help = "Name of the generator to show" )
533
+ parser_gen_show .add_argument (
534
+ "generator" , help = "Name of the generator to show"
535
+ ).completer = GenCompleter ()
494
536
parser_gen_show .set_defaults (func = gen_show )
495
537
496
538
# gen clean subparser
@@ -596,7 +638,9 @@ def get_parser():
596
638
parser_run .add_argument ("--build" , action = "store_true" , help = "Execute build stage" )
597
639
parser_run .add_argument ("--run" , action = "store_true" , help = "Execute run stage" )
598
640
parser_run .add_argument ("--target" , help = "Override default target" )
599
- parser_run .add_argument ("--tool" , help = "Override default tool for target" )
641
+ parser_run .add_argument (
642
+ "--tool" , help = "Override default tool for target"
643
+ ).completer = ToolCompleter ()
600
644
parser_run .add_argument (
601
645
"--flag" ,
602
646
help = "Set custom use flags. Can be specified multiple times" ,
@@ -616,7 +660,9 @@ def get_parser():
616
660
action = "store_true" ,
617
661
help = "Allow additional properties in core files" ,
618
662
)
619
- parser_run .add_argument ("system" , help = "Select a system to operate on" )
663
+ parser_run .add_argument (
664
+ "system" , help = "Select a system to operate on"
665
+ ).completer = CoreCompleter ()
620
666
parser_run .add_argument (
621
667
"backendargs" , nargs = argparse .REMAINDER , help = "arguments to be sent to backend"
622
668
)
@@ -639,6 +685,7 @@ def get_parser():
639
685
def parse_args (argv ):
640
686
parser = get_parser ()
641
687
688
+ argcomplete .autocomplete (parser , always_complete_options = False )
642
689
args = parser .parse_args (argv )
643
690
644
691
if hasattr (args , "func" ):
0 commit comments