summaryrefslogtreecommitdiff
path: root/dotbot/cli.py
diff options
context:
space:
mode:
authorAnish Athalye <aathalye@me.com>2014-03-19 23:07:30 -0400
committerAnish Athalye <aathalye@me.com>2014-03-20 18:57:56 -0400
commit60a560e97699a1d9a4320b8e787a50b1a9a7734d (patch)
tree573ce63c2a49a278af49c0cc6542bfe3b89cf572 /dotbot/cli.py
Initial commit
Diffstat (limited to 'dotbot/cli.py')
-rw-r--r--dotbot/cli.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/dotbot/cli.py b/dotbot/cli.py
new file mode 100644
index 0000000..b9cc528
--- /dev/null
+++ b/dotbot/cli.py
@@ -0,0 +1,46 @@
+from argparse import ArgumentParser
+from .config import ConfigReader, ReadingError
+from .dispatcher import Dispatcher, DispatchError
+from .messenger import Messenger
+from .messenger import Level
+
+def add_options(parser):
+ parser.add_argument('-Q', '--super-quiet', dest = 'super_quiet', action = 'store_true',
+ help = 'suppress almost all output')
+ parser.add_argument('-q', '--quiet', dest = 'quiet', action = 'store_true',
+ help = 'suppress most output')
+ parser.add_argument('-v', '--verbose', dest = 'verbose', action = 'store_true',
+ help = 'enable verbose output')
+ parser.add_argument('-d', '--base-directory', nargs = 1,
+ dest = 'base_directory', help = 'execute commands from within BASEDIR',
+ metavar = 'BASEDIR', required = True)
+ parser.add_argument('-c', '--config-file', nargs = 1, dest = 'config_file',
+ help = 'run commands given in CONFIGFILE', metavar = 'CONFIGFILE',
+ required = True)
+
+def read_config(config_file):
+ reader = ConfigReader(config_file)
+ return reader.get_config()
+
+def main():
+ log = Messenger()
+ try:
+ parser = ArgumentParser()
+ add_options(parser)
+ options = parser.parse_args()
+ if (options.super_quiet):
+ log.set_level(Level.WARNING)
+ if (options.quiet):
+ log.set_level(Level.INFO)
+ if (options.verbose):
+ log.set_level(Level.DEBUG)
+ tasks = read_config(options.config_file[0])
+ dispatcher = Dispatcher(options.base_directory[0])
+ success = dispatcher.dispatch(tasks)
+ if success:
+ log.info('\n==> All tasks executed successfully')
+ else:
+ raise DispatchError('\n==> Some tasks were not executed successfully')
+ except (ReadingError, DispatchError) as e:
+ log.error('%s' % e)
+ exit(1)