From f504d2dc15971a043e0d64416be273491a48b1d4 Mon Sep 17 00:00:00 2001 From: Davis Goglin Date: Mon, 28 Mar 2016 11:49:12 -0700 Subject: [PATCH] Allow config path to be passed --- escpos/cli.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/escpos/cli.py b/escpos/cli.py index bf1c1b9..c84a4b8 100755 --- a/escpos/cli.py +++ b/escpos/cli.py @@ -406,18 +406,20 @@ 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 - #cli [subparser] -args + # 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')