Skip to content

Commit

Permalink
add -x/--ignore-missing option to allow ignoring missing files in any…
Browse files Browse the repository at this point in the history
…config_cli, and a corresponding test case
  • Loading branch information
ssato committed Oct 13, 2014
1 parent 54c55ba commit f4fe420
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions anyconfig/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def option_parser(defaults=None, usage=USAGE):
:param usage: Usage text
"""
defaults = dict(loglevel=1, list=False, output=None, itype=None,
otype=None, atype=None, merge=A.MS_DICTS)
otype=None, atype=None, merge=A.MS_DICTS,
ignore_missing=False)

ctypes = A.list_types()
ctypes_s = ", ".join(ctypes)
Expand Down Expand Up @@ -109,6 +110,9 @@ def option_parser(defaults=None, usage=USAGE):
parser.add_option("", "--get", help=get_help)
parser.add_option("", "--set", help=set_help)

parser.add_option("-x", "--ignore-missing", action="store_true",
help="Ignore missing input files")

parser.add_option("-s", "--silent", action="store_const", dest="loglevel",
const=0, help="Silent or quiet mode")
parser.add_option("-q", "--quiet", action="store_const", dest="loglevel",
Expand Down Expand Up @@ -138,7 +142,8 @@ def main(argv=sys.argv):
parser.print_usage()
sys.exit(-1)

data = A.load(args, options.itype, options.merge)
data = A.load(args, options.itype, options.merge,
ignore_missing=options.ignore_missing)

if options.args:
diff = A.loads(options.args, options.atype)
Expand Down
8 changes: 8 additions & 0 deletions anyconfig/tests/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ def test_34_single_input_w_set_option(self):
x = A.load(output)
self.assertEquals(x, ref)

def test_36_single_input__ignore_missing(self):
# null_cntnr = A.container()
input = os.path.join(os.curdir, "conf_file_should_not_exist.json")
assert not os.path.exists(input)

T.main(["dummy", "-O", "json", "--ignore-missing",
input])

def test_40_multiple_inputs(self):
xs = [dict(a=1, ),
dict(b=dict(b=[1, 2], c="C")), ]
Expand Down

0 comments on commit f4fe420

Please sign in to comment.