22Midscene CLI - Command line interface for automation scripts
33"""
44
5- import asyncio
65import sys
7- from pathlib import Path
8- from typing import Optional , List
6+ from typing import Optional
97
108import typer
11- from loguru import logger
129from rich .console import Console
13- from rich .table import Table
1410
15- from .runner import ScriptRunner
1611from .config import CLIConfig
1712
1813app = typer .Typer (
@@ -30,137 +25,20 @@ def run(
3025 config_file : Optional [str ] = typer .Option (None , "--config" , "-c" , help = "Configuration file path" ),
3126 headless : bool = typer .Option (False , "--headless" , help = "Run browser in headless mode" ),
3227 device_id : Optional [str ] = typer .Option (None , "--device" , "-d" , help = "Android device ID" ),
33- concurrent : int = typer .Option (1 , "--concurrent" , help = "Number of concurrent executions" ),
34- continue_on_error : bool = typer .Option (False , "--continue-on-error" , help = "Continue on script errors" ),
35- generate_report : bool = typer .Option (True , "--report/--no-report" , help = "Generate execution report" ),
3628 verbose : bool = typer .Option (False , "--verbose" , "-v" , help = "Verbose output" ),
3729):
3830 """Run automation script(s)"""
3931
40- # Setup logging
41- log_level = "DEBUG" if verbose else "INFO"
42- logger .remove ()
43- logger .add (sys .stderr , level = log_level , format = "{time} | {level} | {message}" )
44-
45- try :
46- # Load configuration
47- config = CLIConfig .load (config_file ) if config_file else CLIConfig ()
48-
49- # Override config with CLI options
50- if headless is not None :
51- config .web .headless = headless
52- if device_id is not None :
53- config .android .device_id = device_id
54- if concurrent is not None :
55- config .execution .concurrent = concurrent
56- if continue_on_error is not None :
57- config .execution .continue_on_error = continue_on_error
58- if generate_report is not None :
59- config .execution .generate_report = generate_report
60-
61- # Create runner and execute
62- runner = ScriptRunner (config )
63-
64- # Run synchronously
65- result = asyncio .run (runner .run (script_path ))
66-
67- if result .success :
68- console .print ("✅ Execution completed successfully" , style = "green" )
69- if result .report_path :
70- console .print (f"📊 Report: { result .report_path } " )
71- else :
72- console .print ("❌ Execution failed" , style = "red" )
73- if result .error :
74- console .print (f"Error: { result .error } " , style = "red" )
75- sys .exit (1 )
76-
77- except Exception as e :
78- console .print (f"❌ CLI Error: { e } " , style = "red" )
79- if verbose :
80- logger .exception ("CLI execution failed" )
81- sys .exit (1 )
82-
83-
84- @app .command ()
85- def validate (
86- script_path : str = typer .Argument (..., help = "Path to YAML script file" ),
87- ):
88- """Validate automation script syntax"""
89-
90- try :
91- from .validator import ScriptValidator
92-
93- validator = ScriptValidator ()
94- result = validator .validate_file (script_path )
95-
96- if result .valid :
97- console .print ("✅ Script validation passed" , style = "green" )
98- else :
99- console .print ("❌ Script validation failed" , style = "red" )
100- for error in result .errors :
101- console .print (f" • { error } " , style = "red" )
102- sys .exit (1 )
103-
104- except Exception as e :
105- console .print (f"❌ Validation Error: { e } " , style = "red" )
106- sys .exit (1 )
107-
108-
109- @app .command ()
110- def devices ():
111- """List available Android devices"""
112-
113- try :
114- from ..android import AndroidDevice
115-
116- devices = asyncio .run (AndroidDevice .list_devices ())
117-
118- if not devices :
119- console .print ("No Android devices found" , style = "yellow" )
120- return
121-
122- table = Table (title = "Available Android Devices" )
123- table .add_column ("Device ID" , style = "cyan" )
124- table .add_column ("Status" , style = "green" )
125-
126- for device_id in devices :
127- table .add_row (device_id , "Connected" )
128-
129- console .print (table )
130-
131- except Exception as e :
132- console .print (f"❌ Error listing devices: { e } " , style = "red" )
133- sys .exit (1 )
134-
135-
136- @app .command ()
137- def init (
138- name : str = typer .Argument (..., help = "Project name" ),
139- template : str = typer .Option ("basic" , "--template" , "-t" , help = "Project template" ),
140- ):
141- """Initialize new automation project"""
142-
143- try :
144- from .templates import ProjectTemplate
145-
146- template_manager = ProjectTemplate ()
147- project_path = template_manager .create_project (name , template )
148-
149- console .print (f"✅ Created project: { project_path } " , style = "green" )
150- console .print (f"📝 Edit { project_path } /scripts/example.yaml to get started" )
151-
152- except Exception as e :
153- console .print (f"❌ Initialization Error: { e } " , style = "red" )
154- sys .exit (1 )
32+ console .print (f"[yellow]Script execution not yet implemented: { script_path } [/yellow]" )
33+ console .print ("[blue]This is a placeholder CLI implementation[/blue]" )
15534
15635
15736@app .command ()
15837def version ():
15938 """Show version information"""
16039
16140 try :
162- from .. import __version__
163- console .print (f"Midscene Python v{ __version__ } " )
41+ console .print ("Midscene Python v0.1.0" )
16442
16543 except Exception as e :
16644 console .print (f"❌ Error getting version: { e } " , style = "red" )
0 commit comments