Skip to content

Commit

Permalink
Update pki CLI to use ArgumentParser
Browse files Browse the repository at this point in the history
The pki CLI has been updated to parse the main arguments (which
are also defined in MainCLI.java) using ArgumentParser, determine
the subcommand, then pass the remaining arguments to the Python
or Java module corresponding to the subcommand.

It does not use subparsers like in pki-server since the pki CLI
does not have the list of Java subcommands.

The pki CLI have options that might conflict with other options
in some subcommands. That will be addressed separately later.

The help message for default message format in MainCLI.java has
also been updated.
  • Loading branch information
edewata committed Jan 22, 2025
1 parent bb22542 commit 0c5c7e4
Show file tree
Hide file tree
Showing 4 changed files with 235 additions and 178 deletions.
33 changes: 1 addition & 32 deletions base/common/python/pki/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
#

import collections
import getopt
import logging
import sys
from six import itervalues

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -184,40 +182,11 @@ def parse_args(self, args):

return (module, module_args)

def execute(self, argv, args=None):
def execute(self, argv, args=None): # pylint: disable=W0613
'''
:param argv: Argument values
:param args: Parsed arguments
'''
try:
opts, args = getopt.getopt(argv, 'v', [
'verbose', 'help'])

except getopt.GetoptError as e:
logger.error(e)
self.print_help()
sys.exit(1)

if len(args) == 0:
self.print_help()
sys.exit()

for o, _ in opts:
if o == '--debug':
logging.getLogger().setLevel(logging.DEBUG)

elif o in ('-v', '--verbose'):
logging.getLogger().setLevel(logging.INFO)

elif o == '--help':
self.print_help()
sys.exit()

else:
logger.error('Unknown option: %s', o)
self.print_help()
sys.exit(1)

(module, module_argv) = self.parse_args(argv)

module.execute(module_argv)
Loading

0 comments on commit 0c5c7e4

Please sign in to comment.