mirror of
https://github.com/certbot/certbot.git
synced 2026-06-07 15:52:08 -04:00
Use a completely custom usage mesage for plain --help
Keep argparse in place for --help <TOPIC>, but try to make that match the customised short help as much as possible.
This commit is contained in:
parent
f408ac7296
commit
02f3bb4f05
1 changed files with 30 additions and 16 deletions
|
|
@ -25,22 +25,30 @@ from letsencrypt import reporter
|
|||
|
||||
from letsencrypt.display import util as display_util
|
||||
from letsencrypt.display import ops as display_ops
|
||||
|
||||
from letsencrypt.plugins import disco as plugins_disco
|
||||
|
||||
USAGE = """
|
||||
# Argparse's help formatting has a lot of unhelpful peculiarities, so we want
|
||||
# to replace as much of it as we can...
|
||||
|
||||
# This is the stub to include in help generated by argparse
|
||||
|
||||
SHORT_USAGE = """
|
||||
letsencrypt [SUBCOMMAND] [options] [domains]
|
||||
|
||||
The Let's Encrypt agent can obtain and install HTTPS/TLS/SSL certificates. By
|
||||
default, it will attempt to use a webserver both for obtaining and installing
|
||||
the cert. Major SUBCOMMANDS are:
|
||||
the cert. """
|
||||
|
||||
(default) Obtain & install a cert in your current webserver
|
||||
auth Authenticate & obtain cert, but do not install it
|
||||
install Install a previously obtained cert in a server
|
||||
revoke Revoke a previously obtained certificate
|
||||
rollback Rollback server configuration changes made during install
|
||||
config-changes Show changes made to server config during installation
|
||||
# This is the short help for letsencrypt --help, where we disable argparse
|
||||
# altogether
|
||||
USAGE = SHORT_USAGE + """Major SUBCOMMANDS are:
|
||||
|
||||
(default) everything Obtain & install a cert in your current webserver
|
||||
auth Authenticate & obtain cert, but do not install it
|
||||
install Install a previously obtained cert in a server
|
||||
revoke Revoke a previously obtained certificate
|
||||
rollback Rollback server configuration changes made during install
|
||||
config-changes Show changes made to server config during installation
|
||||
|
||||
Choice of server for authentication/installation:
|
||||
|
||||
|
|
@ -142,7 +150,7 @@ def run(args, config, plugins):
|
|||
|
||||
|
||||
def auth(args, config, plugins):
|
||||
"""Obtain a certificate (no install)."""
|
||||
"""Authenticate & obtain cert, but do not install it"""
|
||||
# XXX: Update for renewer / RenewableCert
|
||||
acc = _account_init(args, config)
|
||||
if acc is None:
|
||||
|
|
@ -167,7 +175,7 @@ def auth(args, config, plugins):
|
|||
|
||||
|
||||
def install(args, config, plugins):
|
||||
"""Install cert in server software (no auth)."""
|
||||
"""Install a previously obtained cert in a server"""
|
||||
# XXX: Update for renewer/RenewableCert
|
||||
acc = _account_init(args, config)
|
||||
if acc is None:
|
||||
|
|
@ -184,7 +192,7 @@ def install(args, config, plugins):
|
|||
|
||||
|
||||
def revoke(args, unused_config, unused_plugins):
|
||||
"""Revoke."""
|
||||
"""Revoke a previously obtained certificate"""
|
||||
if args.rev_cert is None and args.rev_key is None:
|
||||
return "At least one of --certificate or --key is required"
|
||||
|
||||
|
|
@ -196,12 +204,12 @@ def revoke(args, unused_config, unused_plugins):
|
|||
|
||||
|
||||
def rollback(args, config, plugins):
|
||||
"""Rollback."""
|
||||
"""Rollback server configuration changes made during install"""
|
||||
client.rollback(args.installer, args.checkpoints, config, plugins)
|
||||
|
||||
|
||||
def config_changes(unused_args, config, unused_plugins):
|
||||
"""View config changes.
|
||||
"""Show changes made to server config during installation
|
||||
|
||||
View checkpoints and associated configuration changes.
|
||||
|
||||
|
|
@ -210,7 +218,7 @@ def config_changes(unused_args, config, unused_plugins):
|
|||
|
||||
|
||||
def plugins_cmd(args, config, plugins): # TODO: Use IDiplay rathern than print
|
||||
"""List plugins."""
|
||||
"""List server software plugins"""
|
||||
logging.debug("Expected interfaces: %s", args.ifaces)
|
||||
|
||||
ifaces = [] if args.ifaces is None else args.ifaces
|
||||
|
|
@ -285,16 +293,22 @@ class HelpfulArgumentParser(object):
|
|||
plugin_names = [name for name, _p in plugins.iteritems()]
|
||||
self.help_topics = HELP_TOPICS + plugin_names
|
||||
self.parser = configargparse.ArgParser(
|
||||
description=__doc__,
|
||||
usage=SHORT_USAGE,
|
||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||
args_for_setting_config_path=["-c", "--config"],
|
||||
default_config_files=flag_default("config_files"))
|
||||
|
||||
self.parser._add_config_file_help = False
|
||||
self.silent_parser = SilentParser(self.parser)
|
||||
|
||||
h1 = self.prescan_for_flag("-h", self.help_topics)
|
||||
h2 = self.prescan_for_flag("--help", self.help_topics)
|
||||
assert max(True, "a") == "a", "Gravity changed direction"
|
||||
help_arg = max(h1, h2)
|
||||
if help_arg == True:
|
||||
# just --help with no topic; avoid argparse altogether
|
||||
print USAGE
|
||||
sys.exit(0)
|
||||
self.visible_topics = self.determine_help_topics(help_arg)
|
||||
#print self.visible_topics
|
||||
self.groups = {} # elements are added by .add_group()
|
||||
|
|
|
|||
Loading…
Reference in a new issue