Allow config path to be passed

This commit is contained in:
Davis Goglin 2016-03-28 11:49:12 -07:00
parent 5a2ca10874
commit f504d2dc15
1 changed files with 17 additions and 6 deletions

View File

@ -406,17 +406,19 @@ def main():
"""
# Load the configuration and defined printer
saved_config = config.Config()
printer = saved_config.printer()
parser = argparse.ArgumentParser(
description='CLI for python-escpos',
epilog='Printer configuration is defined in the python-escpos config'
'file. See documentation for details.',
)
# Everything runs off of a subparser so we can use the format
# Allow config file location to be passed
parser.add_argument(
'-c', '--config',
help='Altnerate path to the configuration file',
)
# Everything interesting runs off of a subparser so we can use the format
# cli [subparser] -args
command_subparsers = parser.add_subparsers(
title='ESCPOS Command',
@ -463,6 +465,15 @@ def main():
sys.exit()
command_arguments = dict([k, v] for k, v in six.iteritems(args_dict) if v)
# If there was a config path passed, grab it
config_path = command_arguments.pop('config', None)
# Load the configuration and defined printer
saved_config = config.Config()
saved_config.load(config_path)
printer = saved_config.printer()
if not printer:
raise Exception('No printers loaded from config')