Skip to content

Commit

Permalink
Merge 26d4a29 into 088d2ba
Browse files Browse the repository at this point in the history
  • Loading branch information
barpod committed Jun 7, 2018
2 parents 088d2ba + 26d4a29 commit e205d48
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
10 changes: 10 additions & 0 deletions doit/doit_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@ def run(self, cmd_args):
# get "global vars" from cmd-line
args = self.process_args(cmd_args)

# move -k and -f args to the and of args list so cmd name can be
# used after them
if len(args) > 0 and (args[0] == "-k" or args[0] == "--seek-file"):
args.append(args.pop(0))
if len(args) > 0 and (args[0].startswith("--file=")):
args.append(args.pop(0))
if len(args) > 1 and (args[0] == "-f"):
args.append(args.pop(0))
args.append(args.pop(0))

# get specified sub-command or use default='run'
if len(args) == 0 or args[0] not in sub_cmds:
specified_run = False
Expand Down
22 changes: 22 additions & 0 deletions tests/test_doit_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,29 @@ def monkey_run(self, opt_values, pos_args):
doit_cmd.DoitMain(extra_config={'GLOBAL': extra_config}).run([])
assert outfile_val[0] == 'foo.txt'

def test_cmdline_option_k_position(self, monkeypatch):
mock_list = Mock()
monkeypatch.setattr(List, "execute", mock_list)
cmd_main(['-k', 'list'])
assert 1 == mock_list.call_count

def test_cmdline_option_seek_file_position(self, monkeypatch):
mock_list = Mock()
monkeypatch.setattr(List, "execute", mock_list)
cmd_main(['--seek-file', 'list'])
assert 1 == mock_list.call_count

def test_cmdline_option_f_position(self, monkeypatch):
mock_list = Mock()
monkeypatch.setattr(List, "execute", mock_list)
cmd_main(['-f', 'filename', 'list'])
assert 1 == mock_list.call_count

def test_cmdline_option_file_position(self, monkeypatch):
mock_list = Mock()
monkeypatch.setattr(List, "execute", mock_list)
cmd_main(['--file=filename', 'list'])
assert 1 == mock_list.call_count

class TestErrors(object):
def test_interrupt(self, monkeypatch):
Expand Down

0 comments on commit e205d48

Please sign in to comment.