import argparse, os, sys
from .. import log
from .. project.importer import import_symbol
from .. project.preset_library import PresetLibrary

__all__ = ['main']

COMMANDS = ('all_pixel', 'devices', 'demo', 'run', 'set', 'show')
MODULES = {c: import_symbol('.' + c, 'bibliopixel.main') for c in COMMANDS}
PRESET_LIBRARY_DEFAULT = '~/.bibliopixel'
LOG_LEVELS = ('debug', 'info', 'warning', 'error', 'critical')


def no_command(*_):
    print('ERROR: No command entered')
    print('Valid:', *COMMANDS)
    return -1


def main():
    parser = argparse.ArgumentParser()
    subparsers = parser.add_subparsers()
    for name, module in sorted(MODULES.items()):
        subparser = subparsers.add_parser(name, help=module.HELP)
        module.set_parser(subparser)
    parser.add_argument('--loglevel', choices=LOG_LEVELS, default='info')
    parser.add_argument('--settings',
                        help='Filename for settings',
                        default=PRESET_LIBRARY_DEFAULT)

    args = ['--help' if i == 'help' else i for i in sys.argv[1:]]
    args = parser.parse_args(args)

    log.set_log_level(args.loglevel)
    settings = PresetLibrary(os.path.expanduser(args.settings), True)

    run = getattr(args, 'run', no_command)
    sys.exit(run(args, settings) or 0)

@@ -205,17 +205,20 @@
 ', 'run'
-,
+)  #
  'set', 
@@ -406,16 +406,39 @@
 tical')%0A
+ENABLE_PRESETS = False%0A
 %0A%0Adef no
@@ -855,16 +855,43 @@
 'info')%0A
+    if ENABLE_PRESETS:%0A    
     pars
@@ -909,23 +909,22 @@
 ment('--
+pre
 set
-ting
 s',%0A    
@@ -943,16 +943,20 @@
         
+   
+ 
 help='Fi
@@ -970,19 +970,22 @@
 for 
-settings',%0A
+presets',%0A    
     
@@ -1184,18 +1184,36 @@
     
-settings =
+presets = ENABLE_PRESETS and
  Pre
@@ -1223,16 +1223,25 @@
 Library(
+%0A        
 os.path.
@@ -1256,23 +1256,22 @@
 er(args.
+pre
 set
-ting
 s), True
@@ -1343,15 +1343,14 @@
 gs, 
+pre
 set
-ting
 s) o

Disable and run and help commands; don't read settings.