Skip to content

Commit

Permalink
Only display value with dotenv get
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bbc2 committed Mar 28, 2021
1 parent f2eba2c commit 5470217
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -7,6 +7,10 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed

- Make `dotenv get <key>` only show the value, not `key=value` (#313 by [@bbc2]).

### Added

- Add `--override`/`--no-override` option to `dotenv run` (#312 by [@zueve] and [@bbc2]).
Expand Down
2 changes: 1 addition & 1 deletion src/dotenv/cli.py
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 5470217

Please sign in to comment.