[stem/master] Moving --help output to configuration

commit 216a6072ccc5506ac7c00acc6ef618e531d42a23 Author: Damian Johnson <atagar@torproject.org> Date: Thu Apr 17 09:27:28 2014 -0700 Moving --help output to configuration It wasn't worth having a config file for just this one string, but now that we have one anyway we might as well use it. This also changes msg() to raise a ValueError so it's less likely that errors where we fail to fetch string resources will go unnoticed. --- stem/interpretor/__init__.py | 8 ++++---- stem/interpretor/arguments.py | 17 ++--------------- stem/interpretor/settings.cfg | 13 +++++++++++++ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/stem/interpretor/__init__.py b/stem/interpretor/__init__.py index c8cd513..3dce2a0 100644 --- a/stem/interpretor/__init__.py +++ b/stem/interpretor/__init__.py @@ -15,7 +15,6 @@ import stem import stem.connection import stem.prereq import stem.util.conf -import stem.util.log from stem.util.term import Attr, Color, format @@ -99,9 +98,11 @@ def msg(message, **attr): Provides the given message. :param str message: message handle - :param dict attr: attributes to format the message with + :param dict attr: values to insert into the message :returns: **str** that was requested + + :raises: **ValueError** if string key doesn't exist """ config = stem.util.conf.get_config('stem_interpretor') @@ -109,5 +110,4 @@ def msg(message, **attr): try: return config.get(message).format(**attr) except: - stem.util.log.notice('BUG: We attempted to use an undefined string resource (%s)' % message) - return '' + raise ValueError('We attempted to use an undefined string resource (%s)' % message) diff --git a/stem/interpretor/arguments.py b/stem/interpretor/arguments.py index bd6655d..ff25fb7 100644 --- a/stem/interpretor/arguments.py +++ b/stem/interpretor/arguments.py @@ -8,6 +8,7 @@ Commandline argument parsing for arm. import collections import getopt +import stem.interpretor import stem.util.connection DEFAULT_ARGS = { @@ -27,20 +28,6 @@ OPT_EXPANDED = [ 'help', ] -HELP_OUTPUT = """ -Usage prompt [OPTION] -Interactive interpretor for Tor. - - -i, --interface [ADDRESS:]PORT change control interface from {address}:{port} - -s, --socket SOCKET_PATH attach using unix domain socket if present, - SOCKET_PATH defaults to: {socket} - -h, --help presents this help - -Example: -prompt -i 1643 attach to control port 1643 -prompt -s ~/.tor/socket attach to a control socket in your home directory -""" - def parse(argv): """ @@ -97,7 +84,7 @@ def get_help(): :returns: **str** with our usage information """ - return HELP_OUTPUT.format( + return stem.interpretor.msg('msg.help', address = DEFAULT_ARGS['control_address'], port = DEFAULT_ARGS['control_port'], socket = DEFAULT_ARGS['control_socket'], diff --git a/stem/interpretor/settings.cfg b/stem/interpretor/settings.cfg index 9430748..bb67144 100644 --- a/stem/interpretor/settings.cfg +++ b/stem/interpretor/settings.cfg @@ -6,6 +6,19 @@ msg.multiline_unimplemented_notice Multi-line control options like this are not yet implemented. +msg.help +|Usage prompt [OPTION] +|Interactive interpretor for Tor. +| +| -i, --interface [ADDRESS:]PORT change control interface from {address}:{port} +| -s, --socket SOCKET_PATH attach using unix domain socket if present, +| SOCKET_PATH defaults to: {socket} +| -h, --help presents this help +| +|Example: +|prompt -i 1643 attach to control port 1643 +|prompt -s ~/.tor/socket attach to a control socket in your home directory + help.quit Terminates the interpretor. help.saveconf Writes Tor's current configuration to its torrc. help.postdescriptor Simulates getting a new relay descriptor.
participants (1)
-
atagar@torproject.org