Skip to content

Commit 797ac46

Browse files
erikwaolofk
authored andcommitted
Add command line argument for reading/writing config
1 parent 0893a87 commit 797ac46

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

fusesoc/main.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,25 @@ def run(cm, args):
306306
)
307307

308308

309+
def config(cm, args):
310+
311+
conf = Config(path=args.config if args.config else None)
312+
313+
if not hasattr(conf, args.key):
314+
logger.error(f"Invalid config parameter: {args.key}")
315+
exit(1)
316+
317+
if not args.value:
318+
# Read
319+
if hasattr(conf, args.key):
320+
print(getattr(conf, args.key))
321+
else:
322+
# Write
323+
if hasattr(conf, args.key):
324+
setattr(conf, args.key, args.value)
325+
conf.write()
326+
327+
309328
# Clean out old work root
310329
def prepare_work_root(work_root):
311330
if os.path.exists(work_root):
@@ -720,6 +739,17 @@ def get_parser():
720739
)
721740
parser_run.set_defaults(func=run)
722741

742+
# config subparser
743+
parser_config = subparsers.add_parser(
744+
"config",
745+
help="Read/write config default section [" + Config.default_section + "]",
746+
)
747+
parser_config.set_defaults(func=config)
748+
parser_config.add_argument("key", help="Config parameter")
749+
parser_config.add_argument(
750+
"value", nargs=argparse.OPTIONAL, help="Config parameter"
751+
)
752+
723753
return parser
724754

725755

0 commit comments

Comments
 (0)