2016-05-30 13:51:12 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
from __future__ import print_function, unicode_literals
|
|
|
|
|
|
|
|
import argparse
|
2016-06-01 23:11:05 +00:00
|
|
|
import io
|
2016-05-30 13:51:12 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
_DESCRIPTION = """\
|
|
|
|
Migrate arbitrary `.go` sources (mostly) from the v1 to v2 API.
|
|
|
|
"""
|
2016-06-02 08:37:36 +00:00
|
|
|
_MIGRATORS = []
|
2016-05-30 13:51:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main(sysargs=sys.argv[:]):
|
|
|
|
parser = argparse.ArgumentParser(
|
|
|
|
description=_DESCRIPTION,
|
|
|
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
2016-05-30 14:46:00 +00:00
|
|
|
parser.add_argument('path', nargs='*',
|
2016-05-30 13:51:12 +00:00
|
|
|
type=os.path.abspath, default=os.getcwd())
|
|
|
|
parser.add_argument('-w', '--write', help='write changes back to file',
|
|
|
|
action='store_true', default=False)
|
|
|
|
parser.add_argument('-q', '--quiet', help='quiet down the logging',
|
|
|
|
action='store_true', default=False)
|
2016-06-02 08:43:31 +00:00
|
|
|
parser.add_argument('-D', '--debug', help='debug up the logging',
|
|
|
|
action='store_true',
|
|
|
|
default=(os.environ.get('DEBUG') != ''))
|
2016-05-30 13:51:12 +00:00
|
|
|
parser.add_argument('--selftest', help='run internal tests',
|
|
|
|
action='store_true', default=False)
|
|
|
|
|
|
|
|
args = parser.parse_args(sysargs[1:])
|
|
|
|
|
|
|
|
if args.selftest:
|
|
|
|
logging.basicConfig(
|
|
|
|
level=logging.WARN,
|
|
|
|
format='selftest: %(message)s'
|
|
|
|
)
|
|
|
|
test_migrators()
|
|
|
|
return 0
|
|
|
|
|
2016-06-02 08:43:31 +00:00
|
|
|
level = logging.FATAL if args.quiet else logging.INFO
|
|
|
|
level = logging.DEBUG if args.debug else level
|
|
|
|
|
|
|
|
logging.basicConfig(level=level, format='%(message)s')
|
2016-05-30 13:51:12 +00:00
|
|
|
|
2016-05-30 14:46:00 +00:00
|
|
|
paths = args.path
|
|
|
|
if len(paths) == 0:
|
|
|
|
paths = ['.']
|
|
|
|
|
|
|
|
for filepath in _find_candidate_files(paths):
|
2016-05-30 13:51:12 +00:00
|
|
|
updated_source = _update_filepath(filepath)
|
|
|
|
if args.write:
|
|
|
|
logging.info('Updating %s', filepath)
|
|
|
|
|
2016-06-01 23:11:05 +00:00
|
|
|
with io.open(filepath, 'w', encoding='utf-8') as outfile:
|
2016-05-30 13:51:12 +00:00
|
|
|
outfile.write(updated_source)
|
|
|
|
else:
|
|
|
|
logging.info('// Updated %s:', filepath)
|
|
|
|
print(updated_source)
|
|
|
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
2016-05-30 14:21:13 +00:00
|
|
|
def _find_candidate_files(paths):
|
|
|
|
for path in paths:
|
|
|
|
if not os.path.isdir(path):
|
|
|
|
yield path
|
|
|
|
continue
|
2016-05-30 13:51:12 +00:00
|
|
|
|
2016-05-30 14:21:13 +00:00
|
|
|
for curdir, dirs, files in os.walk(path):
|
|
|
|
for i, dirname in enumerate(dirs[:]):
|
|
|
|
if dirname.startswith('.'):
|
|
|
|
dirs.pop(i)
|
2016-05-30 13:51:12 +00:00
|
|
|
|
2016-05-30 14:21:13 +00:00
|
|
|
for filename in files:
|
2016-05-30 14:46:00 +00:00
|
|
|
if not filename.decode('utf-8').endswith('.go'):
|
2016-05-30 14:21:13 +00:00
|
|
|
continue
|
2016-05-30 13:51:12 +00:00
|
|
|
|
2016-05-30 14:21:13 +00:00
|
|
|
filepath = os.path.join(curdir, filename)
|
|
|
|
if not os.access(filepath, os.R_OK | os.W_OK):
|
|
|
|
continue
|
|
|
|
|
|
|
|
yield filepath
|
2016-05-30 13:51:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _update_filepath(filepath):
|
2016-06-01 23:11:05 +00:00
|
|
|
with io.open(filepath, encoding='utf-8') as infile:
|
2016-05-30 13:51:12 +00:00
|
|
|
return _update_source(infile.read())
|
|
|
|
|
|
|
|
|
|
|
|
def _update_source(source):
|
2016-06-02 08:37:36 +00:00
|
|
|
for migrator, func in _MIGRATORS:
|
2016-06-02 08:43:31 +00:00
|
|
|
logging.debug('Running %s migrator', migrator)
|
2016-05-30 13:51:12 +00:00
|
|
|
source = func(source)
|
|
|
|
return source
|
|
|
|
|
|
|
|
|
2016-06-02 08:37:36 +00:00
|
|
|
def _subfmt(pattern, replfmt, source, flags=re.UNICODE):
|
|
|
|
def repl(match):
|
|
|
|
return replfmt.format(**match.groupdict())
|
|
|
|
return re.sub(pattern, repl, source, flags=flags)
|
|
|
|
|
|
|
|
|
2016-05-30 13:51:12 +00:00
|
|
|
def _migrator(func):
|
2016-06-02 08:37:36 +00:00
|
|
|
_MIGRATORS.append((func.__name__.strip('_'), func))
|
2016-05-30 13:51:12 +00:00
|
|
|
return func
|
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
2016-06-01 23:11:05 +00:00
|
|
|
def _slice_pointer_types(source):
|
2016-06-02 08:37:36 +00:00
|
|
|
return _subfmt(
|
2016-06-01 23:11:05 +00:00
|
|
|
'(?P<prefix>\\[\\])cli\\.(?P<type>Command|Author){',
|
2016-06-02 08:37:36 +00:00
|
|
|
'{prefix}*cli.{type}{{', source
|
2016-06-01 00:58:12 +00:00
|
|
|
)
|
2016-05-30 13:51:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
2016-06-01 23:11:05 +00:00
|
|
|
def _pointer_type_literal(source):
|
2016-06-02 08:37:36 +00:00
|
|
|
return _subfmt(
|
2016-06-01 23:11:05 +00:00
|
|
|
'(?P<prefix>\\s+)cli\\.(?P<type>Command|Author){',
|
2016-06-02 08:37:36 +00:00
|
|
|
'{prefix}&cli.{type}{{', source
|
2016-06-01 00:58:12 +00:00
|
|
|
)
|
2016-05-30 13:51:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
2016-06-01 23:11:05 +00:00
|
|
|
def _slice_types(source):
|
2016-06-02 08:37:36 +00:00
|
|
|
return _subfmt(
|
2016-06-01 00:58:12 +00:00
|
|
|
'&cli\\.(?P<type>IntSlice|StringSlice){(?P<args>[^}]*)}',
|
2016-06-02 08:45:13 +00:00
|
|
|
'cli.New{type}({args})', source, flags=re.DOTALL | re.UNICODE
|
2016-06-01 00:58:12 +00:00
|
|
|
)
|
2016-05-30 13:51:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
2016-06-01 23:11:05 +00:00
|
|
|
def _flag_literals(source):
|
2016-06-02 08:37:36 +00:00
|
|
|
return _subfmt(
|
2016-06-01 00:58:12 +00:00
|
|
|
'(?P<prefix>\\s+)cli\\.(?P<type>\\w+)Flag{',
|
2016-06-02 08:37:36 +00:00
|
|
|
'{prefix}&cli.{type}Flag{{', source
|
2016-06-01 00:58:12 +00:00
|
|
|
)
|
2016-05-30 13:51:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
2016-06-01 23:11:05 +00:00
|
|
|
def _v1_imports(source):
|
2016-06-01 00:58:12 +00:00
|
|
|
return re.sub(
|
|
|
|
'"(?:github\\.com|gopkg\\.in)/(?:codegangsta|urfave)/cli(?:\\.v1|)"',
|
2016-06-02 08:37:36 +00:00
|
|
|
'"gopkg.in/urfave/cli.v2"', source, flags=re.UNICODE
|
2016-06-01 00:58:12 +00:00
|
|
|
)
|
2016-05-30 13:51:12 +00:00
|
|
|
|
|
|
|
|
2016-05-30 19:15:49 +00:00
|
|
|
@_migrator
|
2016-06-01 23:11:05 +00:00
|
|
|
def _new_exit_error(source):
|
|
|
|
return re.sub('cli\\.NewExitError', 'cli.Exit', source, flags=re.UNICODE)
|
2016-05-30 19:15:49 +00:00
|
|
|
|
2016-05-30 19:24:16 +00:00
|
|
|
|
2016-05-30 19:15:49 +00:00
|
|
|
@_migrator
|
2016-06-01 23:11:05 +00:00
|
|
|
def _bool_t_flag(source):
|
2016-06-02 08:37:36 +00:00
|
|
|
return _subfmt(
|
2016-06-01 00:58:12 +00:00
|
|
|
'cli\\.BoolTFlag{(?P<args>[^}]*)}',
|
2016-06-02 08:37:36 +00:00
|
|
|
'cli.BoolFlag{{Value: true,{args}}}',
|
2016-06-02 08:45:13 +00:00
|
|
|
source, flags=re.DOTALL | re.UNICODE
|
2016-06-01 00:58:12 +00:00
|
|
|
)
|
2016-05-30 19:15:49 +00:00
|
|
|
|
|
|
|
|
2016-06-02 08:37:36 +00:00
|
|
|
@_migrator
|
|
|
|
def _context_args_len(source):
|
|
|
|
return _subfmt(
|
|
|
|
'len\\((?P<prefix>\\S+)\\.Args\\(\\)\\)',
|
|
|
|
'{prefix}.Args().Len()', source
|
|
|
|
)
|
2016-05-30 19:15:49 +00:00
|
|
|
|
|
|
|
|
2016-05-31 20:39:56 +00:00
|
|
|
@_migrator
|
2016-06-01 23:11:05 +00:00
|
|
|
def _context_args_index(source):
|
2016-06-02 08:37:36 +00:00
|
|
|
return _subfmt(
|
2016-06-01 00:58:12 +00:00
|
|
|
'\\.Args\\(\\)\\[(?P<index>\\d+)\\]',
|
2016-06-02 08:37:36 +00:00
|
|
|
'.Args().Get({index})', source
|
2016-06-01 00:58:12 +00:00
|
|
|
)
|
2016-05-31 20:39:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
2016-06-01 23:11:05 +00:00
|
|
|
def _envvar_string(source):
|
2016-06-01 00:59:09 +00:00
|
|
|
return re.sub(
|
|
|
|
'EnvVar:(?P<ws>\\s+)"(?P<string>[^"]+)"',
|
2016-06-01 23:11:05 +00:00
|
|
|
_envvar_string_repl, source, flags=re.UNICODE
|
2016-06-01 00:59:09 +00:00
|
|
|
)
|
2016-05-31 20:39:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _envvar_string_repl(match):
|
2016-06-01 00:58:12 +00:00
|
|
|
return 'EnvVars:{ws}[]string{{{value}}}'.format(
|
|
|
|
value=', '.join([
|
2016-05-31 20:39:56 +00:00
|
|
|
'"{}"'.format(s) for s in
|
2016-06-01 23:11:05 +00:00
|
|
|
re.split(
|
|
|
|
'\\s*,\\s*', match.groupdict()['string'],
|
|
|
|
flags=re.UNICODE
|
|
|
|
)
|
2016-06-01 00:58:12 +00:00
|
|
|
]),
|
|
|
|
**match.groupdict()
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
2016-06-01 23:11:05 +00:00
|
|
|
def _flag_name_stringly(source):
|
2016-06-01 00:58:12 +00:00
|
|
|
return re.sub(
|
|
|
|
'(?P<prefix>\\s+)Name:(?P<ws>\\s+)"(?P<string>[^"]+)"',
|
2016-06-01 23:11:05 +00:00
|
|
|
_flag_name_stringly_repl, source, flags=re.UNICODE
|
2016-06-01 00:58:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def _flag_name_stringly_repl(match):
|
|
|
|
revars = dict(match.groupdict())
|
|
|
|
|
|
|
|
string = revars['string']
|
|
|
|
parts = list(
|
|
|
|
reversed(
|
|
|
|
sorted(
|
|
|
|
filter(lambda s: len(s.strip()) > 0, [
|
|
|
|
part.strip() for part in string.split(',')
|
|
|
|
]), key=len
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
if len(parts) == 1:
|
|
|
|
return '{prefix}Name:{ws}"{string}"'.format(**revars)
|
|
|
|
|
|
|
|
return (
|
|
|
|
'{prefix}Name:{ws}"{name}", Aliases: []string{{{aliases}}}'
|
|
|
|
).format(
|
|
|
|
name=parts[0],
|
|
|
|
aliases=', '.join(['"{}"'.format(s) for s in parts[1:]]),
|
|
|
|
**revars
|
2016-05-31 20:39:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2016-06-01 23:11:05 +00:00
|
|
|
@_migrator
|
|
|
|
def _commands_opaque_type(source):
|
|
|
|
return re.sub('cli\\.Commands', '[]*cli.Command', source, flags=re.UNICODE)
|
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
|
|
|
def _flag_names(source):
|
|
|
|
return re.sub('\\.GetName\\(\\)', '.Names()[0]', source, flags=re.UNICODE)
|
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
|
|
|
def _app_categories(source):
|
2016-06-02 08:37:36 +00:00
|
|
|
source = _subfmt(
|
|
|
|
'(?P<prefix>range\\s+\\S+)\\.App\\.Categories\\(\\)',
|
|
|
|
'{prefix}.App.Categories.Categories()', source
|
2016-06-01 23:11:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
return re.sub(
|
2016-06-02 08:37:36 +00:00
|
|
|
'\\.App\\.Categories\\(\\)', '.App.Categories',
|
|
|
|
source, flags=re.UNICODE
|
2016-06-01 23:11:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
|
|
|
def _command_category_commands(source):
|
|
|
|
# XXX: brittle
|
2016-06-02 08:37:36 +00:00
|
|
|
return _subfmt(
|
2016-06-01 23:11:05 +00:00
|
|
|
'(?P<prefix>\\s+category\\.)Commands(?P<suffix>[^(])',
|
2016-06-02 08:37:36 +00:00
|
|
|
'{prefix}VisibleCommands(){suffix}', source
|
2016-06-01 23:11:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
|
|
|
def _context_bool_t(source):
|
|
|
|
# XXX: probably brittle
|
2016-06-02 08:37:36 +00:00
|
|
|
return _subfmt(
|
2016-06-01 23:11:05 +00:00
|
|
|
'(?P<prefix>\\S+)(?:Global|)BoolT\\(',
|
2016-06-02 08:37:36 +00:00
|
|
|
'!{prefix}Bool(', source
|
2016-06-01 23:11:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
|
|
|
def _context_global_methods(source):
|
2016-06-02 08:37:36 +00:00
|
|
|
return _subfmt(
|
2016-06-02 08:45:13 +00:00
|
|
|
'\\.Global(?P<method>'
|
|
|
|
'Bool|Duration|Float64|Generic|Int|IntSlice|String|StringSlice|'
|
|
|
|
'FlagNames|IsSet|Set'
|
2016-06-01 23:11:05 +00:00
|
|
|
')\\(',
|
2016-06-02 08:37:36 +00:00
|
|
|
'.{method}(', source
|
2016-06-01 23:11:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@_migrator
|
|
|
|
def _context_parent(source):
|
|
|
|
# XXX: brittle
|
|
|
|
return re.sub('\\.Parent\\(\\)', '.Lineage()[1]', source, flags=re.UNICODE)
|
|
|
|
|
|
|
|
|
2016-06-22 16:47:57 +00:00
|
|
|
@_migrator
|
|
|
|
def _app_init(source):
|
2016-06-22 20:57:18 +00:00
|
|
|
return re.sub(
|
|
|
|
'cli\\.NewApp\\(\\)', '(&cli.App{})', source, flags=re.UNICODE
|
|
|
|
)
|
2016-06-22 16:47:57 +00:00
|
|
|
|
2017-02-15 05:18:00 +00:00
|
|
|
|
2016-07-26 10:51:26 +00:00
|
|
|
@_migrator
|
|
|
|
def _bash_complete(source):
|
|
|
|
return re.sub(
|
|
|
|
'BashComplete:', 'ShellComplete:',
|
|
|
|
re.sub('\\.BashComplete', '.ShellComplete', source, flags=re.UNICODE))
|
|
|
|
|
2017-02-15 05:18:00 +00:00
|
|
|
|
2016-07-26 10:51:26 +00:00
|
|
|
@_migrator
|
|
|
|
def _enable_bash_completion(source):
|
|
|
|
return re.sub(
|
|
|
|
'\\.EnableBashCompletion', '.EnableShellCompletion', source, flags=re.UNICODE
|
|
|
|
)
|
|
|
|
|
2017-02-15 05:18:00 +00:00
|
|
|
|
2016-07-26 10:51:26 +00:00
|
|
|
@_migrator
|
|
|
|
def _bash_completion_flag(source):
|
|
|
|
return re.sub(
|
|
|
|
'cli\\.BashCompletionFlag', 'cli.GenerateCompletionFlag', source, flags=re.UNICODE
|
|
|
|
)
|
2016-06-22 16:47:57 +00:00
|
|
|
|
2017-02-15 05:18:00 +00:00
|
|
|
|
2016-05-30 13:51:12 +00:00
|
|
|
def test_migrators():
|
|
|
|
import difflib
|
|
|
|
|
|
|
|
for i, (source, expected) in enumerate(_MIGRATOR_TESTS):
|
|
|
|
actual = _update_source(source)
|
|
|
|
if expected != actual:
|
|
|
|
udiff = difflib.unified_diff(
|
|
|
|
expected.splitlines(), actual.splitlines(),
|
|
|
|
fromfile='a/source.go', tofile='b/source.go', lineterm=''
|
|
|
|
)
|
|
|
|
for line in udiff:
|
|
|
|
print(line)
|
|
|
|
raise AssertionError('migrated source does not match expected')
|
|
|
|
logging.warn('Test case %d/%d OK', i+1, len(_MIGRATOR_TESTS))
|
|
|
|
|
|
|
|
|
|
|
|
_MIGRATOR_TESTS = (
|
|
|
|
("""
|
|
|
|
\t\t\t&cli.StringSlice{"a", "b", "c"},
|
|
|
|
""", """
|
|
|
|
\t\t\tcli.NewStringSlice("a", "b", "c"),
|
|
|
|
"""),
|
|
|
|
("""
|
|
|
|
\t\tcli.IntFlag{
|
|
|
|
\t\t\tName: "yep",
|
|
|
|
\t\t\tValue: 3,
|
|
|
|
\t\t}
|
|
|
|
""", """
|
|
|
|
\t\t&cli.IntFlag{
|
|
|
|
\t\t\tName: "yep",
|
|
|
|
\t\t\tValue: 3,
|
|
|
|
\t\t}
|
|
|
|
"""),
|
|
|
|
("""
|
|
|
|
\t\tapp.Commands = []cli.Command{
|
|
|
|
\t\t\t{
|
|
|
|
\t\t\t\tName: "whatebbs",
|
|
|
|
\t\t\t},
|
|
|
|
\t\t}
|
|
|
|
""", """
|
|
|
|
\t\tapp.Commands = []*cli.Command{
|
|
|
|
\t\t\t{
|
|
|
|
\t\t\t\tName: "whatebbs",
|
|
|
|
\t\t\t},
|
|
|
|
\t\t}
|
|
|
|
"""),
|
|
|
|
("""
|
|
|
|
\t\tapp.Commands = []cli.Command{
|
|
|
|
\t\t\tcli.Command{
|
|
|
|
\t\t\t\tName: "whatebbs",
|
|
|
|
\t\t\t},
|
|
|
|
\t\t}
|
|
|
|
""", """
|
|
|
|
\t\tapp.Commands = []*cli.Command{
|
|
|
|
\t\t\t&cli.Command{
|
|
|
|
\t\t\t\tName: "whatebbs",
|
|
|
|
\t\t\t},
|
|
|
|
\t\t}
|
|
|
|
"""),
|
|
|
|
("""
|
|
|
|
\t"github.com/codegangsta/cli"
|
|
|
|
\t"github.com/urfave/cli"
|
|
|
|
\t"gopkg.in/codegangsta/cli"
|
|
|
|
\t"gopkg.in/codegangsta/cli.v1"
|
|
|
|
\t"gopkg.in/urfave/cli"
|
|
|
|
\t"gopkg.in/urfave/cli.v1"
|
|
|
|
""", """
|
|
|
|
\t"gopkg.in/urfave/cli.v2"
|
|
|
|
\t"gopkg.in/urfave/cli.v2"
|
|
|
|
\t"gopkg.in/urfave/cli.v2"
|
|
|
|
\t"gopkg.in/urfave/cli.v2"
|
|
|
|
\t"gopkg.in/urfave/cli.v2"
|
|
|
|
\t"gopkg.in/urfave/cli.v2"
|
2016-05-30 19:15:49 +00:00
|
|
|
"""),
|
|
|
|
("""
|
|
|
|
\t\t\t\treturn cli.NewExitError("foo whatebber", 9)
|
|
|
|
""", """
|
|
|
|
\t\t\t\treturn cli.Exit("foo whatebber", 9)
|
|
|
|
"""),
|
|
|
|
("""
|
|
|
|
\t\t\tapp.Flags = []cli.Flag{
|
|
|
|
\t\t\t\tcli.StringFlag{
|
|
|
|
\t\t\t\t\tName: "aha",
|
|
|
|
\t\t\t\t},
|
|
|
|
\t\t\t\tcli.BoolTFlag{
|
|
|
|
\t\t\t\t\tName: "blurp",
|
|
|
|
\t\t\t\t},
|
|
|
|
\t\t\t}
|
|
|
|
""", """
|
|
|
|
\t\t\tapp.Flags = []cli.Flag{
|
|
|
|
\t\t\t\t&cli.StringFlag{
|
|
|
|
\t\t\t\t\tName: "aha",
|
|
|
|
\t\t\t\t},
|
2016-05-30 19:24:16 +00:00
|
|
|
\t\t\t\t&cli.BoolFlag{Value: true,
|
2016-05-30 19:15:49 +00:00
|
|
|
\t\t\t\t\tName: "blurp",
|
|
|
|
\t\t\t\t},
|
|
|
|
\t\t\t}
|
2016-05-31 20:39:56 +00:00
|
|
|
"""),
|
|
|
|
("""
|
|
|
|
\t\t\tAction = func(c *cli.Context) error {
|
|
|
|
\t\t\t\tif c.Args()[4] == "meep" {
|
|
|
|
\t\t\t\t\treturn nil
|
|
|
|
\t\t\t\t}
|
|
|
|
\t\t\t\treturn errors.New("mope")
|
|
|
|
\t\t\t}
|
|
|
|
""", """
|
|
|
|
\t\t\tAction = func(c *cli.Context) error {
|
|
|
|
\t\t\t\tif c.Args().Get(4) == "meep" {
|
|
|
|
\t\t\t\t\treturn nil
|
|
|
|
\t\t\t\t}
|
|
|
|
\t\t\t\treturn errors.New("mope")
|
|
|
|
\t\t\t}
|
|
|
|
"""),
|
|
|
|
("""
|
|
|
|
\t\tapp.Flags = []cli.Flag{
|
|
|
|
\t\t\tcli.StringFlag{
|
|
|
|
\t\t\t\tName: "toots",
|
|
|
|
\t\t\t\tEnvVar: "TOOTS,TOOTERS",
|
|
|
|
\t\t\t},
|
|
|
|
\t\t}
|
|
|
|
""", """
|
|
|
|
\t\tapp.Flags = []cli.Flag{
|
|
|
|
\t\t\t&cli.StringFlag{
|
|
|
|
\t\t\t\tName: "toots",
|
|
|
|
\t\t\t\tEnvVars: []string{"TOOTS", "TOOTERS"},
|
|
|
|
\t\t\t},
|
|
|
|
\t\t}
|
2016-06-01 00:58:12 +00:00
|
|
|
"""),
|
|
|
|
("""
|
|
|
|
\t\tapp.Flags = []cli.Flag{
|
|
|
|
\t\t\tcli.StringFlag{
|
|
|
|
\t\t\t\tName: "t, tootles, toots",
|
|
|
|
\t\t\t},
|
|
|
|
\t\t}
|
|
|
|
""", """
|
|
|
|
\t\tapp.Flags = []cli.Flag{
|
|
|
|
\t\t\t&cli.StringFlag{
|
|
|
|
\t\t\t\tName: "tootles", Aliases: []string{"toots", "t"},
|
|
|
|
\t\t\t},
|
|
|
|
\t\t}
|
2016-06-22 16:47:57 +00:00
|
|
|
"""),
|
|
|
|
("""
|
|
|
|
\t\tapp := cli.NewApp()
|
|
|
|
\t\tapp.HideHelp = true
|
|
|
|
""", """
|
|
|
|
\t\tapp := (&cli.App{})
|
|
|
|
\t\tapp.HideHelp = true
|
2016-05-30 13:53:47 +00:00
|
|
|
""")
|
2016-05-30 13:51:12 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.exit(main())
|