Skip to content

Commit

Permalink
[recipes.py] move autoroll arg parsing to its module
Browse files Browse the repository at this point in the history
R=dnj@chromium.org, phajdan.jr@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2845873002
  • Loading branch information
riannucci authored and Commit bot committed Apr 29, 2017
1 parent a8d7f32 commit 3cc22ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
27 changes: 26 additions & 1 deletion recipe_engine/autoroll.py
Expand Up @@ -267,7 +267,32 @@ def test_rolls(repo_cfg_block, config_file, context, package_spec,
return ret


def main(args, repo_root, config_file):
def add_subparser(parser):
autoroll_p = parser.add_parser(
'autoroll',
help='Roll dependencies of a recipe package forward (implies fetch)')
autoroll_p.add_argument(
'--output-json',
type=os.path.abspath,
help='A json file to output information about the roll to.')
autoroll_p.add_argument(
'--verbose-json',
action='store_true',
help=('Emit even more data in the output-json file. '
'Requires --output-json.'))

def postprocess_func(parser, args):
if args.verbose_json and not args.output_json:
parser.error('--verbose-json passed without --output-json')

autoroll_p.set_defaults(
command='autoroll', func=main, postprocess_func=postprocess_func)


def main(_package_deps, args):
config_file = args.package
repo_root = package.InfraRepoConfig().from_recipes_cfg(config_file.path)

package_pb = config_file.read()

context = package.PackageContext.from_package_pb(
Expand Down
29 changes: 2 additions & 27 deletions recipes.py
Expand Up @@ -226,16 +226,6 @@ def remote(args):
return remote.main(args)


def autoroll(repo_root, config_file, args):
from recipe_engine import autoroll

if args.verbose_json and not args.output_json:
print >> sys.stderr, '--verbose-json passed without --output-json'
return 1

return autoroll.main(args, repo_root, config_file)


class ProjectOverrideAction(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
p = values.split('=', 2)
Expand Down Expand Up @@ -394,8 +384,8 @@ def main():

common_postprocess_func = add_common_args(parser)

from recipe_engine import fetch, lint_test, bundle, depgraph
to_add = [fetch, lint_test, bundle, depgraph]
from recipe_engine import fetch, lint_test, bundle, depgraph, autoroll
to_add = [fetch, lint_test, bundle, depgraph, autoroll]

subp = parser.add_subparsers()
for module in to_add:
Expand Down Expand Up @@ -504,19 +494,6 @@ def properties_type(value):
'remote_args', nargs='*',
help='Arguments to pass to fetched repo\'s recipes.py')

autoroll_p = subp.add_parser(
'autoroll',
help='Roll dependencies of a recipe package forward (implies fetch)')
autoroll_p.set_defaults(command='autoroll')
autoroll_p.add_argument(
'--output-json',
type=os.path.abspath,
help='A json file to output information about the roll to.')
autoroll_p.add_argument(
'--verbose-json',
action='store_true',
help=('Emit even more data in the output-json file. '
'Requires --output-json.'))

refs_p = subp.add_parser(
'refs',
Expand Down Expand Up @@ -620,8 +597,6 @@ def _real_main(args):
return test(config_file, package_deps, args)
elif args.command == 'run':
return run(config_file, package_deps, args)
elif args.command == 'autoroll':
return autoroll(repo_root, config_file, args)
elif args.command == 'refs':
return refs(config_file, package_deps, args)
elif args.command == 'doc':
Expand Down

0 comments on commit 3cc22ba

Please sign in to comment.