mirror of
https://github.com/certbot/certbot.git
synced 2026-07-30 18:04:31 +02: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:
+30
-16
@@ -25,22 +25,30 @@ from letsencrypt import reporter
|
|||||||
|
|
||||||
from letsencrypt.display import util as display_util
|
from letsencrypt.display import util as display_util
|
||||||
from letsencrypt.display import ops as display_ops
|
from letsencrypt.display import ops as display_ops
|
||||||
|
|
||||||
from letsencrypt.plugins import disco as plugins_disco
|
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]
|
letsencrypt [SUBCOMMAND] [options] [domains]
|
||||||
|
|
||||||
The Let's Encrypt agent can obtain and install HTTPS/TLS/SSL certificates. By
|
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
|
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
|
# This is the short help for letsencrypt --help, where we disable argparse
|
||||||
auth Authenticate & obtain cert, but do not install it
|
# altogether
|
||||||
install Install a previously obtained cert in a server
|
USAGE = SHORT_USAGE + """Major SUBCOMMANDS are:
|
||||||
revoke Revoke a previously obtained certificate
|
|
||||||
rollback Rollback server configuration changes made during install
|
(default) everything Obtain & install a cert in your current webserver
|
||||||
config-changes Show changes made to server config during installation
|
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:
|
Choice of server for authentication/installation:
|
||||||
|
|
||||||
@@ -142,7 +150,7 @@ def run(args, config, plugins):
|
|||||||
|
|
||||||
|
|
||||||
def auth(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
|
# XXX: Update for renewer / RenewableCert
|
||||||
acc = _account_init(args, config)
|
acc = _account_init(args, config)
|
||||||
if acc is None:
|
if acc is None:
|
||||||
@@ -167,7 +175,7 @@ def auth(args, config, plugins):
|
|||||||
|
|
||||||
|
|
||||||
def install(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
|
# XXX: Update for renewer/RenewableCert
|
||||||
acc = _account_init(args, config)
|
acc = _account_init(args, config)
|
||||||
if acc is None:
|
if acc is None:
|
||||||
@@ -184,7 +192,7 @@ def install(args, config, plugins):
|
|||||||
|
|
||||||
|
|
||||||
def revoke(args, unused_config, unused_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:
|
if args.rev_cert is None and args.rev_key is None:
|
||||||
return "At least one of --certificate or --key is required"
|
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):
|
def rollback(args, config, plugins):
|
||||||
"""Rollback."""
|
"""Rollback server configuration changes made during install"""
|
||||||
client.rollback(args.installer, args.checkpoints, config, plugins)
|
client.rollback(args.installer, args.checkpoints, config, plugins)
|
||||||
|
|
||||||
|
|
||||||
def config_changes(unused_args, config, unused_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.
|
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
|
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)
|
logging.debug("Expected interfaces: %s", args.ifaces)
|
||||||
|
|
||||||
ifaces = [] if args.ifaces is None else 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()]
|
plugin_names = [name for name, _p in plugins.iteritems()]
|
||||||
self.help_topics = HELP_TOPICS + plugin_names
|
self.help_topics = HELP_TOPICS + plugin_names
|
||||||
self.parser = configargparse.ArgParser(
|
self.parser = configargparse.ArgParser(
|
||||||
description=__doc__,
|
usage=SHORT_USAGE,
|
||||||
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
||||||
args_for_setting_config_path=["-c", "--config"],
|
args_for_setting_config_path=["-c", "--config"],
|
||||||
default_config_files=flag_default("config_files"))
|
default_config_files=flag_default("config_files"))
|
||||||
|
|
||||||
|
self.parser._add_config_file_help = False
|
||||||
self.silent_parser = SilentParser(self.parser)
|
self.silent_parser = SilentParser(self.parser)
|
||||||
|
|
||||||
h1 = self.prescan_for_flag("-h", self.help_topics)
|
h1 = self.prescan_for_flag("-h", self.help_topics)
|
||||||
h2 = self.prescan_for_flag("--help", self.help_topics)
|
h2 = self.prescan_for_flag("--help", self.help_topics)
|
||||||
assert max(True, "a") == "a", "Gravity changed direction"
|
assert max(True, "a") == "a", "Gravity changed direction"
|
||||||
help_arg = max(h1, h2)
|
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)
|
self.visible_topics = self.determine_help_topics(help_arg)
|
||||||
#print self.visible_topics
|
#print self.visible_topics
|
||||||
self.groups = {} # elements are added by .add_group()
|
self.groups = {} # elements are added by .add_group()
|
||||||
|
|||||||
Reference in New Issue
Block a user