Skip to content

Commit

Permalink
updated main.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tikazyq committed Dec 22, 2021
1 parent 9049541 commit 5bc9e20
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions python/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
type=str)
login_parser.add_argument('--password', '-p', help='Password for logging in Crawlab', default=CLI_DEFAULT_API_PASSWORD,
type=str)
login_parser.set_defaults(func=login)
login_parser.set_defaults(func=login, action=CLI_ACTION_LOGIN)

# upload parser
upload_parser = subparsers.add_parser(CLI_ACTION_UPLOAD)
Expand All @@ -35,18 +35,31 @@
upload_parser.add_argument('--col_name', '-C',
help='Spider results collection name if creating a new spider. Default: results_<spider_name>',
type=str)
upload_parser.set_defaults(func=upload)
upload_parser.set_defaults(func=upload, action=CLI_ACTION_UPLOAD)

# config parser
config_parser = subparsers.add_parser(CLI_ACTION_CONFIG)
config_parser.add_argument('--set', '-s', type=str)
config_parser.add_argument('--unset', '-u', type=str)
config_parser.set_defaults(func=config_func)
config_parser.set_defaults(func=config_func, action=CLI_ACTION_CONFIG)


def main():
args = root_parser.parse_args()
args.func(args)
if not hasattr(args, 'func'):
root_parser.print_help()
return
try:
args.func(args)
except Exception:
if getattr(args, 'action') == CLI_ACTION_LOGIN:
login_parser.print_help()
elif getattr(args, 'action') == CLI_ACTION_UPLOAD:
upload_parser.print_help()
elif getattr(args, 'action') == CLI_ACTION_CONFIG:
config_parser.print_help()
else:
root_parser.print_help()


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion python/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setup(
name='crawlab-sdk',
version='0.6.b20211213_2123',
version='0.6.b20211222_1538',
packages=find_packages(),
url='https://github.com/crawlab-team/crawlab-sdk',
license='BSD-3-Clause',
Expand Down

0 comments on commit 5bc9e20

Please sign in to comment.