Skip to content

Commit

Permalink
CLI Boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
pfnsec committed Jun 16, 2020
1 parent 8c2e790 commit 5d16e63
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
22 changes: 21 additions & 1 deletion batik/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
Usage:
batik hello
batik auth
batik init
batik deploy
batik undeploy <deployId>
batik publish
batik login [create]
batik hub [add]
batik hub [list]
batik hub [search <query>]
batik hub [upload <packageId>]
batik hub [download <packageId>]
batik hub [delete <packageId>]
batik deployments
batik clusters
batik publish
batik offline
batik install
batik run -p <payload.yaml>
batik -h | --help
batik --version
Expand All @@ -24,18 +42,20 @@

from . import __version__ as VERSION


def main():
"""Main CLI entrypoint."""
import batik.commands
options = docopt(__doc__, version=VERSION)

# Here we'll try to dynamically match the command the user is trying to run
# with a pre-defined command class we've already created.

for (k, v) in options.items():
if hasattr(batik.commands, k) and v:
module = getattr(batik.commands, k)

batik.commands = getmembers(module, isclass)

command = [command[1] for command in batik.commands if command[0] != 'Base'][0]
command = command(options)
command.run()
18 changes: 18 additions & 0 deletions batik/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

import os
import yaml

batik_env = {}
env = batik_env.get

def set_env_file(file):
with open(file, 'r') as stream:
try:
batik_env = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)


# TODO eventually check other paths?
if(os.path.exists("./batik.env.yaml")):
set_env_file("./batik.env.yaml")
10 changes: 9 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,15 @@ def run(self):
],
keywords = 'cli',
packages = find_packages(exclude=['docs', 'tests*']),
install_requires = ['docopt'],
install_requires = [
'docopt',
'requests',
'qrcode',
'docker',
'pyyaml',
'gitignore-parser',
'pycryptodome',
],
extras_require = {
'test': ['coverage', 'pytest', 'pytest-cov'],
},
Expand Down

0 comments on commit 5d16e63

Please sign in to comment.