def __qmark__(self): """ user-friendly information when the input is "<bash_fxn>?" """ name, source = map(str, [self.name, self.source]) table = [ ['type:','bash function'], ['source:', str(source)], ['source name:', name], ['smash name:', name], ] table = tabulate(table) #string from list table = table.split('\n')[1:-1] # back to list (removing header/footer) table = [ console.blue(' | ') + x for x in table ] out = out = [ console.red('Smash-Bash bridge:') ] + table return '\n'.join(out)
def __qmark__(self): """ user-friendly information when the input is "plugins?" """ alias_map = get_smash().project_manager.alias_map out = [console.red('Smash Aliases:') + ' ({0} total, {1} groups)'.format( len(self._aliases), len(alias_map))] for group_name in alias_map.keys(): g_aliases = alias_map[group_name] max_summary = 3 summary = [x[0] for x in g_aliases[:max_summary]] if len(g_aliases) > max_summary: summary += ['..'] summary = ', '.join(summary) out += [' : "{0}" with {1} aliases: {2})'.format( group_name, len(g_aliases), summary)] return '\n'.join(out)
def parse_argv(): # flake8: noqa """ """ parser = get_parser() args, unknown = parser.parse_known_args(sys.argv[1:]) if args.subcommand in ['version', 'help']: if args.subcommand == 'version': print version.__version__ if args.subcommand == 'help': parser.print_help() raise SystemExit() elif args.subcommand == 'list': do_list() elif args.subcommand == 'status': do_status(args.tunnel_name) elif args.subcommand == 'edit': ed = os.environ.get('EDITOR', 'vi') report('opening configuration in {0}'.format(ed)) os.system(ed + ' ' + TUNL_CONFIG) elif args.subcommand == 'start': do_start(args.tunnel_name) elif args.subcommand == 'stop': do_stop(args.tunnel_name) elif args.subcommand == 'add': data = args.tunnel_json err = console.red('Bad data passed into "tunl add" command. ') err += ( 'Example usage follows:\n ' 'tunl add tunl_name --data "' "{remote_host:'monkey.org', local_port:5151, remote_port:22}" '"') if not data: raise SystemExit(err) try: data = demjson.decode(data) except demjson.JSONDecodeError as e: err = "demjson.JSONDecodeError: " + str(e) print err raise SystemExit(err) else: try: do_add(args.tunnel_name, data) except voluptuous.Invalid, e: print "voluptuous.Invalid: " + str(e) raise SystemExit(err)
def summarize(parameter_s=''): _dir = parameter_s or os.getcwd() assert ope(_dir) tmp = guess_dir_type(_dir) print console.red('match types:') console.draw_line() print ' {0}'.format(tmp) print console.red('virttualenvs:') console.draw_line() print ' {0}'.format(find_venvs(_dir)) print console.red('sloccount:') for report_section in sloccount(_dir): console.draw_line() print report_section.strip() console.draw_line()
def show_usage(self): """ handler used when naked '?' is entered into the terminal """ return page.page( console.red("main documentation:") + \ "\n http://mattvonrocketstein.github.io/smash/")
def __qmark__(self): """ user-friendly information when the input is "plugins?" """ out = [console.red("Smash Plugins: ") + "({0} total)".format(len(self._plugins))] for nick in sorted(self._plugins): out += [console.blue(" | ") + "{0}".format(nick)] return "\n".join(out)