Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit f90c1a5

Browse files
authored
Merge pull request #119 from msabramo/env_regex
Allow regex pattern for environment name
2 parents 0259ee5 + 723b554 commit f90c1a5

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

docs/usingsupernova.md

+10
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ You can also use a comma-separated list of environment names:
3838
supernova iad,dfw,ord list
3939
```
4040

41+
You can use a regular expression for the environment if you enclose it
42+
in slashes:
43+
44+
```html
45+
supernova /^rax/ list
46+
```
47+
48+
The above command will execute `nova list` for every environment whose
49+
name starts with `rax`.
50+
4151
You can use supernova with long-running options and the output will be piped live to your terminal. For example, you can use `--poll` when you boot an instance and you'll see the novaclient output update as your instance is being built.
4252

4353
For debug output, supernova accepts `--debug` as a supernova option or as a novaclient option. Both of these are okay:

supernova/executable.py

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Contains the functions needed for supernova and supernova-keyring commands
1818
to run
1919
"""
20+
import re
2021
import sys
2122
import webbrowser
2223

@@ -177,6 +178,9 @@ def run_supernova(ctx, executable, debug, quiet, environment, command, conf,
177178
envs.extend(utils.get_envs_in_group(env, nova_creds))
178179
else:
179180
envs.append(env)
181+
elif environment.startswith('/') and environment.endswith('/'):
182+
envs = [nova_env for nova_env in nova_creds.keys()
183+
if re.search(environment[1:-1], nova_env)]
180184
else:
181185
envs = [environment]
182186

tests/test_executable.py

+13
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,19 @@ def mockreturn(nova_creds, nova_args, supernova_args):
155155
result = runner.invoke(executable.run_supernova, command)
156156
assert result.exit_code == 0
157157

158+
def test_env_regex(self, monkeypatch):
159+
envs = []
160+
161+
def mockreturn(nova_creds, nova_args, supernova_args):
162+
envs.append(supernova_args['nova_env'])
163+
return 0
164+
monkeypatch.setattr(supernova, "run_command", mockreturn)
165+
runner = CliRunner()
166+
command = ['/^s/', 'list']
167+
result = runner.invoke(executable.run_supernova, command)
168+
assert result.exit_code == 0
169+
assert envs == ['syd', 'someinova']
170+
158171
def test_broken_configuration_file(self):
159172
runner = CliRunner()
160173
command = ['-c', 'tests/configs/rax_without_keyring_malformed', 'dfw',

0 commit comments

Comments
 (0)