Files
@ 0590c952df64
Branch filter:
Location: gimmecert/gimmecert/cli.py - annotation
0590c952df64
2.1 KiB
text/x-python
GC-11: Added a help subcommand to the tool:
- Updated functional test for checking on the help subcommand as well.
- Implemented the 'help' subcommand.
- Updated required function signature for the subcommand_parser
decorator (functions should return ArgumentParser instance).
- Fixed a typo in inline documentation.
- Updated the test for subcommand_parser decorator to be a more robust
when checking if function registration works.
- Updated functional test for checking on the help subcommand as well.
- Implemented the 'help' subcommand.
- Updated required function signature for the subcommand_parser
decorator (functions should return ArgumentParser instance).
- Fixed a typo in inline documentation.
- Updated the test for subcommand_parser decorator to be a more robust
when checking if function registration works.
d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 0590c952df64 0590c952df64 d8ec591edb40 cf5813628ae1 cf5813628ae1 cf5813628ae1 e82ee8e024f4 e82ee8e024f4 cf5813628ae1 cf5813628ae1 cf5813628ae1 0590c952df64 0590c952df64 0590c952df64 0590c952df64 0590c952df64 0590c952df64 0590c952df64 0590c952df64 0590c952df64 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 cf5813628ae1 cf5813628ae1 cf5813628ae1 d8ec591edb40 0590c952df64 0590c952df64 0590c952df64 0590c952df64 0590c952df64 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 d8ec591edb40 cf5813628ae1 cf5813628ae1 cf5813628ae1 cf5813628ae1 cf5813628ae1 d8ec591edb40 d8ec591edb40 d8ec591edb40 cf5813628ae1 cf5813628ae1 | # -*- coding: utf-8 -*-
#
# Copyright (C) 2018 Branko Majic
#
# This file is part of Gimmecert.
#
# Gimmecert is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# Gimmecert is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Gimmecert. If not, see <http://www.gnu.org/licenses/>.
#
import argparse
from .decorators import subcommand_parser, get_subcommand_parser_setup_functions
DESCRIPTION = """\
Issues server and client X.509 certificates using a local CA
hierarchy.
Examples:
"""
@subcommand_parser
def setup_help_subcommand_parser(parser, subparsers):
subparser = subparsers.add_parser('help', description='shows help')
subparser.set_defaults(func=lambda args: parser.print_help())
return subparser
def get_parser():
"""
Sets-up and returns a CLI argument parser.
:returns: argparse.ArgumentParser -- argument parser for CLI.
"""
parser = argparse.ArgumentParser(description=DESCRIPTION)
parser.set_defaults(func=lambda args: parser.print_usage())
subparsers = parser.add_subparsers()
for setup_subcommad_parser in get_subcommand_parser_setup_functions():
setup_subcommad_parser(parser, subparsers)
return parser
def main():
"""
This function is a CLI entry point for the tool. It is a thin
wrapper around the argument parser, and underlying command
implementation.
In order for this to work, the parser needs to register the
callback function as a default parameter for attribute
'func'. This attribute is then invoked by the main function,
passing-in all the parsed arguments while at it.
"""
parser = get_parser()
args = parser.parse_args()
args.func(args)
|