From 07d166ac3bb65a3e0f68325782f4b4693413ee26 Mon Sep 17 00:00:00 2001 From: Glen Smith Date: Fri, 28 Aug 2020 12:08:58 -0600 Subject: [PATCH] Add a `scripts` command and a test for it. - https://github.com/pypa/pipenv/issues/3686 --- pipenv/cli/command.py | 20 ++++++++++++++++++++ tests/integration/test_cli.py | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/pipenv/cli/command.py b/pipenv/cli/command.py index 6b9c339226..eaf024a622 100644 --- a/pipenv/cli/command.py +++ b/pipenv/cli/command.py @@ -716,5 +716,25 @@ def clean(ctx, state, dry_run=False, bare=False, user=False): system=state.system) +@cli.command( + short_help="Lists scripts in current environment config.", + context_settings=subcommand_context_no_interspersion, +) +@common_options +@argument("args", nargs=-1) +@pass_state +def scripts(state, args): + """Lists scripts in current environment config.""" + from ..core import project + if not project: + print("project not found") + exit(1) + scripts = project.parsed_pipfile.get('scripts', []) + print("command\tscript") + for k, v in scripts.items(): + print(f"{k}\t{v}") + return + + if __name__ == "__main__": cli() diff --git a/tests/integration/test_cli.py b/tests/integration/test_cli.py index 04253fc5de..94d5b0dd4d 100644 --- a/tests/integration/test_cli.py +++ b/tests/integration/test_cli.py @@ -197,6 +197,19 @@ def test_bare_output(PipenvInstance): assert p.pipenv('').out +@pytest.mark.cli +def test_scripts(PipenvInstance): + with PipenvInstance() as p: + with open(p.pipfile_path, "w") as f: + contents = """ +[scripts] +pyver = "which python" + """.strip() + f.write(contents) + c = p.pipenv('scripts') + assert 'pyver' in c.out + + @pytest.mark.cli def test_help(PipenvInstance): with PipenvInstance() as p: