aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2015-07-23 08:58:30 -0700
committerBrian Dolbec <dolsen@gentoo.org>2015-07-23 08:58:30 -0700
commiteef202ed24e26c70b138df0bece2f3fc8fa581d2 (patch)
tree862c330c680bc8cb3ae49d8236b31d936352398d
parentgkeys/actions.py: Add filename extension check exclusion (diff)
downloadgentoo-keys-eef202ed24e26c70b138df0bece2f3fc8fa581d2.tar.gz
gentoo-keys-eef202ed24e26c70b138df0bece2f3fc8fa581d2.tar.bz2
gentoo-keys-eef202ed24e26c70b138df0bece2f3fc8fa581d2.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.py1
-rw-r--r--gkeys-ldap/gkeyldap/cli.py1
-rw-r--r--gkeys/gkeys/base.py47
-rw-r--r--gkeys/gkeys/cli.py1
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 fba1976..55ade81 100644
--- a/gkeys/gkeys/base.py
+++ b/gkeys/gkeys/base.py
@@ -35,6 +35,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!'''
@@ -45,6 +46,7 @@ class CliBase(object):
self.actions = None
self.logger = None
self.version = None
+ self.need_Action = True
@staticmethod
@@ -213,29 +215,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----']:
@@ -297,6 +302,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 194afd2..bbe8897 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!'''