Skip to content

Commit cc91bf2

Browse files
author
Saurabh Kumar
committed
Fix fab command usages along with get_cli_string helper
closes theskumar#14
1 parent 563c124 commit cc91bf2

3 files changed

Lines changed: 19 additions & 16 deletions

File tree

README.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,16 @@ server.
139139
env.dotenv_path = '/opt/myapp/.env'
140140
141141
@task
142-
def config(action=None, key_value=None):
142+
def config(action=None, key=None, value=None):
143143
'''Manage project configuration via .env
144144
145-
e.g: fab config:set,<key>=<value>
145+
e.g: fab config:set,<key>,<value>
146146
fab config:get,<key>
147147
fab config:unset,<key>
148148
fab config:list
149149
'''
150150
run('touch %(dotenv_path)s' % env)
151-
command = dotenv.get_cli_string(env.dotenv_path, action, key_value)
151+
command = dotenv.get_cli_string(env.dotenv_path, action, key, value)
152152
run(command)
153153
154154
Usage is designed to mirror the heroku config api very closely.
@@ -159,11 +159,11 @@ Get all your remote config info with ``fab config``
159159

160160
$ fab config
161161

162-
Set remote config variables with ``fab config:set,<key>=<value>``
162+
Set remote config variables with ``fab config:set,<key>,<value>``
163163

164164
::
165165

166-
$ fab config:set,hello=world
166+
$ fab config:set,hello,world
167167

168168
Get a single remote config variables with ``fab config:get,<key>``
169169

@@ -178,11 +178,11 @@ Delete a remote config variables with ``fab config:unset,<key>``
178178
$ fab config:unset,hello
179179

180180
Thanks entirely to fabric and not one bit to this project, you can chain
181-
commands like so ``fab config:set,<key1>=<value1> config:set,<key2>=<value2>``
181+
commands like so ``fab config:set,<key1>,<value1> config:set,<key2>,<value2>``
182182

183183
::
184184

185-
$ fab config:set,hello=world config:set,foo=bar config:set,fizz=buzz
185+
$ fab config:set,hello,world config:set,foo,bar config:set,fizz=buzz
186186

187187

188188
Releated Projects

dotenv.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def unset(ctx, key):
168168
exit(1)
169169

170170

171-
def get_cli_string(path=None, action=None, key_value=None):
171+
def get_cli_string(path=None, action=None, key=None, value=None):
172172
"""Returns a string suitable for running as a shell script.
173173
174174
Useful for converting a arguments passed to a fabric task
@@ -179,11 +179,13 @@ def get_cli_string(path=None, action=None, key_value=None):
179179
command.append('-f %s' % path)
180180
if action:
181181
command.append(action)
182-
if key_value:
183-
if '=' in key_value:
184-
command += key_value.split('=', 1)
185-
else:
186-
command.append(key_value)
182+
if key:
183+
command.append(key)
184+
if value:
185+
if ' ' in value:
186+
command.append('"%s"' % value)
187+
else:
188+
command.append(value)
187189

188190
return ' '.join(command).strip()
189191

tests/test_utils.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def test_to_cli_string():
66
assert c(path='/etc/.env') == 'dotenv -f /etc/.env'
77
assert c(path='/etc/.env', action='list') == 'dotenv -f /etc/.env list'
88
assert c(action='list') == 'dotenv list'
9-
assert c(action='get', key_value='DEBUG') == 'dotenv get DEBUG'
10-
assert c(action='set', key_value='DEBUG=True') == 'dotenv set DEBUG True'
11-
assert c(action='set', key_value='SECRET==@asdfasf') == 'dotenv set SECRET =@asdfasf'
9+
assert c(action='get', key='DEBUG') == 'dotenv get DEBUG'
10+
assert c(action='set', key='DEBUG', value='True') == 'dotenv set DEBUG True'
11+
assert c(action='set', key='SECRET', value='=@asdfasf') == 'dotenv set SECRET =@asdfasf'
12+
assert c(action='set', key='SECRET', value='a b') == 'dotenv set SECRET "a b"'

0 commit comments

Comments
 (0)