-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ce63bfd
commit 673e3f8
Showing
9 changed files
with
160 additions
and
38 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use crate::config; | ||
use clap::{Arg, Command}; | ||
use futures::executor::block_on; | ||
use serde::Serialize; | ||
|
||
use super::{ | ||
queries::{ | ||
projects::ProjectsProjectsEdgesNode, user_projects::UserProjectsMeProjectsEdgesNode, | ||
}, | ||
*, | ||
}; | ||
|
||
/// List all projects in your Railway account | ||
#[derive(Parser, Debug)] | ||
pub struct Args {} | ||
|
||
pub fn get_dynamic_args(cmd: Command) -> Command { | ||
if !std::env::args().any(|f| f.eq_ignore_ascii_case("scale")) { | ||
// if the command has nothing to do with railway scale, dont make the web request. | ||
return cmd; | ||
} | ||
block_on(async move { | ||
let configs = Configs::new().unwrap(); | ||
let client = GQLClient::new_authorized(&configs).unwrap(); | ||
let regions = post_graphql::<queries::Regions, _>( | ||
&client, | ||
configs.get_backboard(), | ||
queries::regions::Variables, | ||
) | ||
.await | ||
.expect("couldn't get regions"); | ||
|
||
// Collect region names as owned Strings. | ||
let region_strings = regions | ||
.regions | ||
.iter() | ||
.map(|r| r.name.to_string()) | ||
.collect::<Vec<String>>(); | ||
|
||
// Mutate the command to add each region as a flag. | ||
let mut new_cmd = cmd; | ||
for region in region_strings { | ||
let region_static: &'static str = Box::leak(region.into_boxed_str()); | ||
new_cmd = new_cmd.arg( | ||
Arg::new(region_static) // unique identifier | ||
.long(region_static) // --my-region | ||
.help(format!("Number of instances to run on {}", region_static)) | ||
.value_name("INSTANCES") | ||
.value_parser(clap::value_parser!(u16)) | ||
.action(clap::ArgAction::Set) | ||
); | ||
} | ||
new_cmd | ||
}) | ||
} | ||
|
||
pub async fn command(args: Args, json: bool) -> Result<()> { | ||
// Args::command().; | ||
println!("hello"); | ||
println!("{:?}", args); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
query Regions { | ||
regions { | ||
name | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters