diff --git a/cli/__pycache__/controller.cpython-36.pyc b/cli/__pycache__/controller.cpython-36.pyc new file mode 100644 index 00000000..d29f462f Binary files /dev/null and b/cli/__pycache__/controller.cpython-36.pyc differ diff --git a/cli/__pycache__/model.cpython-36.pyc b/cli/__pycache__/model.cpython-36.pyc new file mode 100644 index 00000000..3642d67c Binary files /dev/null and b/cli/__pycache__/model.cpython-36.pyc differ diff --git a/cli/controller.py b/cli/controller.py index 184ca964..b0176355 100644 --- a/cli/controller.py +++ b/cli/controller.py @@ -104,6 +104,40 @@ class Create: pass -class Manage(model.DockerComposeOp): - pass +class Status: + + '''The status operation of project, e.g Start | Stop | Restart | Erase''' + + def __init__(self, project_name: str, project_path: Optional[str] = None): + + self.project_name = project_name + self.project_path = project_path + self.dockerop = model.DockerOp() + + projectdict = self.dockerop.getProject() + + if self.project_path == None: + try: + self.project_path = projectdict[self.project_name] + self.dockercomposeop = model.DockerComposeOp(self.project_path) + except: + print("No this application!") + sys.exit(0) + def stopApp(self): + pass + + def upApp(self): + pass + + def startApp(self): + pass + + def retartApp(self): + pass + + def eraseApp(self): + self.dockercomposeop.down() + + def upApp(self): + self.dockercomposeop.up(self.project_path) \ No newline at end of file diff --git a/cli/model.py b/cli/model.py index 0f0d3567..7df67cf4 100644 --- a/cli/model.py +++ b/cli/model.py @@ -115,7 +115,7 @@ class SecurityOp: class DockerComposeOp: '''Docker Compose operation''' - def __int__(self, path: Optional[str] = ""): + def __init__(self, path: Optional[str] = ''): self.cmd_up = "docker-compose up -d" self.cmd_stop = "docker-compose stop" @@ -125,22 +125,22 @@ class DockerComposeOp: try: os.chdir(self.path) except: - print("No found project directory") + print("Not found project directory") sys.exit(0) def up(self): '''docker-compose up''' try: - os.system(cmd_up) + os.system(self.cmd_up) except: print("Create failed") - os.system(cmd_up) + os.system(self.cmd_up) sys.exit(0) def stop(self): '''docker-compose stop''' try: - os.system(cmd_stop) + os.system(self.cmd_stop) except: print("Stop failed, suggest try it again") sys.exit(0) @@ -148,7 +148,7 @@ class DockerComposeOp: def down(self): '''docker-compose down''' try: - os.system(cmd_down) + os.system(self.cmd_down) except: print("Down failed, suggest try it again") sys.exit(0) diff --git a/cli/stackhub.py b/cli/stackhub.py index 67d5e5de..a028d887 100644 --- a/cli/stackhub.py +++ b/cli/stackhub.py @@ -22,16 +22,41 @@ def create(app_name: str, project_name: Optional[str] = None): create.setEnv() create.upRepo() create.printResult() - -@app.command() -def start(app_name: str, project_name: Optional[str] = None): - '''start one application''' - pass @app.command() -def update(name: str): +def up(path: str): + '''up one deleted application''' + status = controller.Status("application", path) + status.startApp() + +@app.command() +def start(project_name: str): + '''start one stopped application''' + status = controller.Status(project_name) + status.startApp() + +@app.command() +def stop(project_name: str): + '''start one running application''' + status = controller.Status(project_name) + status.stopApp() + +@app.command() +def restart(project_name: str): + '''Restart one application''' + status = controller.Status(project_name) + status.retartApp() + +@app.command() +def erase(project_name: str): + '''erase or delete an application''' + status = controller.Status(project_name) + status.eraseApp() + +@app.command() +def update(project_name: str): '''update the local lists cache''' - typer.echo(f"Hello {name}") + typer.echo(f"Hello {project_name}") @app.command()