diff --git a/.gitignore b/.gitignore index 8caaf99..1035dd7 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,9 @@ !.coveragerc *~ *.pyc +*.log build dist rtv.egg-info tests/refresh-token +venv/ diff --git a/rtv/config.py b/rtv/config.py index 2a29275..2a7e28a 100644 --- a/rtv/config.py +++ b/rtv/config.py @@ -32,13 +32,14 @@ def build_parser(): epilog=docs.CONTROLS, formatter_class=argparse.RawDescriptionHelpFormatter) parser.add_argument( - '-V', '--version', action='version', version='rtv '+__version__) + 'link', metavar='URL', nargs='?', + help='[optional] Full URL of a submission to open') parser.add_argument( '-s', dest='subreddit', - help='Name of the subreddit that will be opened on start') + help='Name of the subreddit that will be loaded on start') parser.add_argument( - '-l', dest='link', - help='Full URL of a submission that will be opened on start') + '-l', dest='link_deprecated', + help=argparse.SUPPRESS) # Deprecated, use the positional arg instead parser.add_argument( '--log', metavar='FILE', action='store', help='Log HTTP requests to the given file') @@ -52,8 +53,7 @@ def build_parser(): '--monochrome', action='store_const', const=True, help='Disable color') parser.add_argument( - '--non-persistent', dest='persistent', action='store_const', - const=False, + '--non-persistent', dest='persistent', action='store_const', const=False, help='Forget the authenticated user when the program exits') parser.add_argument( '--clear-auth', dest='clear_auth', action='store_const', const=True, @@ -67,6 +67,8 @@ def build_parser(): parser.add_argument( '--enable-media', dest='enable_media', action='store_const', const=True, help='Open external links using programs defined in the mailcap config') + parser.add_argument( + '-V', '--version', action='version', version='rtv '+__version__) return parser @@ -206,6 +208,12 @@ class Config(object): parser = build_parser() args = vars(parser.parse_args()) + + # Overwrite the deprecated "-l" option into the link variable + if args['link_deprecated'] and args['link'] is None: + args['link'] = args['link_deprecated'] + args.pop('link_deprecated', None) + # Filter out argument values that weren't supplied return {key: val for key, val in args.items() if val is not None} diff --git a/rtv/docs.py b/rtv/docs.py index c8904f1..de52f62 100644 --- a/rtv/docs.py +++ b/rtv/docs.py @@ -7,12 +7,11 @@ desktop:https://github.com/michael-lazar/rtv:{version}\ """ SUMMARY = """ -Reddit Terminal Viewer is a lightweight browser for www.reddit.com built into a -terminal window. +Reddit Terminal Viewer is a lightweight browser for https://www.reddit.com """ CONTROLS = """ -Move the cursor using either the arrow keys or *Vim* style movement. +Move the cursor using the arrow keys or vim style movement. Press `?` to open the help screen. """ diff --git a/tests/test_config.py b/tests/test_config.py index 060a6e4..b8b5c7f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -80,8 +80,8 @@ def test_config_get_args(): "Ensure that command line arguments are parsed properly" args = ['rtv', + 'https://reddit.com/permalink •', '-s', 'cfb', - '-l', 'https://reddit.com/permalink •', '--log', 'logfile.log', '--config', 'configfile.cfg', '--ascii', @@ -113,6 +113,23 @@ def test_config_get_args(): assert config['enable_media'] is True +def test_config_link_deprecated(): + + # Should still be able to specify the link using the old "-l" + args = ['rtv', '-l', 'https://reddit.com/option'] + with mock.patch('sys.argv', args): + config_dict = Config.get_args() + config = Config(**config_dict) + assert config['link'] == 'https://reddit.com/option' + + # But the positional argument should take preference + args = ['rtv', 'https://reddit.com/arg', '-l', 'https://reddit.com/option'] + with mock.patch('sys.argv', args): + config_dict = Config.get_args() + config = Config(**config_dict) + assert config['link'] == 'https://reddit.com/arg' + + def test_config_from_file(): "Ensure that config file arguments are parsed properly"