diff options
author | 2015-07-23 08:58:30 -0700 | |
---|---|---|
committer | 2015-08-08 08:51:40 -0700 | |
commit | 7b6040a62b1f590c2e09564158f4b3ad3faadd9f (patch) | |
tree | 33e54cbafdad74fae8c4e5b777e9999084a0282e | |
parent | gkeys: Update copyrights, Add Pavlos to several files (diff) | |
download | gentoo-keys-7b6040a62b1f590c2e09564158f4b3ad3faadd9f.tar.gz gentoo-keys-7b6040a62b1f590c2e09564158f4b3ad3faadd9f.tar.bz2 gentoo-keys-7b6040a62b1f590c2e09564158f4b3ad3faadd9f.zip |
gentoo-keys: Modify the cli base for the new gkeys-gpg gpg wrapper command
gkeys-gpg needs options added to the base app without sub commands.
-rw-r--r-- | gkeys-gen/gkeygen/cli.py | 1 | ||||
-rw-r--r-- | gkeys-ldap/gkeyldap/cli.py | 1 | ||||
-rw-r--r-- | gkeys/gkeys/base.py | 47 | ||||
-rw-r--r-- | gkeys/gkeys/cli.py | 1 |
4 files changed, 31 insertions, 19 deletions
diff --git a/gkeys-gen/gkeygen/cli.py b/gkeys-gen/gkeygen/cli.py index f522814..c0beb3b 100644 --- a/gkeys-gen/gkeygen/cli.py +++ b/gkeys-gen/gkeygen/cli.py @@ -32,6 +32,7 @@ class Main(CliBase): 'Actions': Actions, 'Available_Actions': Available_Actions, 'Action_Map': Action_Map, + 'Base_Options': [], 'prog': 'gkeys-gen', 'description': 'Gentoo Keys GPG key generator program', 'epilog': '''CAUTION: adding UNTRUSTED keys can be HAZARDOUS to your system!''' diff --git a/gkeys-ldap/gkeyldap/cli.py b/gkeys-ldap/gkeyldap/cli.py index f18b6de..4d38485 100644 --- a/gkeys-ldap/gkeyldap/cli.py +++ b/gkeys-ldap/gkeyldap/cli.py @@ -34,6 +34,7 @@ class Main(CliBase): 'Actions': Actions, 'Available_Actions': Available_Actions, 'Action_Map': Action_Map, + 'Base_Options': [], 'prog': 'gkeys-ldap', 'description': 'Gentoo-keys LDAP interface and seed file generator program', 'epilog': '''CAUTION: adding UNTRUSTED keys can be HAZARDOUS to your system!''' diff --git a/gkeys/gkeys/base.py b/gkeys/gkeys/base.py index 4cee27d..dbe6642 100644 --- a/gkeys/gkeys/base.py +++ b/gkeys/gkeys/base.py @@ -64,6 +64,7 @@ class CliBase(object): 'Actions': None, 'Available_Actions': [], 'Action_Map': {}, + 'Base_Options': [], 'prog': 'gkeys', 'description': 'Gentoo-keys manager program', 'epilog': '''Caution: adding UNTRUSTED keys can be HAZARDOUS to your system!''' @@ -74,6 +75,7 @@ class CliBase(object): self.actions = None self.logger = None self.version = None + self.need_Action = True @staticmethod @@ -242,29 +244,32 @@ class CliBase(object): parser.add_argument('-V', '--version', action = 'version', version = self.version) + # Add any additional options to the command base + self._add_options(parser, self.cli_config['Base_Options']) - subparsers = parser.add_subparsers( - title='Subcommands', - description='Valid subcommands', - help='Additional help') - for name in self.cli_config['Available_Actions']: - actiondoc = self.cli_config['Action_Map'][name]['desc'] - try: - text = actiondoc.splitlines()[0] - except AttributeError: - text = "" - action_parser = subparsers.add_parser( - name, - help=text, - description=actiondoc, - formatter_class=argparse.RawDescriptionHelpFormatter) - action_parser.set_defaults(action=name) - options = self.cli_config['Action_Map'][name]['options'] - self._add_options(action_parser, options) + if self.cli_config['Available_Actions']: + subparsers = parser.add_subparsers( + title='Subcommands', + description='Valid subcommands', + help='Additional help') + for name in self.cli_config['Available_Actions']: + actiondoc = self.cli_config['Action_Map'][name]['desc'] + try: + text = actiondoc.splitlines()[0] + except AttributeError: + text = "" + action_parser = subparsers.add_parser( + name, + help=text, + description=actiondoc, + formatter_class=argparse.RawDescriptionHelpFormatter) + action_parser.set_defaults(action=name) + options = self.cli_config['Action_Map'][name]['options'] + self._add_options(action_parser, options) parsed_args = parser.parse_args(argv) action = getattr(parsed_args, 'action', None) - if not action: + if self.need_Action and not action: parser.print_usage() sys.exit(1) elif action in ['---general---', '----keys-----', '----seeds----']: @@ -327,6 +332,10 @@ class CliBase(object): def run(self, args): + '''Run the action selected + + @param args: list of argumanets to parse + ''' # establish our actions instance self.actions = self.cli_config['Actions'](self.config, self.output_results, self.logger) diff --git a/gkeys/gkeys/cli.py b/gkeys/gkeys/cli.py index 532c03e..8ce00b3 100644 --- a/gkeys/gkeys/cli.py +++ b/gkeys/gkeys/cli.py @@ -41,6 +41,7 @@ class Main(CliBase): 'Actions': Actions, 'Available_Actions': Available_Actions, 'Action_Map': Action_Map, + 'Base_Options': [], 'prog': 'gkeys', 'description': 'Gentoo-keys manager program', 'epilog': '''CAUTION: adding UNTRUSTED keys can be HAZARDOUS to your system!''' |