def main():
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter,
description='A cmdline tool to enhance PL9K theme for ZSH\n')
subparsers = parser.add_subparsers(help='Use {subcommand} -h for each subcommand\'s optional arguments details',
dest='command')
subparsers.add_parser('init', help='Init the settings in `~/.zshrc` file')
subparsers.add_parser('polling', help='Start the polling daemon process')
display_parser = subparsers.add_parser('display', help='Print the corresponding info on the terminal')
display_parser.add_argument('widget', help='The widget to display, e.g. weather')
args = parser.parse_args()
if args.command == 'polling':
with daemon.DaemonContext(pidfile=daemon.pidfile.PIDLockFile(constants.PID_PATH)):
polling()
elif args.command == 'display':
widgets = sys.modules['thunderbolt100k.widgets']
assert hasattr(widgets, args.widget), 'There is no widget called {0}'.format(args.widget)
assert hasattr(getattr(widgets, args.widget),
'display'), 'The widget {0} must contains a `display` method'.format(args.widget)
result = getattr(widgets, args.widget).display()
if result:
print(result)
elif args.command == 'init':
init_zshrc()
评论列表
文章目录