From 1083121433d58d5cb41700c027ea682f020b240f Mon Sep 17 00:00:00 2001 From: Steven Honson Date: Sat, 28 Jul 2012 19:42:29 +1000 Subject: [PATCH] Cosmetic and formatting fixes, examples and tests made more generic. --- AUTHORS.rst | 9 +++------ README.rst | 26 ++++++++++++-------------- args.py | 6 ++---- tests.py | 28 ++++++++++++---------------- 4 files changed, 29 insertions(+), 40 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index a04435f..79820df 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -2,12 +2,9 @@ Args is written and maintained by Kenneth Reitz and various contributors. Development Lead -------- - - Kenneth Reitz +- Kenneth Reitz Patches and Suggestions --- - - Kracekumar - - Steven Honson - - - +- Kracekumar +- Steven Honson \ No newline at end of file diff --git a/README.rst b/README.rst index 442e835..445dbd7 100644 --- a/README.rst +++ b/README.rst @@ -30,13 +30,13 @@ No arguments:: A few arguments:: - $ tool -s this that --arch=x64 --import this and that and this and that --arch=i386 - Arguments passed in: ['-s', 'this', 'that', '--arch=x64', '--import', 'this', 'and', 'that', 'and', 'this', 'and', 'that', '--arch=i386'] - Flags detected: + $ tool -s yes no --number=one --alphabet a b c --number=two + Arguments passed in: ['-s', 'yes', 'no', '--number=one', '--alphabet', 'a', 'b', 'c', '--number=two'] + Flags detected: Files detected: [] - NOT files detected: - Grouped Arguments: OrderedDict([('_', ), ('-s', ), ('--arch=x64', ), ('--import', ), ('--arch=i386', )]) - Assignments detected: OrderedDict([('--arch=', )]) + NOT files detected: + Grouped Arguments: OrderedDict([('_', ), ('-s', ), ('--number=one', ), ('--alphabet', ), ('--number=two', )]) + Assignments detected: OrderedDict([('--number', )]) A few expanded file arguments:: @@ -60,13 +60,12 @@ A few non-expanded file arguments:: A few mixed files/flags/arguments:: - $ tool '*.py' --test test face book -s ~/.ssh --arch=x64 - Arguments passed in: ['*.py', '--test', 'test', 'face', 'book', '-s', '/home/example/.ssh', '--arch=x64'] - Flags detected: - Files detected: ['args.py', 'setup.py', 'tests.py', '/home/example/.ssh/authorized_keys'] - NOT files detected: - Grouped Arguments: OrderedDict([('_', ), ('--test', ), ('-s', ), ('--arch=x64', )]) - Assignments detected: OrderedDict([('--arch=', )]) + Arguments passed in: ['*.py', '--alphabet', 'a', 'b', 'c', '-s', '/home/example/.example', '--number=one', '--number=two'] + Flags detected: + Files detected: ['setup.py', 'args.py', 'tool.py', 'tests.py', '/home/example/.example/two', '/home/example/.example/one'] + NOT files detected: + Grouped Arguments: OrderedDict([('_', ), ('--alphabet', ), ('-s', ), ('--number=one', ), ('--number=two', )]) + Assignments detected: OrderedDict([('--number', )]) Installation @@ -75,4 +74,3 @@ Installation Installation is simple with pip:: $ pip install args - diff --git a/args.py b/args.py index ffa4d1c..07d0342 100644 --- a/args.py +++ b/args.py @@ -3,9 +3,6 @@ """ args ~~~~ - -This module provides the CLI argument interface for clint. - """ import os @@ -48,7 +45,6 @@ def _is_collection(obj): return hasattr(obj, '__getitem__') - class ArgsList(object): """CLI Argument management.""" @@ -373,12 +369,14 @@ class ArgsList(object): return ArgsList(_args, no_argv=True) + @property def copy(self): """Returns a copy of Args object for temporary manipulation.""" return ArgsList(self.all) + @property def assignments(self): """Extracts assignment values from assignments.""" diff --git a/tests.py b/tests.py index e857695..7603d35 100644 --- a/tests.py +++ b/tests.py @@ -8,26 +8,24 @@ def compare_values(a, b): ok_(a == b) def test_args_all(): - arguments = ['install', '--lang', 'python', 'c', 'js'] + arguments = ['test', '--number', 'one', 'two', 'three'] arg = args.ArgsList(args = arguments) ok_(arg.all == arguments) def test_flags(): - flags = ['--name', '--email'] - arguments = [flags[0], 'kracekumar', flags[1], 'me@kracekumar'] + flags = ['--one', '--two'] + arguments = [flags[0], 'a', flags[1], 'b'] arg = args.ArgsList(args = arguments) ok_(arg.flags.all == flags) - def test_files(): files = ['*.py'] arg = args.ArgsList(args = files) - #any way current directory will have minimum one file i.e this file ok_(len(arg.files) > 1) def test_not_files(): - flags = ['--name', '--email'] - arguments = [flags[0], 'kracekumar', flags[1], 'me@kracekumar', '*.py'] + flags = ['--one', '--two'] + arguments = [flags[0], 'a', flags[1], 'b', '*.py'] arg = args.ArgsList(args = arguments) arguments.pop() ok_(arg.not_files.all == arguments) @@ -49,16 +47,16 @@ def test_grouped(): yield compare_values, arg.grouped[item].all, details[item] def test_start_with(): - dynamic_lang = ['python', 'perl'] - static_lang = ['c', 'c++'] - arguments = ['--lang'] - arguments.extend(dynamic_lang) - arguments.extend(static_lang) + numbers = ['one', 'two', 'three'] + fnumbers = ['four', 'five'] + arguments = ['--number'] + arguments.extend(numbers) + arguments.extend(fnumbers) arg = args.ArgsList(args = arguments) - ok_(arg.start_with('p').all == dynamic_lang) + ok_(arg.start_with('f').all == fnumbers) def test_assignments(): - details = {'--arch': ['x64', 'i386'], 'lang': ['']} + details = {'--number': ['one', 'two'], 'test': ['']} arguments = [] for key in details: for argument in details[key]: @@ -68,5 +66,3 @@ def test_assignments(): yield compare_values, len(arg.assignments), len(details) for item in arg.assignments: yield compare_values, arg.assignments[item].all, details[item] - -