Skip to content

Commit

Permalink
Merge pull request #13 from aitomatic/feat/change_command_syntax
Browse files Browse the repository at this point in the history
change CLI syntax to aito <verb> <noun>
  • Loading branch information
phamhoangtuan committed Apr 26, 2022
2 parents de8c362 + 92c1a28 commit a97ee81
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 33 deletions.
File renamed without changes.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ Both the above commands would install the package globally and `aito` will be av
## How to use

- `aito login`: Login to Aitomatic cloud
- `aito app deploy`: Deploy app to Aitomatic cluster
- `aito app execute <app_name>`: Execute app in Aitomatic cluster
- `aito deploy app <app_name>`: Deploy app to Aitomatic cluster
- `aito execute app <app_name>`: Execute app in Aitomatic cluster

## Feedback

Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ classifiers =
[options]
packages =
src
src.app
src.deploy
src.execute
src.login
src.api
install_requires =
Expand Down
7 changes: 4 additions & 3 deletions src/aito.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import click
import json
from pathlib import Path
from src.app.main import app
from src.execute.main import execute
from src.deploy.main import deploy
from src.login.main import login, CREDENTIAL_FILE


Expand All @@ -23,7 +23,8 @@ def cli():


cli.add_command(login)
cli.add_command(app)
cli.add_command(execute)
cli.add_command(deploy)


if __name__ == '__main__':
Expand Down
10 changes: 5 additions & 5 deletions src/api/aitomatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def __init__(self, token):
'http://a1adce51c15d34971924a8c7bb9feafd-904302004.us-west-2.elb.amazonaws.com',
)

def deploy(self, app_id, data):
def deploy(self, app_name, data):
res = requests.post(
url=f"{self.API_BASE}/app/{app_id}/deploy",
url=f"{self.API_BASE}/app/{app_name}/deploy",
data=data,
headers={
'content-type': 'application/x-www-form-urlencoded',
Expand All @@ -22,14 +22,14 @@ def deploy(self, app_id, data):

return res

def execute(self, app_id, data):
def execute(self, app_name, data):
res = requests.post(
url=f"{self.API_BASE}/app/{app_id}/execute",
url=f"{self.API_BASE}/app/{app_name}/execute",
data=data,
headers={
'content-type': 'application/x-www-form-urlencoded',
'Authorization': f'Bearer {self.token}',
},
)

return res
return res
12 changes: 0 additions & 12 deletions src/app/main.py

This file was deleted.

10 changes: 5 additions & 5 deletions src/app/deploy.py → src/deploy/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@


@click.command()
@click.argument('app_name', type=str)
@click.pass_obj
@authenticated
def deploy(obj):
def app(obj, app_name):
'''Deploy app to Aitomatic cluster'''

click.echo('Deploy app to Aitomatic...')
app_id = 'fish-finder' # get the app id somehow
click.echo(f'Deploying app {app_name} to Aitomatic...')

api = AiCloudApi(token=obj.get("access_token"))
res = api.deploy(app_id=app_id, data={"foo": "bar"})
res = api.deploy(app_name=app_name, data={"foo": "bar"})

data = res.json()

click.echo(f'App deployed successfully. Open {data["url"]}')
click.echo(f'App {app_name} deployed successfully. Open {data["url"]}')

# TODO launch the app in browser
# click.launch(data["url"])
Expand Down
10 changes: 10 additions & 0 deletions src/deploy/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import click
from src.deploy.app import app


@click.group()
def deploy():
'''Deploy app/project to Aitomatic cluster'''


deploy.add_command(app)
8 changes: 4 additions & 4 deletions src/app/execute.py → src/execute/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
@click.argument('app_name', type=str)
@click.pass_obj
@authenticated
def execute(obj, app_name):
'''Execute app in Aitomatic cluster'''
def app(obj, app_name):
'''Execute an app deployed in Aitomatic cluster'''

click.echo(f'Execute {app_name} app in Aitomatic...')
click.echo(f'Executing app {app_name} in Aitomatic...')

api = AiCloudApi(token=obj.get("access_token"))
res = api.execute(app_id=app_name, data={"foo": "bar"})
res = api.execute(app_name=app_name, data={"foo": "bar"})

data = res.json()
if data['status'] == 'OK':
Expand Down
10 changes: 10 additions & 0 deletions src/execute/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import click
from src.execute.app import app


@click.group()
def execute():
'''Execute app/project deployed in Aitomatic cluster'''


execute.add_command(app)
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.5.0
0.6.0

0 comments on commit a97ee81

Please sign in to comment.