@@ -53,7 +53,10 @@ pub enum SelectedTab {
5353}
5454
5555#[ derive( Parser ) ]
56- pub struct Args { }
56+ pub struct Args {
57+ #[ arg( long, help = "Name of the provider to use" ) ]
58+ provider : Option < String > ,
59+ }
5760
5861pub struct App {
5962 done : bool ,
@@ -310,25 +313,33 @@ pub struct ExplorerContext {
310313 pub store : Store ,
311314 pub provider : Provider ,
312315}
313- impl TryFrom < & Context > for ExplorerContext {
316+ impl TryFrom < ( Args , & Context ) > for ExplorerContext {
314317 type Error = miette:: Error ;
315- fn try_from ( value : & Context ) -> Result < Self , Self :: Error > {
316- let provider = match value. store . default_provider ( ) {
317- Some ( provider) => provider,
318- None => match value. store . providers ( ) . first ( ) {
319- Some ( provider) => provider,
320- None => bail ! ( "No providers configured" ) ,
318+ fn try_from ( value : ( Args , & Context ) ) -> Result < Self , Self :: Error > {
319+ let ( args, ctx) = value;
320+ let provider = match args. provider {
321+ Some ( name) => match ctx. store . find_provider ( & name) {
322+ Some ( provider) => provider. clone ( ) ,
323+ None => bail ! ( "Provider not found." ) ,
324+ } ,
325+ None => match ctx. store . default_provider ( ) {
326+ Some ( provider) => provider. clone ( ) ,
327+ None => match ctx. store . providers ( ) . first ( ) {
328+ Some ( provider) => provider. clone ( ) ,
329+ None => bail ! ( "No providers configured" ) ,
330+ } ,
321331 } ,
322332 } ;
333+
323334 Ok ( Self {
324- store : value . store . clone ( ) ,
325- provider : provider . clone ( ) ,
335+ store : ctx . store . clone ( ) ,
336+ provider,
326337 } )
327338 }
328339}
329- impl TryFrom < & Context > for App {
340+ impl TryFrom < ( Args , & Context ) > for App {
330341 type Error = miette:: Error ;
331- fn try_from ( value : & Context ) -> Result < Self , Self :: Error > {
342+ fn try_from ( value : ( Args , & Context ) ) -> Result < Self , Self :: Error > {
332343 let context: Arc < ExplorerContext > = Arc :: new ( value. try_into ( ) ?) ;
333344 Ok ( Self {
334345 context : context. clone ( ) ,
@@ -347,9 +358,9 @@ impl TryFrom<&Context> for App {
347358 }
348359}
349360
350- pub async fn run ( _args : Args , ctx : & Context ) -> miette:: Result < ( ) > {
361+ pub async fn run ( args : Args , ctx : & Context ) -> miette:: Result < ( ) > {
351362 let terminal = ratatui:: init ( ) ;
352- let app = App :: try_from ( ctx) ?;
363+ let app = App :: try_from ( ( args , ctx) ) ?;
353364 let result = app. run ( terminal) . await ;
354365 ratatui:: restore ( ) ;
355366 result
0 commit comments