Skip to content

Commit 69735cf

Browse files
venthurtheskumar
authored andcommitted
feat: add --version parameter to cli (theskumar#114)
* Added support for --version the actual version is now stored in dotenv/version.py and setup.py reads from that instead of the hardcoded variant. * Updated bumpversion.cfg to point to dotenv/version.py * Make flake8 happy
1 parent 9b3c645 commit 69735cf

File tree

5 files changed

+16
-2
lines changed

5 files changed

+16
-2
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ current_version = 0.8.2
33
commit = True
44
tag = True
55

6-
[bumpversion:file:setup.py]
6+
[bumpversion:file:dotenv/version.py]
77

dotenv/cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
sys.exit(1)
1010

1111
from .main import dotenv_values, get_key, set_key, unset_key, run_command
12+
from .version import __version__
1213

1314

1415
@click.group()
@@ -18,6 +19,7 @@
1819
@click.option('-q', '--quote', default='always',
1920
type=click.Choice(['always', 'never', 'auto']),
2021
help="Whether to quote or not the variable values. Default mode is always. This does not affect parsing.")
22+
@click.version_option(version=__version__)
2123
@click.pass_context
2224
def cli(ctx, file, quote):
2325
'''This script is used to set, get or unset values from a .env file.'''

dotenv/version.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.8.2"

setup.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,14 @@
1313
with io.open('README.md', encoding="utf-8") as f:
1414
long_description = f.read()
1515

16+
meta = {}
17+
exec(open('./dotenv/version.py').read(), meta)
18+
1619
setup(
1720
name="python-dotenv",
1821
description="Add .env support to your django/flask apps in development and deployments",
1922
long_description=long_description,
20-
version="0.8.2",
23+
version=meta['__version__'],
2124
author="Saurabh Kumar",
2225
author_email="[email protected]",
2326
url="http://github.com/theskumar/python-dotenv",

tests/test_cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from os.path import dirname, join
44

55
import dotenv
6+
from dotenv.version import __version__
67
from dotenv.cli import cli as dotenv_cli
78

89
import sh
@@ -217,3 +218,10 @@ def test_run_without_cmd(cli):
217218
def test_run_with_invalid_cmd(cli):
218219
result = cli.invoke(dotenv_cli, ['run', 'i_do_not_exist'])
219220
assert result.exit_code != 0
221+
222+
223+
def test_run_with_version(cli):
224+
result = cli.invoke(dotenv_cli, ['--version'])
225+
print(vars(result))
226+
assert result.exit_code == 0
227+
assert result.output.strip().endswith(__version__)

0 commit comments

Comments
 (0)