def get_search_command(as_parser=False): """A command which provides various subcommands mimicking popular command-line text search tools to test power, compatiblity, and flexibility. """ cmd = Command(None, 'search') cmd.add('--verbose', char='-V', parse_as=True) rg_subcmd = Command(_rg, 'rg') rg_subcmd.add('--glob', char='-g', multi=True, parse_as=str, doc='Include or exclude files/directories for searching' ' that match the given glob. Precede with ! to exclude.') rg_subcmd.add('--max-count', char='-m', parse_as=int, doc='Limit the number of matching lines per file.') rg_subcmd.add('--filetype', ChoicesParam(['py', 'js', 'html'])) rg_subcmd.add('--extensions', ListParam(strip=True)) cmd.add(rg_subcmd) cmd.add(_timestamp_mw) if as_parser: cmd.__class__ = Parser return cmd
def get_vcs_cmd(as_parser=False): cmd = Command(None, 'vcs') cmd.add(_add_cmd, name='add', posargs={'min_count': 1}, post_posargs=True) cmd.add(_checkout_cmd, name='checkout', posargs={'max_count': 1}) if as_parser: cmd.__class__ = Parser return cmd
def get_calc_cmd(as_parser=False): cmd = Command(None, 'calc') cmd.add(_add_cmd, name='add', posargs={'min_count': 2, 'parse_as': float}) cmd.add(_add_two_ints, name='add_two_ints', posargs={'count': 2, 'parse_as': int, 'provides': 'ints'}) cmd.add(_is_odd, name='is_odd', posargs={'count': 1, 'parse_as': int, 'provides': 'target_int'}) cmd.add(_ask_halve, name='halve', posargs=False) cmd.add(_ask_blackjack, name='blackjack') if as_parser: cmd.__class__ = Parser return cmd