From d1cd0673c5bd970fad2e5f8466ff1e6e8e525339 Mon Sep 17 00:00:00 2001 From: Bertrand Bonnefoy-Claudet Date: Sun, 28 Mar 2021 17:55:18 +0200 Subject: [PATCH] Only display value with `dotenv get` The `get` subcommand would return `key=value`, which is impractical to retrieve the value of a key in a script. Since the `key` is already known by the caller, there is no point in showing it. This also makes the output consistent with the documentation for the subcommand. --- CHANGELOG.md | 4 ++++ src/dotenv/cli.py | 2 +- tests/test_cli.py | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a5b276b..8969b4c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Changed + +- Make `dotenv get ` only show the value, not `key=value` (#313 by [@bbc2]). + ### Added - Add `--override`/`--no-override` option to `dotenv run` (#312 by [@zueve] and [@bbc2]). diff --git a/src/dotenv/cli.py b/src/dotenv/cli.py index 51f25e8d..bb96c023 100644 --- a/src/dotenv/cli.py +++ b/src/dotenv/cli.py @@ -85,7 +85,7 @@ def get(ctx, key): ) stored_value = get_key(file, key) if stored_value: - click.echo('%s=%s' % (key, stored_value)) + click.echo(stored_value) else: exit(1) diff --git a/tests/test_cli.py b/tests/test_cli.py index a048ef3b..b21725ca 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -35,7 +35,7 @@ def test_get_existing_value(cli, dotenv_file): result = cli.invoke(dotenv_cli, ['--file', dotenv_file, 'get', 'a']) - assert (result.exit_code, result.output) == (0, "a=b\n") + assert (result.exit_code, result.output) == (0, "b\n") def test_get_non_existent_value(cli, dotenv_file): @@ -124,7 +124,7 @@ def test_get_default_path(tmp_path): result = sh.dotenv("get", "a") - assert result == "a=b\n" + assert result == "b\n" def test_run(tmp_path):