@@ -3,7 +3,7 @@ use clap::{Parser, Subcommand};
33use crate :: client:: CovalClient ;
44use crate :: commands;
55use crate :: config:: Config ;
6- use crate :: output:: OutputFormat ;
6+ use crate :: output:: { OutputContext , OutputFormat } ;
77
88#[ derive( Parser ) ]
99#[ command( name = "coval" ) ]
@@ -21,6 +21,9 @@ pub struct Cli {
2121
2222 #[ arg( long, global = true , env = "COVAL_API_URL" ) ]
2323 pub api_url : Option < String > ,
24+
25+ #[ arg( long, global = true ) ]
26+ pub agent : bool ,
2427}
2528
2629#[ derive( Subcommand ) ]
@@ -100,18 +103,68 @@ pub enum Commands {
100103 } ,
101104}
102105
103- pub async fn run ( cli : Cli ) -> anyhow:: Result < ( ) > {
106+ impl Commands {
107+ pub fn resource ( & self ) -> & ' static str {
108+ match self {
109+ Self :: Login ( _) | Self :: Whoami => "auth" ,
110+ Self :: Config { .. } => "config" ,
111+ Self :: Agents { .. } => "agents" ,
112+ Self :: Conversations { .. } => "conversations" ,
113+ Self :: Runs { .. } => "runs" ,
114+ Self :: Simulations { .. } => "simulations" ,
115+ Self :: TestSets { .. } => "test-sets" ,
116+ Self :: TestCases { .. } => "test-cases" ,
117+ Self :: Personas { .. } => "personas" ,
118+ Self :: Metrics { .. } => "metrics" ,
119+ Self :: Mutations { .. } => "mutations" ,
120+ Self :: ApiKeys { .. } => "api-keys" ,
121+ Self :: RunTemplates { .. } => "run-templates" ,
122+ Self :: ScheduledRuns { .. } => "scheduled-runs" ,
123+ Self :: Dashboards { command } => match command {
124+ commands:: dashboards:: DashboardCommands :: Widgets { .. } => "widgets" ,
125+ _ => "dashboards" ,
126+ } ,
127+ Self :: ReviewAnnotations { .. } => "review-annotations" ,
128+ Self :: ReviewProjects { .. } => "review-projects" ,
129+ }
130+ }
131+
132+ pub fn operation ( & self ) -> & ' static str {
133+ match self {
134+ Self :: Login ( _) => "login" ,
135+ Self :: Whoami => "whoami" ,
136+ Self :: Config { command } => command. operation ( ) ,
137+ Self :: Agents { command } => command. operation ( ) ,
138+ Self :: Conversations { command } => command. operation ( ) ,
139+ Self :: Runs { command } => command. operation ( ) ,
140+ Self :: Simulations { command } => command. operation ( ) ,
141+ Self :: TestSets { command } => command. operation ( ) ,
142+ Self :: TestCases { command } => command. operation ( ) ,
143+ Self :: Personas { command } => command. operation ( ) ,
144+ Self :: Metrics { command } => command. operation ( ) ,
145+ Self :: Mutations { command } => command. operation ( ) ,
146+ Self :: ApiKeys { command } => command. operation ( ) ,
147+ Self :: RunTemplates { command } => command. operation ( ) ,
148+ Self :: ScheduledRuns { command } => command. operation ( ) ,
149+ Self :: Dashboards { command } => command. operation ( ) ,
150+ Self :: ReviewAnnotations { command } => command. operation ( ) ,
151+ Self :: ReviewProjects { command } => command. operation ( ) ,
152+ }
153+ }
154+ }
155+
156+ pub async fn run ( cli : Cli , ctx : & OutputContext ) -> anyhow:: Result < ( ) > {
104157 let config = Config :: load ( ) . unwrap_or_default ( ) ;
105158 let api_key = cli. api_key . or ( config. api_key ) ;
106159 let api_url = cli. api_url . or ( config. api_url ) ;
107160
108161 match cli. command {
109- Commands :: Login ( args) => commands:: auth:: login ( args) . await ,
162+ Commands :: Login ( args) => commands:: auth:: login ( args, ctx ) . await ,
110163 Commands :: Whoami => {
111- commands:: auth:: whoami ( api_key. as_ref ( ) ) ;
164+ commands:: auth:: whoami ( api_key. as_ref ( ) , ctx ) ;
112165 Ok ( ( ) )
113166 }
114- Commands :: Config { command } => commands:: config:: execute ( command) ,
167+ Commands :: Config { command } => commands:: config:: execute ( command, ctx ) ,
115168 _ => {
116169 let api_key = api_key. ok_or_else ( || {
117170 anyhow:: anyhow!(
@@ -122,49 +175,47 @@ pub async fn run(cli: Cli) -> anyhow::Result<()> {
122175
123176 match cli. command {
124177 Commands :: Agents { command } => {
125- commands:: agents:: execute ( command, & client, cli . format ) . await
178+ commands:: agents:: execute ( command, & client, ctx ) . await
126179 }
127180 Commands :: Conversations { command } => {
128- commands:: conversations:: execute ( command, & client, cli. format ) . await
129- }
130- Commands :: Runs { command } => {
131- commands:: runs:: execute ( command, & client, cli. format ) . await
181+ commands:: conversations:: execute ( command, & client, ctx) . await
132182 }
183+ Commands :: Runs { command } => commands:: runs:: execute ( command, & client, ctx) . await ,
133184 Commands :: Simulations { command } => {
134- commands:: simulations:: execute ( command, & client, cli . format ) . await
185+ commands:: simulations:: execute ( command, & client, ctx ) . await
135186 }
136187 Commands :: TestSets { command } => {
137- commands:: test_sets:: execute ( command, & client, cli . format ) . await
188+ commands:: test_sets:: execute ( command, & client, ctx ) . await
138189 }
139190 Commands :: TestCases { command } => {
140- commands:: test_cases:: execute ( command, & client, cli . format ) . await
191+ commands:: test_cases:: execute ( command, & client, ctx ) . await
141192 }
142193 Commands :: Personas { command } => {
143- commands:: personas:: execute ( command, & client, cli . format ) . await
194+ commands:: personas:: execute ( command, & client, ctx ) . await
144195 }
145196 Commands :: Metrics { command } => {
146- commands:: metrics:: execute ( command, & client, cli . format ) . await
197+ commands:: metrics:: execute ( command, & client, ctx ) . await
147198 }
148199 Commands :: Mutations { command } => {
149- commands:: mutations:: execute ( command, & client, cli . format ) . await
200+ commands:: mutations:: execute ( command, & client, ctx ) . await
150201 }
151202 Commands :: ApiKeys { command } => {
152- commands:: api_keys:: execute ( command, & client, cli . format ) . await
203+ commands:: api_keys:: execute ( command, & client, ctx ) . await
153204 }
154205 Commands :: RunTemplates { command } => {
155- commands:: run_templates:: execute ( command, & client, cli . format ) . await
206+ commands:: run_templates:: execute ( command, & client, ctx ) . await
156207 }
157208 Commands :: ScheduledRuns { command } => {
158- commands:: scheduled_runs:: execute ( command, & client, cli . format ) . await
209+ commands:: scheduled_runs:: execute ( command, & client, ctx ) . await
159210 }
160211 Commands :: Dashboards { command } => {
161- commands:: dashboards:: execute ( command, & client, cli . format ) . await
212+ commands:: dashboards:: execute ( command, & client, ctx ) . await
162213 }
163214 Commands :: ReviewAnnotations { command } => {
164- commands:: review_annotations:: execute ( command, & client, cli . format ) . await
215+ commands:: review_annotations:: execute ( command, & client, ctx ) . await
165216 }
166217 Commands :: ReviewProjects { command } => {
167- commands:: review_projects:: execute ( command, & client, cli . format ) . await
218+ commands:: review_projects:: execute ( command, & client, ctx ) . await
168219 }
169220 _ => unreachable ! ( ) ,
170221 }
0 commit comments