File size: 683 Bytes
27dc10f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# """Command line argument parser for configuration files.
# Converts YAML config file key-value pairs into command line arguments.
# """
import sys
import yaml

# Load the YAML configuration file
config_file = sys.argv[1]
with open(config_file) as f:
    config = yaml.safe_load(f)

args = []
for key, value in config.items():
    if isinstance(value, bool):
        # Include boolean flags only if they are True
        if value:
            args.append(f"--{key}")
    elif value is not None:
        # Include other key-value pairs
        args.append(f"--{key}")
        args.append(str(value))

# Print the generated arguments as a space-separated string
print(" ".join(args))