Skip to content

Display netlab defaults as (exported) environment variables#3413

Open
ipspace wants to merge 1 commit into
devfrom
cli-def-env
Open

Display netlab defaults as (exported) environment variables#3413
ipspace wants to merge 1 commit into
devfrom
cli-def-env

Conversation

@ipspace
Copy link
Copy Markdown
Owner

@ipspace ipspace commented May 19, 2026

This commit adds '--format' parameter to 'netlab defaults' to display selected netlab defaults in YAML format or as shell environment variables.

This commit adds '--format' parameter to 'netlab defaults' to display
selected netlab defaults in YAML format or as shell environment
variables.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the netlab defaults CLI to support alternate output formats intended for automation, allowing selected defaults to be displayed as YAML or as shell environment variable assignments (optionally prefixed with export).

Changes:

  • Added --format {yaml,env,export} option to netlab defaults for alternate “show” output.
  • Implemented formatting logic to emit YAML-like key: value lines or NETLAB_...=... assignments.
  • Updated docs/netlab/defaults.md to document the new option and provide examples.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
netsim/cli/defaults.py Adds --format parsing and output formatting logic for defaults display.
docs/netlab/defaults.md Documents the new --format option and shows example outputs.

Comment thread netsim/cli/defaults.py
if not args.format:
print(f'{k} = {v}')
elif args.format == 'yaml':
print(f'{k}: {shlex.quote(v) if isinstance(v,str) else v}')
Comment thread netsim/cli/defaults.py
key = 'NETLAB_'+k.replace('_','__').replace('.','_').upper()
if args.format == 'export':
key = 'export '+key
print(f'{key}={shlex.quote(v) if isinstance(v,str) else v}')
Comment thread netsim/cli/defaults.py
Comment on lines 260 to +263
if def_expanded:
print_def_list(def_expanded,args.source)
if args.source and args.format:
log.fatal('Cannot use --source option together with --format')
print_def_list(def_expanded,args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants