|
| 1 | +import click |
| 2 | +from rich.console import Console |
| 3 | +from rich.table import Table |
| 4 | +from rich.panel import Panel |
| 5 | +from rich import print as rprint |
| 6 | +import sys |
| 7 | +import os |
| 8 | +from pathlib import Path |
| 9 | + |
| 10 | +from .commands.init import init_project |
| 11 | +from .commands.run import run_workflow |
| 12 | +from .commands.validate import validate_workflow |
| 13 | +from .commands.status import show_status |
| 14 | +from .commands.stop import stop_all |
| 15 | +from .commands.inspect import inspect_workflow |
| 16 | + |
| 17 | +console = Console() |
| 18 | + |
| 19 | +@click.group() |
| 20 | +@click.version_option(version='1.0.0', prog_name='concore') |
| 21 | +def cli(): |
| 22 | + pass |
| 23 | + |
| 24 | +@cli.command() |
| 25 | +@click.argument('name', required=True) |
| 26 | +@click.option('--template', default='basic', help='Template type to use') |
| 27 | +def init(name, template): |
| 28 | + try: |
| 29 | + init_project(name, template, console) |
| 30 | + except Exception as e: |
| 31 | + console.print(f"[red]Error:[/red] {str(e)}") |
| 32 | + sys.exit(1) |
| 33 | + |
| 34 | +@cli.command() |
| 35 | +@click.argument('workflow_file', type=click.Path(exists=True)) |
| 36 | +@click.option('--source', '-s', default='src', help='Source directory') |
| 37 | +@click.option('--output', '-o', default='out', help='Output directory') |
| 38 | +@click.option('--type', '-t', default='windows', type=click.Choice(['windows', 'posix', 'docker']), help='Execution type') |
| 39 | +@click.option('--auto-build', is_flag=True, help='Automatically run build after generation') |
| 40 | +def run(workflow_file, source, output, type, auto_build): |
| 41 | + try: |
| 42 | + run_workflow(workflow_file, source, output, type, auto_build, console) |
| 43 | + except Exception as e: |
| 44 | + console.print(f"[red]Error:[/red] {str(e)}") |
| 45 | + sys.exit(1) |
| 46 | + |
| 47 | +@cli.command() |
| 48 | +@click.argument('workflow_file', type=click.Path(exists=True)) |
| 49 | +def validate(workflow_file): |
| 50 | + try: |
| 51 | + validate_workflow(workflow_file, console) |
| 52 | + except Exception as e: |
| 53 | + console.print(f"[red]Error:[/red] {str(e)}") |
| 54 | + sys.exit(1) |
| 55 | + |
| 56 | +@cli.command() |
| 57 | +@click.argument('workflow_file', type=click.Path(exists=True)) |
| 58 | +@click.option('--json', 'output_json', is_flag=True, help='Output in JSON format') |
| 59 | +def inspect(workflow_file, output_json): |
| 60 | + try: |
| 61 | + inspect_workflow(workflow_file, console, output_json) |
| 62 | + except Exception as e: |
| 63 | + console.print(f"[red]Error:[/red] {str(e)}") |
| 64 | + sys.exit(1) |
| 65 | + |
| 66 | +@cli.command() |
| 67 | +def status(): |
| 68 | + try: |
| 69 | + show_status(console) |
| 70 | + except Exception as e: |
| 71 | + console.print(f"[red]Error:[/red] {str(e)}") |
| 72 | + sys.exit(1) |
| 73 | + |
| 74 | +@cli.command() |
| 75 | +@click.confirmation_option(prompt='Stop all running concore processes?') |
| 76 | +def stop(): |
| 77 | + try: |
| 78 | + stop_all(console) |
| 79 | + except Exception as e: |
| 80 | + console.print(f"[red]Error:[/red] {str(e)}") |
| 81 | + sys.exit(1) |
| 82 | + |
| 83 | +if __name__ == '__main__': |
| 84 | + cli() |
0 commit comments