@@ -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,65 @@ 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 { .. } => "dashboards" ,
124+ Self :: ReviewAnnotations { .. } => "review-annotations" ,
125+ Self :: ReviewProjects { .. } => "review-projects" ,
126+ }
127+ }
128+
129+ pub fn operation ( & self ) -> & ' static str {
130+ match self {
131+ Self :: Login ( _) => "login" ,
132+ Self :: Whoami => "whoami" ,
133+ Self :: Config { command } => command. operation ( ) ,
134+ Self :: Agents { command } => command. operation ( ) ,
135+ Self :: Conversations { command } => command. operation ( ) ,
136+ Self :: Runs { command } => command. operation ( ) ,
137+ Self :: Simulations { command } => command. operation ( ) ,
138+ Self :: TestSets { command } => command. operation ( ) ,
139+ Self :: TestCases { command } => command. operation ( ) ,
140+ Self :: Personas { command } => command. operation ( ) ,
141+ Self :: Metrics { command } => command. operation ( ) ,
142+ Self :: Mutations { command } => command. operation ( ) ,
143+ Self :: ApiKeys { command } => command. operation ( ) ,
144+ Self :: RunTemplates { command } => command. operation ( ) ,
145+ Self :: ScheduledRuns { command } => command. operation ( ) ,
146+ Self :: Dashboards { command } => command. operation ( ) ,
147+ Self :: ReviewAnnotations { command } => command. operation ( ) ,
148+ Self :: ReviewProjects { command } => command. operation ( ) ,
149+ }
150+ }
151+ }
152+
153+ pub async fn run ( cli : Cli , ctx : & OutputContext ) -> anyhow:: Result < ( ) > {
104154 let config = Config :: load ( ) . unwrap_or_default ( ) ;
105155 let api_key = cli. api_key . or ( config. api_key ) ;
106156 let api_url = cli. api_url . or ( config. api_url ) ;
107157
108158 match cli. command {
109- Commands :: Login ( args) => commands:: auth:: login ( args) . await ,
159+ Commands :: Login ( args) => commands:: auth:: login ( args, ctx ) . await ,
110160 Commands :: Whoami => {
111- commands:: auth:: whoami ( api_key. as_ref ( ) ) ;
161+ commands:: auth:: whoami ( api_key. as_ref ( ) , ctx ) ;
112162 Ok ( ( ) )
113163 }
114- Commands :: Config { command } => commands:: config:: execute ( command) ,
164+ Commands :: Config { command } => commands:: config:: execute ( command, ctx ) ,
115165 _ => {
116166 let api_key = api_key. ok_or_else ( || {
117167 anyhow:: anyhow!(
@@ -122,49 +172,47 @@ pub async fn run(cli: Cli) -> anyhow::Result<()> {
122172
123173 match cli. command {
124174 Commands :: Agents { command } => {
125- commands:: agents:: execute ( command, & client, cli . format ) . await
175+ commands:: agents:: execute ( command, & client, ctx ) . await
126176 }
127177 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
178+ commands:: conversations:: execute ( command, & client, ctx) . await
132179 }
180+ Commands :: Runs { command } => commands:: runs:: execute ( command, & client, ctx) . await ,
133181 Commands :: Simulations { command } => {
134- commands:: simulations:: execute ( command, & client, cli . format ) . await
182+ commands:: simulations:: execute ( command, & client, ctx ) . await
135183 }
136184 Commands :: TestSets { command } => {
137- commands:: test_sets:: execute ( command, & client, cli . format ) . await
185+ commands:: test_sets:: execute ( command, & client, ctx ) . await
138186 }
139187 Commands :: TestCases { command } => {
140- commands:: test_cases:: execute ( command, & client, cli . format ) . await
188+ commands:: test_cases:: execute ( command, & client, ctx ) . await
141189 }
142190 Commands :: Personas { command } => {
143- commands:: personas:: execute ( command, & client, cli . format ) . await
191+ commands:: personas:: execute ( command, & client, ctx ) . await
144192 }
145193 Commands :: Metrics { command } => {
146- commands:: metrics:: execute ( command, & client, cli . format ) . await
194+ commands:: metrics:: execute ( command, & client, ctx ) . await
147195 }
148196 Commands :: Mutations { command } => {
149- commands:: mutations:: execute ( command, & client, cli . format ) . await
197+ commands:: mutations:: execute ( command, & client, ctx ) . await
150198 }
151199 Commands :: ApiKeys { command } => {
152- commands:: api_keys:: execute ( command, & client, cli . format ) . await
200+ commands:: api_keys:: execute ( command, & client, ctx ) . await
153201 }
154202 Commands :: RunTemplates { command } => {
155- commands:: run_templates:: execute ( command, & client, cli . format ) . await
203+ commands:: run_templates:: execute ( command, & client, ctx ) . await
156204 }
157205 Commands :: ScheduledRuns { command } => {
158- commands:: scheduled_runs:: execute ( command, & client, cli . format ) . await
206+ commands:: scheduled_runs:: execute ( command, & client, ctx ) . await
159207 }
160208 Commands :: Dashboards { command } => {
161- commands:: dashboards:: execute ( command, & client, cli . format ) . await
209+ commands:: dashboards:: execute ( command, & client, ctx ) . await
162210 }
163211 Commands :: ReviewAnnotations { command } => {
164- commands:: review_annotations:: execute ( command, & client, cli . format ) . await
212+ commands:: review_annotations:: execute ( command, & client, ctx ) . await
165213 }
166214 Commands :: ReviewProjects { command } => {
167- commands:: review_projects:: execute ( command, & client, cli . format ) . await
215+ commands:: review_projects:: execute ( command, & client, ctx ) . await
168216 }
169217 _ => unreachable ! ( ) ,
170218 }
0 commit comments