Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/cli rework #432

Closed
wants to merge 5 commits into from
Closed

Conversation

mcrowson
Copy link
Collaborator

Description

Redid the CLI so we could have help on the commands. A few questions:

  1. The test_cli_args currently just returns and prints "The command is not recognized" The rework causes this to fail because derp was never a command. If the intention was to exit, i have modified the test to grab that exit. If the intent was to succeed, let me know what success looks like and I can update the test so it doesn't exit.
  2. Do both -s and -a arguments come before the command argument?
  3. Do both -y and --all arguments come after the command argument?

GitHub Issues

#404

@mcrowson
Copy link
Collaborator Author

Looks like it has issues with how we're getting the versions. This might be easier to merge after #426 or implement a different version method.

@mcrowson
Copy link
Collaborator Author

mcrowson commented Dec 7, 2016

It looks like there is interest in progressing the CLI, If this PR seems more appealing than #519 I can bring it up to date with master.

zappa_cli.handle(argv)
with self.assertRaises(SystemExit) as system_exit:
# https://github.com/Miserlou/Zappa/issues/404
# Previously returned with printed warning. Now exists as derp is not a valid command.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exists -> exits

# https://github.com/Miserlou/Zappa/issues/404
# Previously returned with printed warning. Now exists as derp is not a valid command.
zappa_cli.handle(argv)
self.assertNotEqual(system_exit.exception.code, 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not check this against the actual return code? argparse will always exit with a code 2 for an incorrect argument.

# Functionality shared by all commands
parent_parser = argparse.ArgumentParser(add_help=False)
parent_parser.add_argument('environment', type=str, help='Deployment environment', default=None, nargs='?')
parent_parser.add_argument('-y', '--yes', action='store_true', help='Auto confirm yes', default=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT the yes argument is only used by the undeploy command.

subparsers = parser.add_subparsers(title="Zappa Commands", help="Choose a valid zappa command", dest='command')

# Parent Parser
# Functionality shared by all commands
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this functionality is shared by all commands. zappa --all init doesn't make much sense for example.


# Deploy command
deploy_help = "Deploy the Zappa application."
deploy_parser = subparsers.add_parser('deploy', description=deploy_help, help=deploy_help, parents=[parent_parser])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parser doesn't need to be assigned to a variable since it's never used afterwards. Same applies to init_parser, manage_parser, schedule_parser, unschedule_parser, and update_parser.

# Certify command
certify_help = "Use Let's Encrypt to setup SSL to the domain specified in the config"
certify_parser = subparsers.add_parser('certify', description=certify_help, help=certify_help, parents=[parent_parser])
certify_parser.add_argument('--no-cleanup', action='store_true', help="Don't remove certificate files from /tmp during certify. Dangerous.", default=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the action is 'store_true' argparse assigns a default of False so it doesn't need to be specified here.

@@ -193,16 +213,16 @@ def handle(self, argv=None):
if all_environments: # All envs!
environments = self.zappa_settings.keys()
else: # Just one env.
if len(self.command_env) < 2: # pragma: no cover
if self.command_env is None: # pragma: no cover
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if not self.command_env:

self.command_env = self.vargs['command_env']
self.command = self.command_env[0]
# Make sure there isn't a new version available
self.check_for_update()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This no longer lets you bypass check_for_update when specifying --json. Was that intended?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

# If there's only one environment defined in the settings,
# use that as the default.
if len(self.zappa_settings.keys()) is 1:
environments.append(self.zappa_settings.keys()[0])
else:
parser.error("Please supply an environment to interact with.")
parser.error("There is more than 1 environment in the settings file. Please supply an environment to interact with.")
sys.exit(1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this isn't yours but this line will never be reached. parser.error() exits with a status code of 2.

parser.add_argument('command_env', metavar='U', type=str, nargs='*', help=help_message)
parser.add_argument('-n', '--num-rollback', type=int, default=0,
help='The number of versions to rollback.')
parser = argparse.ArgumentParser(description='Zappa - Deploy Python applications to AWS Lambda and API Gateway.\n', version=pkg_resources.require("zappa")[0].version, prog="zappa")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, I've never seen version= used here to provide a version argument. TIL.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, argparse has version built in. https://docs.python.org/2.7/library/argparse.html#action

@mcrowson
Copy link
Collaborator Author

@rmoe is taking over this stuff with #519

@mcrowson mcrowson closed this Dec 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants