From 13b7be269140ebc009238dfa3d680f40fb745d24 Mon Sep 17 00:00:00 2001 From: Alexander Ng Date: Tue, 21 Feb 2023 00:41:52 -0800 Subject: [PATCH 1/6] feat: alex's feature request has been done --- src/commands/variables.rs | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/commands/variables.rs b/src/commands/variables.rs index bca8cb4..cf66ed3 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 environment + environment: Option, /// Show variables for a plugin #[clap(short, long)] plugin: bool, @@ -46,6 +48,26 @@ 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() + }; + + dbg!(&environment); + let (vars, name) = if args.plugin { if plugins.is_empty() { bail!("No plugins found"); @@ -53,7 +75,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()), @@ -70,7 +92,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, @@ -84,7 +106,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()), From 47e04447967b8b926c47ad5e6145db4c7edc0751 Mon Sep 17 00:00:00 2001 From: Alexander Ng Date: Tue, 21 Feb 2023 00:43:35 -0800 Subject: [PATCH 2/6] feat: include 'specific' --- src/commands/variables.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/variables.rs b/src/commands/variables.rs index cf66ed3..23d955c 100644 --- a/src/commands/variables.rs +++ b/src/commands/variables.rs @@ -12,7 +12,7 @@ use super::{ /// Show variables for active environment #[derive(Parser)] pub struct Args { - /// Show variables for a environment + /// Show variables for a specific environment environment: Option, /// Show variables for a plugin #[clap(short, long)] From c6c8b6bf22e086aa629f8628caf62e7749c433a8 Mon Sep 17 00:00:00 2001 From: Alexander Ng Date: Tue, 21 Feb 2023 00:51:11 -0800 Subject: [PATCH 3/6] fix: remove dbg!() --- src/commands/variables.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/commands/variables.rs b/src/commands/variables.rs index 23d955c..99a23d5 100644 --- a/src/commands/variables.rs +++ b/src/commands/variables.rs @@ -66,8 +66,6 @@ pub async fn command(args: Args, json: bool) -> Result<()> { linked_project.environment.clone() }; - dbg!(&environment); - let (vars, name) = if args.plugin { if plugins.is_empty() { bail!("No plugins found"); From 489ebf750245cfee4e1d320cff73b51f23016b07 Mon Sep 17 00:00:00 2001 From: Alexander Ng Date: Wed, 22 Feb 2023 21:58:42 -0800 Subject: [PATCH 4/6] chore: README.md conforms to MD022 --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index c7632f9..196f64c 100644 --- a/README.md +++ b/README.md @@ -7,17 +7,23 @@ This is the command line interface for [Railway](https://railway.app). Use it to [View the docs](https://docs.railway.app/develop/cli) ## 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 From d2f09de2d6f9ded53c7151c477944bcfabbc0909 Mon Sep 17 00:00:00 2001 From: Alexander Ng Date: Thu, 23 Feb 2023 22:57:34 -0800 Subject: [PATCH 5/6] feat: add arg to environment for going faster --- src/commands/environment.rs | 57 +++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 12 deletions(-) diff --git a/src/commands/environment.rs b/src/commands/environment.rs index 7af9d11..f8c5d24 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()?; @@ -24,17 +26,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(), From cf476cc9f25933fdcdeff905926f29705893e112 Mon Sep 17 00:00:00 2001 From: Alexander Ng Date: Wed, 1 Mar 2023 23:32:31 -0800 Subject: [PATCH 6/6] monkeypatch Signed-off-by: Alexander Ng --- src/config.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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(()) }