def run(): arguments = docopt(__doc__, version=VERSION) f = Clf(format="json", order=arguments['--order'], proxy=arguments['--proxy']) if arguments['--browse']: commands = f.browse() elif arguments['<command>']: commands = f.command(arguments['<command>']) elif arguments['<keyword>']: commands = f.search(arguments['<keyword>']) for command in commands: if (arguments['--color']) or (os.getenv('CLF_COLOR')): output = '{}# {}{}\n'.format(BLUE, command.summary, END) output += highlight(command.command, BashLexer(), TerminalFormatter(bg="dark")) else: output = '# {}\n'.format(command.summary) output += command.command + "\n" print(output)
def run(): arguments = docopt(__doc__, version=VERSION) f = Clf(format="json", order=arguments['--order'], proxy=arguments['--proxy']) if arguments['--browse']: commands = f.browse() elif arguments['<command>']: commands = f.command(arguments['<command>']) elif arguments['<keyword>']: commands = f.search(arguments['<keyword>']) if (arguments['--color']) or (os.getenv('CLF_COLOR')): def get_output(command): detail = highlight(command.command, BashLexer(), TerminalFormatter(bg="dark")) return '{}# {}{}\n{}'.format(BLUE, command.summary, END, detail) else: def get_output(command): return '# {}\n{}\n'.format(command.summary, command.command) for command in commands: print(get_output(command))
def run(): arguments = docopt(__doc__, version=VERSION) f = Clf(format="json", order=arguments['--order'], proxy=arguments['--proxy']) # Save the snippet locally if arguments['-s']: try: snippet = save_snippet(arguments['-s'], f._get_proxies()) except(RequestsException, OSException, DuplicateException) as e: print(e) else: print("The snippet has been successfully saved.") exit() # Retrieve the snippets list if arguments['--local']: commands = get_local_snippets() elif arguments['<command>']: commands = f.command(arguments['<command>']) elif arguments['<keyword>']: commands = f.search(arguments['<keyword>']) else: commands = f.browse() # Show the snippets id if arguments['--id']: sid = lambda c: '({})'.format(c.id) else: sid = lambda c: '' # Display in colors if (arguments['--color']) or (os.getenv('CLF_COLOR')): def get_output(command): detail = highlight(command.command, BashLexer(), TerminalFormatter(bg="dark")) return '{}#{} {}{}\n{}'.format(BLUE, sid(command), command.summary, END, detail) else: def get_output(command): return '#{} {}\n{}\n'.format(sid(command), command.summary, command.command) # Limit the number of snippets try: limit = int(arguments['-n']) except ValueError: limit = 25 # Display the snippets for idx, command in enumerate(commands): if limit == idx: break print(get_output(command))