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 :
@@ -393,6 +396,41 @@ def update(fs, args):
393
396
fs .update_libraries (args .libraries )
394
397
395
398
399
+ class CoreCompleter :
400
+ def __call__ (self , parsed_args , ** kwargs ):
401
+ config = Config (parsed_args .config )
402
+ args_to_config (parsed_args , config )
403
+ fs = Fusesoc (config )
404
+ cores = fs .get_cores ()
405
+ return cores
406
+
407
+
408
+ class ToolCompleter :
409
+ def __call__ (self , parsed_args , ** kwargs ):
410
+ from edalize .edatool import get_edatool , walk_tool_packages
411
+
412
+ _tp = list (walk_tool_packages ())
413
+ tools = []
414
+ for tool_name in _tp :
415
+ try :
416
+ tool_class = get_edatool (tool_name )
417
+ if tool_class .get_doc (0 )["description" ]:
418
+ tools += [tool_name ]
419
+ # Ignore any misbehaving backends
420
+ except Exception :
421
+ pass
422
+ return tools
423
+
424
+
425
+ class GenCompleter :
426
+ def __call__ (self , parsed_args , ** kwargs ):
427
+ config = Config (parsed_args .config )
428
+ args_to_config (parsed_args , config )
429
+ fs = Fusesoc (config )
430
+ cores = fs .get_generators ()
431
+ return cores
432
+
433
+
396
434
def get_parser ():
397
435
parser = argparse .ArgumentParser ()
398
436
subparsers = parser .add_subparsers ()
@@ -444,7 +482,9 @@ def get_parser():
444
482
parser_core_show = core_subparsers .add_parser (
445
483
"show" , help = "Show information about a core"
446
484
)
447
- parser_core_show .add_argument ("core" , help = "Name of the core to show" )
485
+ parser_core_show .add_argument (
486
+ "core" , help = "Name of the core to show"
487
+ ).completer = CoreCompleter ()
448
488
parser_core_show .set_defaults (func = core_info )
449
489
450
490
# tool subparser
@@ -466,7 +506,7 @@ def get_parser():
466
506
parser_core_info = subparsers .add_parser (
467
507
"core-info" , help = "Display details about a core"
468
508
)
469
- parser_core_info .add_argument ("core" )
509
+ parser_core_info .add_argument ("core" ). completer = CoreCompleter ()
470
510
parser_core_info .set_defaults (func = core_info )
471
511
472
512
# gen subparser
@@ -486,7 +526,9 @@ def get_parser():
486
526
parser_gen_show = gen_subparsers .add_parser (
487
527
"show" , help = "Show information about a generator"
488
528
)
489
- parser_gen_show .add_argument ("generator" , help = "Name of the generator to show" )
529
+ parser_gen_show .add_argument (
530
+ "generator" , help = "Name of the generator to show"
531
+ ).completer = GenCompleter ()
490
532
parser_gen_show .set_defaults (func = gen_show )
491
533
492
534
# gen clean subparser
@@ -581,7 +623,9 @@ def get_parser():
581
623
parser_run .add_argument ("--build" , action = "store_true" , help = "Execute build stage" )
582
624
parser_run .add_argument ("--run" , action = "store_true" , help = "Execute run stage" )
583
625
parser_run .add_argument ("--target" , help = "Override default target" )
584
- parser_run .add_argument ("--tool" , help = "Override default tool for target" )
626
+ parser_run .add_argument (
627
+ "--tool" , help = "Override default tool for target"
628
+ ).completer = ToolCompleter ()
585
629
parser_run .add_argument (
586
630
"--flag" ,
587
631
help = "Set custom use flags. Can be specified multiple times" ,
@@ -601,7 +645,9 @@ def get_parser():
601
645
action = "store_true" ,
602
646
help = "Allow additional properties in core files" ,
603
647
)
604
- parser_run .add_argument ("system" , help = "Select a system to operate on" )
648
+ parser_run .add_argument (
649
+ "system" , help = "Select a system to operate on"
650
+ ).completer = CoreCompleter ()
605
651
parser_run .add_argument (
606
652
"backendargs" , nargs = argparse .REMAINDER , help = "arguments to be sent to backend"
607
653
)
@@ -624,6 +670,7 @@ def get_parser():
624
670
def parse_args (argv ):
625
671
parser = get_parser ()
626
672
673
+ argcomplete .autocomplete (parser , always_complete_options = False )
627
674
args = parser .parse_args (argv )
628
675
629
676
if hasattr (args , "func" ):
0 commit comments