Skip to content
Snippets Groups Projects
Commit 5f2f20f3 authored by Lars Beckers's avatar Lars Beckers
Browse files

generate: fix presets from different cfg file

parent 6f5a8e61
No related branches found
No related tags found
No related merge requests found
......@@ -16,9 +16,17 @@ except Exception:
pass
if not 'presets' in config:
config['presets'] = {}
choices = []
choice_default = None
else:
choices = list(config['presets'])
choice_default = list(config['presets'].keys())[0]
parser = argparse.ArgumentParser(description='Generates a SSH config file from some DNS zone(s).')
parser.add_argument('--preset', choices=list(config['presets']), default=list(config['presets'].keys())[0], help='select a configuration preset')
if choices:
parser.add_argument('--preset', choices=choices, default=choice_default, help='select a configuration preset')
else:
parser.add_argument('--preset', action='store', default=choice_default, help='select a configuration preset')
parser.add_argument('--cfg', action='store', default='./sshgen.cfg', help='config file')
args = parser.parse_args()
preset = args.preset
......@@ -26,6 +34,8 @@ preset = args.preset
if args.cfg != './sshgen.cfg':
with open(args.cfg) as fp:
config.read_file(fp)
if preset not in list(config['presets']):
sys.exit('preset not in presets configuration')
def get_zones():
all_zones = []
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment