Fill in migrations for cli.Exit and BoolFlag with Value
This commit is contained in:
parent
1d13fa8140
commit
659e1c1e0b
46
cli-v1-to-v2
46
cli-v1-to-v2
@ -20,7 +20,7 @@ _SLICE_TYPE_RE = re.compile(
|
|||||||
flags=re.DOTALL
|
flags=re.DOTALL
|
||||||
)
|
)
|
||||||
_FLAG_LITERAL_RE = re.compile(
|
_FLAG_LITERAL_RE = re.compile(
|
||||||
'(?P<prefix>[^&]?)cli\\.(?P<type>\\w+)Flag{',
|
'(?P<prefix>\\s+)cli\\.(?P<type>\\w+)Flag{',
|
||||||
)
|
)
|
||||||
_COMMAND_SLICE_RE = re.compile(
|
_COMMAND_SLICE_RE = re.compile(
|
||||||
'(?P<prefix>\\[\\])cli\\.Command{',
|
'(?P<prefix>\\[\\])cli\\.Command{',
|
||||||
@ -28,6 +28,11 @@ _COMMAND_SLICE_RE = re.compile(
|
|||||||
_COMMAND_LITERAL_RE = re.compile(
|
_COMMAND_LITERAL_RE = re.compile(
|
||||||
'(?P<prefix>\\s+)cli\\.Command{',
|
'(?P<prefix>\\s+)cli\\.Command{',
|
||||||
)
|
)
|
||||||
|
_EXIT_ERROR_RE = re.compile('cli\\.NewExitError')
|
||||||
|
_BOOL_T_FLAG_RE = re.compile(
|
||||||
|
'cli\\.BoolTFlag{(?P<args>[^}]*)}',
|
||||||
|
flags=re.DOTALL
|
||||||
|
)
|
||||||
|
|
||||||
_MIGRATORS = {}
|
_MIGRATORS = {}
|
||||||
|
|
||||||
@ -162,6 +167,21 @@ def _migrate_v1_imports(source):
|
|||||||
return _V1_IMPORT_RE.sub(_V2_IMPORT, source)
|
return _V1_IMPORT_RE.sub(_V2_IMPORT, source)
|
||||||
|
|
||||||
|
|
||||||
|
@_migrator
|
||||||
|
def _migrate_new_exit_error(source):
|
||||||
|
return _EXIT_ERROR_RE.sub('cli.Exit', source)
|
||||||
|
|
||||||
|
@_migrator
|
||||||
|
def _migrate_bool_t_flag(source):
|
||||||
|
return _BOOL_T_FLAG_RE.sub(_bool_t_flag_repl, source)
|
||||||
|
|
||||||
|
|
||||||
|
def _bool_t_flag_repl(match):
|
||||||
|
return 'cli.BoolFlag{{Value: true, {}}}'.format(
|
||||||
|
match.groupdict()['args']
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_migrators():
|
def test_migrators():
|
||||||
import difflib
|
import difflib
|
||||||
|
|
||||||
@ -235,6 +255,30 @@ _MIGRATOR_TESTS = (
|
|||||||
\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"
|
||||||
|
"""),
|
||||||
|
("""
|
||||||
|
\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},
|
||||||
|
\t\t\t\t&cli.BoolFlag{Value: true,
|
||||||
|
\t\t\t\t\tName: "blurp",
|
||||||
|
\t\t\t\t},
|
||||||
|
\t\t\t}
|
||||||
""")
|
""")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
3
runtests
3
runtests
@ -88,7 +88,8 @@ def _migrations():
|
|||||||
_run(['python', migration_script, '-w', gofile])
|
_run(['python', migration_script, '-w', gofile])
|
||||||
_run('go build -o tmp.out {}'.format(gofile).split())
|
_run('go build -o tmp.out {}'.format(gofile).split())
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(tmpdir, ignore_errors=True)
|
if os.environ.get('NOCLEAN', '') == '':
|
||||||
|
shutil.rmtree(tmpdir, ignore_errors=True)
|
||||||
|
|
||||||
|
|
||||||
def _run(command):
|
def _run(command):
|
||||||
|
Loading…
Reference in New Issue
Block a user