Skip to content

Commit

Permalink
v2.0.0
Browse files Browse the repository at this point in the history
=====================================================================

Subscwrypts + Environment Inheritance

--- Release Notes ------------------------

- added support for environment inheritance
- added support for arbitrarily nested scripts (subscwrypts)
- added support for CI mode

- improved modularity of zsh/utils module

- refactored to move some data from ~/.config/scwrypts to ~/.local/share/scwrypts

- refactored various scripts to use new subscwrypt api

--- New Scripts --------------------------

zsh )
  - db/interactive/postgres
  - aws/rds/interactive-login
  • Loading branch information
wrynegade committed Jul 2, 2022
1 parent 2dcf941 commit eaefc99
Show file tree
Hide file tree
Showing 34 changed files with 740 additions and 230 deletions.
Binary file modified .config
Binary file not shown.
File renamed without changes.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.zsh diff
.config diff
15 changes: 11 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@ Check out [Meta Scwrypts](./zsh/scwrypts) to quickly set up environments and adj
### No Install / API Usage
Alternatively, the `scwrypts` API can be used directly:
```zsh
./scwrypts (environment-name) (...script-patterns)
./scwrypts [--env environment-name] (...script-name-patterns...) [-- ...passthrough arguments... ]
```

If not already set with `$SCWRYPTS_ENV`, Scwrypts will try to load `$1` as an environment.
If no environment with the name `$1` is found, `$1` is assumed to be a script pattern.

Given one or more script patterns, Scwrypts will filter the commands by pattern conjunction.
If only one command is found which matches the pattern(s), it will immediately begin execution.
If multiple commands match, the user will be prompted to select from the filtered list.
Expand All @@ -44,6 +41,16 @@ Given no script patterns, Scwrypts becomes an interactive CLI, prompting the use
After determining which script to run, if no environment has been specified, Scwrypts prompts the user to choose one.


### Using in CI/CD or Automated Workflows
Set environment variable `CI=true` (and use the no install method) to run in an automated pipeline.
There are a few notable changes to this runtime:
- **The Scwrypts sandbox environment will not load.** All variables will be read from context.
- The underscore-prefixed `_AWS_(PROFILE|REGION|ACCOUNT)` variables will be read from the standard `AWS_` variables
- User yes/no prompts will **always be YES**
- Other user input will default to an empty string
- Logs will not be captured


## Contributing

Before contributing an issue, idea, or pull request, check out the [super-brief contributing guide](./docs/CONTRIBUTING.md)
1 change: 0 additions & 1 deletion py/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
__pycache__/
*.py[cod]
*.so
.env/
7 changes: 3 additions & 4 deletions py/redis/interactive.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/usr/bin/env python
from os import getenv

from py.redis.client import Client
from py.scwrypts import interactive
from py.scwrypts import interactive, getenv


@interactive
def main():
r = Client

print('''
r = StrictRedis("{getenv("REDIS_HOST")}")
print(f'''
>>> r = StrictRedis({getenv("REDIS_HOST")}:{getenv("REDIS_PORT")})
''')

return locals()
Expand Down
1 change: 1 addition & 0 deletions py/scwrypts/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from py.scwrypts.getenv import getenv
from py.scwrypts.interactive import interactive
from py.scwrypts.run import run
15 changes: 4 additions & 11 deletions py/scwrypts/getenv.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
from os import getenv as os_getenv
from pathlib import Path
from subprocess import run

from py.scwrypts.exceptions import MissingVariableError
from py.scwrypts.run import run


def getenv(name, required=True):
value = os_getenv(name, None)

if value == None:
ZSH_COMMAND = Path(__file__).parents[2] / 'zsh/scwrypts/environment/stage-variables'
run('zsh/scwrypts/environment/stage-variables', name)

run(
f'{ZSH_COMMAND} {name}',
shell=True,
executable='/bin/zsh',
)

if required:
raise MissingVariableError(name)
if required and not value:
raise MissingVariableError(name)

return value
2 changes: 2 additions & 0 deletions py/scwrypts/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

def interactive(function):
def main(*args, **kwargs):
print('preparing interactive environment...')
local_vars = function(*args, **kwargs)
print('environment ready; user, GO! :)')
embed(local_vars)

return main
17 changes: 17 additions & 0 deletions py/scwrypts/run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from os import getenv
from pathlib import Path
from subprocess import run as subprocess_run


def run(scwrypt_name, *args):
DEPTH = int(getenv('SUBSCWRYPT', '0'))
DEPTH += 1

print(f'\n {"--"*DEPTH} ({DEPTH}) BEGIN SUBSCWRYPT : {Path(scwrypt_name).name}')
subprocess_run(
f'SUBSCWRYPT={DEPTH} {Path(__file__).parents[2] / "scwrypts"} {scwrypt_name} -- {" ".join([str(x) for x in args])}',
shell=True,
executable='/bin/zsh',
)

print(f' {"--"*DEPTH} ({DEPTH}) END SUBSCWRYPT : {Path(scwrypt_name).name}\n')
Loading

0 comments on commit eaefc99

Please sign in to comment.