Skip to content

Commit d35f5ce

Browse files
author
Saurabh Kumar
committed
try to find the .env in the current working dir
1 parent 5f181b4 commit d35f5ce

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

dotenv.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def flatten_and_write(dotenv_path, dotenv_as_dict):
118118
@click.argument('key', required=False)
119119
@click.argument('value', required=False)
120120
@click.option('--force', is_flag=True)
121-
@click.option('-f', '--file', default='.env', type=click.Path(exists=True))
121+
@click.option('-f', '--file', default=os.path.join(os.getcwd(), '.env'),
122+
type=click.Path(exists=True))
122123
def cli(file, action, key, value, force):
123124

124125
if not action:
@@ -129,7 +130,7 @@ def cli(file, action, key, value, force):
129130
if action == 'get':
130131
stored_value = get_key(file, key)
131132
if stored_value:
132-
click.echo("%s=%s" % (key, stored_value))
133+
click.echo('%s="%s"' % (key, stored_value))
133134
exit(0)
134135
else:
135136
click.echo("%s doesn't seems to have been set yet.")
@@ -141,7 +142,7 @@ def cli(file, action, key, value, force):
141142
exit(1)
142143
success, key, value = set_key(file, key, value)
143144
if success:
144-
click.echo("%s=%s" % (key, value))
145+
click.echo('%s="%s"' % (key, value))
145146
exit(0)
146147
else:
147148
exit(1)

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
flake8
2-
pytest
3-
sh
1+
flake8>=2.2.3
2+
pytest>=2.6.2
3+
sh>=1.09
Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,18 @@ def test_read_write():
1515
sh.rm(dotenv_path)
1616

1717

18-
def test_script():
18+
def test_console_script():
1919
sh.touch(dotenv_path)
2020
sh.dotenv('set', 'HELLO', 'WORLD', '-f', dotenv_path)
2121
output = sh.dotenv('get', 'HELLO', '-f', dotenv_path)
22-
assert output == 'HELLO=WORLD\n'
22+
assert output == 'HELLO="WORLD"\n'
23+
sh.rm(dotenv_path)
24+
25+
26+
def test_default_path():
27+
sh.touch(dotenv_path)
28+
sh.cd(here)
29+
sh.dotenv('set', 'HELLO', 'WORLD')
30+
output = sh.dotenv('get', 'HELLO')
31+
assert output == 'HELLO="WORLD"\n'
2332
sh.rm(dotenv_path)

0 commit comments

Comments
 (0)