Skip to content
This repository was archived by the owner on Jun 14, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 45 additions & 12 deletions src/commands/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ use super::{queries::project::ProjectProjectEnvironmentsEdgesNode, *};

/// Change the active environment
#[derive(Parser)]
pub struct Args {}
pub struct Args {
environment: Option<String>,
}

pub async fn command(_args: Args, _json: bool) -> Result<()> {
let mut configs = Configs::new()?;
Expand All @@ -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(),
Expand Down
26 changes: 23 additions & 3 deletions src/commands/variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use super::{
/// Show variables for active environment
#[derive(Parser)]
pub struct Args {
/// Show variables for a specific environment
environment: Option<String>,
/// Show variables for a plugin
#[clap(short, long)]
plugin: bool,
Expand Down Expand Up @@ -45,14 +47,32 @@ 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");
}
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()),
Expand Down Expand Up @@ -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,
Expand All @@ -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()),
Expand Down
11 changes: 7 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -191,16 +192,18 @@ impl Configs {
environment_id: String,
environment_name: Option<String>,
) -> 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(())
}

Expand Down