From f0f7dd41d18e5dcfbd9604ac74641c677b4da84e Mon Sep 17 00:00:00 2001 From: JorisE Date: Tue, 28 Jan 2014 00:18:23 +0100 Subject: [PATCH 1/2] The prompt_choices function now returns a correct result. The prompt_choices function would try to call string.ascii_lowercase(rv) where rv is a string. This would raise an error because ascii_lowercase is not a function. Assuming that the intended result is a lowercase version of the string, this has been changed to use rv.lower() Also the check:: if isinstance(string, basestring): has been changed to:: if type(string) is str: because basestring is not defined in python3. --- tmuxp/cli.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index e09a3f883cd..4ca09faeedf 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -106,8 +106,7 @@ def prompt_yes_no(name, default=True): return prompt_bool(name, default=default) -def prompt_choices(name, choices, default=None, resolve=ascii_lowercase, - no_choice=('none',)): +def prompt_choices(name, choices, default=None, no_choice=('none',)): """Return user input from command line from set of provided choices. :param name: prompt text @@ -123,7 +122,7 @@ def prompt_choices(name, choices, default=None, resolve=ascii_lowercase, options = [] for choice in choices: - if isinstance(choice, basestring): + if type(choice) is str: options.append(choice) else: options.append("%s [%s]" % (choice[1], choice[0])) @@ -134,7 +133,7 @@ def prompt_choices(name, choices, default=None, resolve=ascii_lowercase, rv = prompt(name + ' - (%s)' % ', '.join(options), default) if not rv: return default - rv = resolve(rv) + rv = rv.lower() if rv in no_choice: return None if rv in _choices: From 6d92023d0f06bbd902b231e377727e72e48c2a20 Mon Sep 17 00:00:00 2001 From: JorisE Date: Tue, 28 Jan 2014 00:39:51 +0100 Subject: [PATCH 2/2] A check has been added to know if args has an attribute 'callback'. If args has no attribute callback, the help text should be printed. Because there was a check to:: if args.callback is 'x': It would raise an error before the parser.print_help() was reached. --- tmuxp/cli.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 4ca09faeedf..7290626d176 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -965,7 +965,9 @@ def main(): ) try: - if args.callback is command_load: + if not hasattr(args, 'callback'): + parser.print_help() + elif args.callback is command_load: command_load(args) elif args.callback is command_convert: command_convert(args) @@ -979,7 +981,5 @@ def main(): command_attach_session(args) elif args.callback is command_kill_session: command_kill_session(args) - else: - parser.print_help() except KeyboardInterrupt: pass