mirror of
https://github.com/kennethreitz-archive/args.git
synced 2026-06-05 15:10:18 +00:00
Cosmetic and formatting fixes, examples and tests made more generic.
This commit is contained in:
+3
-6
@@ -2,12 +2,9 @@ Args is written and maintained by Kenneth Reitz and various contributors.
|
||||
|
||||
Development Lead
|
||||
--------
|
||||
- Kenneth Reitz <me@kennethreitz.com>
|
||||
- Kenneth Reitz <me@kennethreitz.com>
|
||||
|
||||
Patches and Suggestions
|
||||
---
|
||||
- Kracekumar <me@kracekumar.com>
|
||||
- Steven Honson
|
||||
|
||||
|
||||
|
||||
- Kracekumar <me@kracekumar.com>
|
||||
- Steven Honson
|
||||
+12
-14
@@ -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: <args ['-s', '--arch=x64', '--import', '--arch=i386']>
|
||||
$ 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: <args ['-s', '--number=one', '--alphabet', '--number=two']>
|
||||
Files detected: []
|
||||
NOT files detected: <args ['-s', 'this', 'that', '--arch=x64', '--import', 'this', 'and', 'that', 'and', 'this', 'and', 'that', '--arch=i386']>
|
||||
Grouped Arguments: OrderedDict([('_', <args []>), ('-s', <args ['this', 'that']>), ('--arch=x64', <args []>), ('--import', <args ['this', 'and', 'that', 'and', 'this', 'and', 'that']>), ('--arch=i386', <args []>)])
|
||||
Assignments detected: OrderedDict([('--arch=', <args ['x64', 'i386']>)])
|
||||
NOT files detected: <args ['-s', 'yes', 'no', '--number=one', '--alphabet', 'a', 'b', 'c', '--number=two']>
|
||||
Grouped Arguments: OrderedDict([('_', <args []>), ('-s', <args ['yes', 'no']>), ('--number=one', <args []>), ('--alphabet', <args ['a', 'b', 'c']>), ('--number=two', <args []>)])
|
||||
Assignments detected: OrderedDict([('--number', <args ['one', 'two']>)])
|
||||
|
||||
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: <args ['--test', '-s', '--arch=x64']>
|
||||
Files detected: ['args.py', 'setup.py', 'tests.py', '/home/example/.ssh/authorized_keys']
|
||||
NOT files detected: <args ['--test', 'test', 'face', 'book', '-s', '--arch=x64']>
|
||||
Grouped Arguments: OrderedDict([('_', <args ['*.py']>), ('--test', <args ['test', 'face', 'book']>), ('-s', <args ['/home/example/.ssh']>), ('--arch=x64', <args []>)])
|
||||
Assignments detected: OrderedDict([('--arch=', <args ['x64']>)])
|
||||
Arguments passed in: ['*.py', '--alphabet', 'a', 'b', 'c', '-s', '/home/example/.example', '--number=one', '--number=two']
|
||||
Flags detected: <args ['--alphabet', '-s', '--number=one', '--number=two']>
|
||||
Files detected: ['setup.py', 'args.py', 'tool.py', 'tests.py', '/home/example/.example/two', '/home/example/.example/one']
|
||||
NOT files detected: <args ['--alphabet', 'a', 'b', 'c', '-s', '--number=one', '--number=two']>
|
||||
Grouped Arguments: OrderedDict([('_', <args ['*.py']>), ('--alphabet', <args ['a', 'b', 'c']>), ('-s', <args ['/home/example/.example']>), ('--number=one', <args []>), ('--number=two', <args []>)])
|
||||
Assignments detected: OrderedDict([('--number', <args ['one', 'two']>)])
|
||||
|
||||
|
||||
Installation
|
||||
@@ -75,4 +74,3 @@ Installation
|
||||
Installation is simple with pip::
|
||||
|
||||
$ pip install args
|
||||
|
||||
|
||||
@@ -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."""
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user