refactor: migrate from class commands to scripts commands
This commit is contained in:
+18
-70
@@ -1,84 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import locale
|
||||
from argparse import Namespace
|
||||
from typing import Optional
|
||||
import typer
|
||||
|
||||
from git_flow import GitFlowError
|
||||
from git_flow.command.base import Command
|
||||
from git_flow.command.branch import BranchCommand
|
||||
from git_flow.command.commit import CommitCommand
|
||||
from git_flow.command.init import InitCommand
|
||||
from git_flow.command.merge import MergeCommand
|
||||
from git_flow.command.new import NewCommand
|
||||
from git_flow.command.release import ReleaseCommand
|
||||
from git_flow.command.tag import TagCommand
|
||||
from git_flow.io import *
|
||||
|
||||
from git_flow.command.base import *
|
||||
from git_flow.command import init, new, commit, merge, tag, release, branch
|
||||
|
||||
REPOSITORY_TOKEN_PATH = ".repository-token"
|
||||
LOCALE = "es_AR.UTF-8"
|
||||
|
||||
|
||||
app = typer.Typer()
|
||||
|
||||
|
||||
@app.command()
|
||||
def init():
|
||||
run(InitCommand())
|
||||
|
||||
|
||||
@app.command()
|
||||
def new():
|
||||
run(NewCommand())
|
||||
|
||||
|
||||
@app.command()
|
||||
def commit():
|
||||
run(CommitCommand())
|
||||
|
||||
|
||||
@app.command()
|
||||
def merge():
|
||||
run(MergeCommand())
|
||||
|
||||
|
||||
@app.command()
|
||||
def tag(token: Optional[str] = None):
|
||||
run(TagCommand(), Namespace(token = token))
|
||||
|
||||
|
||||
@app.command()
|
||||
def release(group: Optional[str] = None):
|
||||
run(ReleaseCommand(), Namespace(group = group))
|
||||
|
||||
|
||||
@app.command()
|
||||
def branch(env: Optional[str] = None, trash: bool = False, wip: bool = False, all: bool = False):
|
||||
args = Namespace(
|
||||
environment = env,
|
||||
trash = trash,
|
||||
wip = wip,
|
||||
all = all,
|
||||
)
|
||||
|
||||
run(BranchCommand(), args)
|
||||
|
||||
|
||||
def run(command: Command, args: Namespace = Namespace()):
|
||||
command.init()
|
||||
|
||||
try:
|
||||
command.run(args)
|
||||
except GitFlowError as e:
|
||||
command.error(str(e))
|
||||
except Exception as e:
|
||||
command.error("Ocurrió un error inesperado: " + str(e))
|
||||
except KeyboardInterrupt as e:
|
||||
print()
|
||||
command.error("Ejecución abortada")
|
||||
app.add_typer(init.app)
|
||||
app.add_typer(new.app)
|
||||
app.add_typer(commit.app)
|
||||
app.add_typer(merge.app)
|
||||
app.add_typer(tag.app)
|
||||
app.add_typer(release.app)
|
||||
app.add_typer(branch.app)
|
||||
|
||||
|
||||
def main():
|
||||
app()
|
||||
try:
|
||||
app()
|
||||
except GitFlowError as e:
|
||||
error(str(e))
|
||||
except Exception as e:
|
||||
error("Ocurrió un error inesperado: " + str(e))
|
||||
except KeyboardInterrupt as e:
|
||||
print()
|
||||
error("Ejecución abortada")
|
||||
|
||||
Reference in New Issue
Block a user