Skip to content

Commit

Permalink
Apply CustomParser to env arg parsing. Fixes #14.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Dec 20, 2023
1 parent 1fcc486 commit 518c139
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmdix/command/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


def parseargs(p):
p.__class__ = CustomParser
p.set_defaults(func=func)
p.description = "Set each NAME to VALUE in the environment and run " + "COMMAND."
p.usage = '%(prog)s [OPTION]... [-] [NAME=VALUE]... [COMMAND [ARG]...]'
Expand Down
16 changes: 15 additions & 1 deletion tests/test_env.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
import subprocess
import sys

import pytest

from . import BaseTestCase


class TestCase(BaseTestCase):
@pytest.mark.xfail('platform.system() == "Windows"')
def test_env(self, capfd):
def test_env_dash_i(self, capfd):
self.runcommandline('env -i FOO=bar env')
assert capfd.readouterr().out == 'FOO=bar\n'

@pytest.mark.xfail('platform.system() == "Windows"')
def test_dash_as_dash_i(self, capfd):
self.runcommandline('env - FOO=bar env')
assert capfd.readouterr().out == 'FOO=bar\n'

def test_env_simple(self, capfd):
self.runcommandline('env')
assert capfd.readouterr().out

def test_command_opts(self, capfd):
# invoke Python's help (not env's help)
cmd = ['env', sys.executable, '--help']
self.runcommandline(subprocess.list2cmdline(cmd))
assert "-m mod" in capfd.readouterr().out

0 comments on commit 518c139

Please sign in to comment.