Skip to content

Commit

Permalink
set_default_url command
Browse files Browse the repository at this point in the history
  • Loading branch information
marcua committed Jan 6, 2024
1 parent f5e651c commit 74e8b7d
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/bin/ayb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ async fn main() -> std::io::Result<()> {
.num_args(0..)
)
)
.subcommand(
Command::new("set_default_url")
.about("Set the default server URL for future requests in .ayb.json")
.arg(arg!(<url> "The URL to use in the future")
.required(true))
)
)
.get_matches();

Expand All @@ -185,6 +191,15 @@ async fn main() -> std::io::Result<()> {
};
let mut config = ClientConfig::from_file(&config_path)?;

if let Some(matches) = matches.subcommand_matches("set_default_url") {
if let Some(url) = matches.get_one::<String>("url") {
config.default_url = Some(url.to_string());
config.to_file(&config_path)?;
println!("Saved {} as new default_url", url);
return Ok(());
}
}

let url = if let Some(server_url) = matches.get_one::<String>("url") {
if config.default_url.is_none() {
config.default_url = Some(server_url.to_string());
Expand All @@ -194,7 +209,7 @@ async fn main() -> std::io::Result<()> {
} else if let Some(ref server_url) = config.default_url {
server_url.to_string()
} else {
panic!("Server URL is required through --url parameter, AYB_SERVER_URL environment variable, or default_url in ayb.json");
panic!("Server URL is required through --url parameter, AYB_SERVER_URL environment variable, or default_url in .ayb.json");
};

let token = matches
Expand Down

0 comments on commit 74e8b7d

Please sign in to comment.