Option name can't be dashed #421

Closed
wants to merge 2 commits into
from

Projects

None yet

3 participants

@mher
mher commented Dec 15, 2011

from tornado.options import options, define, parse_command_line
define("mysql-host", default="127.0.0.1")
parse_command_line("progname --mysql-host=localhost".split())
Usage: [OPTIONS]

Options:
--help show this help information
--log_file_max_size max size of log files before rollover
--log_file_num_backups number of log files to keep
--log_file_prefix=PATH Path prefix for log files. Note that if you are running multiple tornado processes, log_file_prefix must be different for each of them (e.g. include the port number)
--log_to_stderr Send log output to stderr (colorized if possible). By default use stderr if --log_file_prefix is not set and no other logging is configured.
--logging=info|warning|error|none Set the Python log level. If 'none', tornado won't touch the logging configuration.

--mysql-host

Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/tornado/options.py", line 125, in parse_command_line
raise Error('Unrecognized command line option: %r' % name)
tornado.options.Error: Unrecognized command line option: 'mysql_host'

With patch:

from tornado.options import options, define, parse_command_line
define("mysql-host", default="127.0.0.1")
parse_command_line("progname --mysql-host=localhost".split())
[]
options.mysql_host
u'localhost'
options['mysql-host'].value()
u'localhost'

@bdarnell
Member

This doesn't work for the parse_config_file half of the options interface. Also, the predefined options --log_file_prefix et al would still be underscore-only. Maybe all we need is a replace('-', '_') in define() to go along with the one in parse_command_line?

@mher
mher commented Dec 16, 2011

On Dec 16, 2011, at 7:13 AM, bdarnell wrote:

This doesn't work for the parse_config_file half of the options interface.

mher@69594d8

Also, the predefined options --log_file_prefix et al would still be underscore-only.

The patch only adds an ability to use dashed names. Underscore-only names are usable as before.

Maybe all we need is a replace('-', '_') in define() to go along with the one in parse_command_line?

It will break backward compatibility. options['dashed-name'] will become broken.

@bdarnell bdarnell added the options label Jul 16, 2014
@mjrk
mjrk commented Jun 10, 2015

+1

@bdarnell bdarnell closed this in 463669e Jul 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment