-
Notifications
You must be signed in to change notification settings - Fork 118
feat: add non-interactive mode and route management options to CLI #2532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use anyhow::*; | ||
use clap::Parser; | ||
use toolchain::{ | ||
rivet_api::{apis, models}, | ||
ToolchainCtx, | ||
}; | ||
|
||
/// Get information about a route endpoint | ||
#[derive(Parser, Clone)] | ||
pub struct Opts { | ||
/// Name of the route to retrieve information about | ||
function_name: String, | ||
|
||
/// Specify the environment to get the route from (will prompt if not specified) | ||
#[clap(long, alias = "env", short = 'e')] | ||
environment: Option<String>, | ||
} | ||
|
||
impl Opts { | ||
pub async fn execute(&self) -> Result<()> { | ||
let ctx = crate::util::login::load_or_login().await?; | ||
let env = crate::util::env::get_or_select(&ctx, self.environment.as_ref()).await?; | ||
|
||
// Get route information | ||
let route = get_route(&ctx, &env, &self.function_name).await?; | ||
|
||
match route { | ||
Some(route) => { | ||
println!("https://{}{}", route.hostname, route.path); | ||
|
||
Ok(()) | ||
} | ||
None => Err(anyhow!( | ||
"Route '{}' not found in environment '{}'", | ||
self.function_name, | ||
env | ||
)), | ||
} | ||
} | ||
} | ||
|
||
// Helper function to get route if it exists | ||
async fn get_route( | ||
ctx: &ToolchainCtx, | ||
env: &str, | ||
route_id: &str, | ||
) -> Result<Option<models::RoutesRoute>> { | ||
let routes_response = apis::routes_api::routes_list( | ||
&ctx.openapi_config_cloud, | ||
Some(&ctx.project.name_id.to_string()), | ||
Some(env), | ||
) | ||
.await?; | ||
|
||
// Find route that matches the ID | ||
let matching_route = routes_response | ||
.routes | ||
.iter() | ||
.find(|route| route.id == *route_id) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: Route lookup compares |
||
.cloned(); | ||
|
||
Ok(matching_route) | ||
} | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,38 @@ | ||||||
use anyhow::*; | ||||||
use clap::Parser; | ||||||
use toolchain::rivet_api::apis; | ||||||
|
||||||
/// List all functions for an environment | ||||||
#[derive(Parser)] | ||||||
pub struct Opts { | ||||||
/// Specify the environment to list function for (will prompt if not specified) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. syntax: Typo in help text: 'list function for' should be 'list functions for'
Suggested change
|
||||||
#[clap(long, alias = "env", short = 'e')] | ||||||
environment: Option<String>, | ||||||
} | ||||||
|
||||||
impl Opts { | ||||||
pub async fn execute(&self) -> Result<()> { | ||||||
let ctx = crate::util::login::load_or_login().await?; | ||||||
let env = crate::util::env::get_or_select(&ctx, self.environment.as_ref()).await?; | ||||||
|
||||||
// Get routes | ||||||
let routes_response = apis::routes_api::routes_list( | ||||||
&ctx.openapi_config_cloud, | ||||||
Some(&ctx.project.name_id.to_string()), | ||||||
Some(&env), | ||||||
) | ||||||
.await?; | ||||||
|
||||||
if routes_response.routes.is_empty() { | ||||||
println!("No routes found for environment '{}'", env); | ||||||
return Ok(()); | ||||||
} | ||||||
|
||||||
for route in routes_response.routes { | ||||||
println!("- {}: {}{}", route.id, route.hostname, route.path); | ||||||
} | ||||||
|
||||||
Ok(()) | ||||||
} | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use anyhow::*; | ||
use clap::Parser; | ||
|
||
pub mod endpoint; | ||
pub mod list; | ||
|
||
/// Commands for managing routes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. style: Module comment describes 'routes' but module name is 'function'. Consider updating comment or module name for consistency. |
||
#[derive(Parser)] | ||
pub enum SubCommand { | ||
/// List all routes | ||
List(list::Opts), | ||
/// Get information about a specific route endpoint | ||
Endpoint(endpoint::Opts), | ||
} | ||
|
||
impl SubCommand { | ||
pub async fn execute(&self) -> Result<()> { | ||
match self { | ||
SubCommand::List(opts) => opts.execute().await, | ||
SubCommand::Endpoint(opts) => opts.execute().await, | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ pub mod config; | |
pub mod deno; | ||
pub mod deploy; | ||
pub mod environment; | ||
pub mod function; | ||
pub mod login; | ||
pub mod logout; | ||
pub mod metadata; | ||
|
@@ -60,11 +61,13 @@ pub enum SubCommand { | |
subcommand: region::SubCommand, | ||
}, | ||
/// Commands for managing routes | ||
#[clap(alias = "r", alias = "endpoint")] | ||
Route { | ||
#[clap(alias = "f", alias = "func", alias = "route")] | ||
Function { | ||
#[clap(subcommand)] | ||
subcommand: route::SubCommand, | ||
subcommand: function::SubCommand, | ||
}, | ||
/// Get information about a specific route endpoint | ||
Endpoint(function::endpoint::Opts), | ||
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. logic: The Endpoint command appears to duplicate functionality that should be under the Function subcommand. Consider moving this under Function instead of having it as a top-level command. |
||
/// Commands for managing Rivet configuration | ||
Config { | ||
#[clap(subcommand)] | ||
|
@@ -102,7 +105,8 @@ impl SubCommand { | |
SubCommand::Actor { subcommand } => subcommand.execute().await, | ||
SubCommand::Build { subcommand } => subcommand.execute().await, | ||
SubCommand::Region { subcommand } => subcommand.execute().await, | ||
SubCommand::Route { subcommand } => subcommand.execute().await, | ||
SubCommand::Function { subcommand } => subcommand.execute().await, | ||
SubCommand::Endpoint(opts) => opts.execute().await, | ||
SubCommand::Config { subcommand } => subcommand.execute().await, | ||
SubCommand::Metadata { subcommand } => subcommand.execute().await, | ||
SubCommand::Deno(opts) => opts.execute().await, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Parameter name
route_id
is misleading since it's actually receiving a function name