diff --git a/README.md b/README.md index e67f109..6b292b1 100644 --- a/README.md +++ b/README.md @@ -15,17 +15,23 @@ The Railway CLI allows you to - Pull down environment variables for your project locally to run - Create services and databases right from the comfort of your fingertips ## Status + Currently pre-release. We are looking for feedback and suggestions. Please join our [Discord](https://discord.gg/railway) to provide feedback. ## Installation + ### Cargo + ```bash cargo install railwayapp --locked ``` + ### From source + See [CONTRIBUTING.md](https://github.com/railwayapp/cliv3/blob/master/CONTRIBUTING.md) for information on setting up this repo locally. ## Documentation + [View the full documentation](https://docs.railway.app) ## Feedback diff --git a/src/commands/environment.rs b/src/commands/environment.rs index a4e8ee2..cd80839 100644 --- a/src/commands/environment.rs +++ b/src/commands/environment.rs @@ -4,7 +4,9 @@ use super::{queries::project::ProjectProjectEnvironmentsEdgesNode, *}; /// Change the active environment #[derive(Parser)] -pub struct Args {} +pub struct Args { + environment: Option, +} pub async fn command(_args: Args, _json: bool) -> Result<()> { let mut configs = Configs::new()?; @@ -19,17 +21,48 @@ pub async fn command(_args: Args, _json: bool) -> Result<()> { let body = res.data.context("Failed to retrieve response body")?; - let environments: Vec<_> = body - .project - .environments - .edges - .iter() - .map(|env| Environment(&env.node)) - .collect(); - - let environment = inquire::Select::new("Select an environment", environments) - .with_render_config(configs.get_render_config()) - .prompt()?; + let environment = if let Some(environment) = _args.environment.clone() { + let env = body + .project + .environments + .edges + .iter() + .map(|env| Environment(&env.node)) + .find(|env| env.0.name == environment); + + env.ok_or_else(|| anyhow::anyhow!("Environment not found"))? + } else { + let environments: Vec<_> = body + .project + .environments + .edges + .iter() + .map(|env| Environment(&env.node)) + .collect(); + + let env = inquire::Select::new("Select an environment", environments) + .with_render_config(configs.get_render_config()) + .prompt()?; + + env + }; + + // dbg!(body.clone().project.environments.edges); + // dbg!(environment.clone()); + // // early return + // return Ok(()); + + // let environments: Vec<_> = body + // .project + // .environments + // .edges + // .iter() + // .map(|env| Environment(&env.node)) + // .collect(); + + // let environment = inquire::Select::new("Select an environment", environments) + // .with_render_config(configs.get_render_config()) + // .prompt()?; configs.link_project( linked_project.project.clone(), diff --git a/src/commands/variables.rs b/src/commands/variables.rs index b19e4b3..a141658 100644 --- a/src/commands/variables.rs +++ b/src/commands/variables.rs @@ -12,6 +12,8 @@ use super::{ /// Show variables for active environment #[derive(Parser)] pub struct Args { + /// Show variables for a specific environment + environment: Option, /// Show variables for a plugin #[clap(short, long)] plugin: bool, @@ -45,6 +47,24 @@ pub async fn command(args: Args, json: bool) -> Result<()> { .map(|plugin| Plugin(&plugin.node)) .collect(); + let environment = if let Some(environment) = args.environment.clone() { + let envs = &body + .project + .environments + .edges + .iter() + .map(|env| env.node.clone()) + .find(|env| env.name == environment); + + if envs.is_none() { + bail!("Environment not found"); + } + + envs.clone().unwrap().id + } else { + linked_project.environment.clone() + }; + let (vars, name) = if args.plugin { if plugins.is_empty() { bail!("No plugins found"); @@ -52,7 +72,7 @@ pub async fn command(args: Args, json: bool) -> Result<()> { let plugin = prompt_plugin(plugins)?; ( queries::variables::Variables { - environment_id: linked_project.environment.clone(), + environment_id: environment, project_id: linked_project.project.clone(), service_id: None, plugin_id: Some(plugin.0.id.clone()), @@ -86,7 +106,7 @@ pub async fn command(args: Args, json: bool) -> Result<()> { .context("Service not found")?; ( queries::variables::Variables { - environment_id: linked_project.environment.clone(), + environment_id: environment, project_id: linked_project.project.clone(), service_id: Some(service.clone()), plugin_id: None, @@ -100,7 +120,7 @@ pub async fn command(args: Args, json: bool) -> Result<()> { let plugin = prompt_plugin(plugins)?; ( queries::variables::Variables { - environment_id: linked_project.environment.clone(), + environment_id: environment, project_id: linked_project.project.clone(), service_id: None, plugin_id: Some(plugin.0.id.clone()), diff --git a/src/config.rs b/src/config.rs index 9c65cb4..81a1823 100644 --- a/src/config.rs +++ b/src/config.rs @@ -156,7 +156,8 @@ impl Configs { let data = res.data.context("Invalid project token!")?; let project = RailwayProject { - project_path: self.get_closest_linked_project_directory()?, + // project_path: self.get_closest_linked_project_directory()?, + project_path: ".".to_string(), name: Some(data.project_token.project.name), project: data.project_token.project.id, environment: data.project_token.environment.id, @@ -191,16 +192,18 @@ impl Configs { environment_id: String, environment_name: Option, ) -> Result<()> { - let path = self.get_closest_linked_project_directory()?; + // let path = self.get_closest_linked_project_directory()?; let project = RailwayProject { - project_path: path.clone(), + // project_path: path.clone(), + project_path: ".".to_string(), name, project: project_id, environment: environment_id, environment_name, service: None, }; - self.root_config.projects.insert(path, project); + // self.root_config.projects.insert(path, project); + self.root_config.projects.insert(".".to_string(), project); Ok(()) }