This repository has been archived by the owner on Dec 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
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
bddfa6d
commit 56f4a16
Showing
9 changed files
with
211 additions
and
84 deletions.
There are no files selected for viewing
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,78 @@ | ||
use clap::Parser; | ||
use std::process::ExitCode; | ||
use toolchain::{ | ||
tasks::{deploy, get_bootstrap_data, RunConfig}, | ||
util::task::run_task, | ||
}; | ||
|
||
#[derive(Parser)] | ||
pub struct Opts { | ||
environment: String, | ||
#[clap(long, conflicts_with = "only_backend")] | ||
only_game_server: bool, | ||
#[clap(long, conflicts_with = "only_game_server")] | ||
only_backend: bool, | ||
} | ||
|
||
impl Opts { | ||
pub async fn execute(&self) -> ExitCode { | ||
let run_config = RunConfig::empty(); | ||
|
||
let bootstrap_data = match run_task::<get_bootstrap_data::Task>( | ||
run_config.clone(), | ||
get_bootstrap_data::Input {}, | ||
) | ||
.await | ||
{ | ||
Ok(x) => x, | ||
Err(e) => { | ||
eprintln!("Error getting bootstrap: {e}"); | ||
return ExitCode::FAILURE; | ||
} | ||
}; | ||
|
||
// Find environment | ||
let environment = match bootstrap_data | ||
.backend_environments | ||
.iter() | ||
.find(|env| env.name_id == self.environment) | ||
{ | ||
Some(env) => env, | ||
None => { | ||
eprintln!( | ||
"Environment '{}' not found. Available environments:", | ||
self.environment | ||
); | ||
for env in &bootstrap_data.backend_environments { | ||
eprintln!("- {}", env.name_id); | ||
} | ||
return ExitCode::FAILURE; | ||
} | ||
}; | ||
|
||
match run_task::<deploy::Task>( | ||
run_config, | ||
deploy::Input { | ||
cwd: std::env::current_dir() | ||
.unwrap_or_default() | ||
.to_string_lossy() | ||
.to_string(), | ||
environment_id: environment.environment_id.to_string(), | ||
game_server: !self.only_backend, | ||
backend: !self.only_game_server, | ||
}, | ||
) | ||
.await | ||
{ | ||
Ok(_) => { | ||
println!("Deployment completed successfully."); | ||
ExitCode::SUCCESS | ||
} | ||
Err(e) => { | ||
eprintln!("Error during deployment: {e}"); | ||
ExitCode::FAILURE | ||
} | ||
} | ||
} | ||
} | ||
|
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 |
---|---|---|
@@ -1,50 +1,65 @@ | ||
use clap::Parser; | ||
use global_error::prelude::*; | ||
use std::process::ExitCode; | ||
use toolchain::{ | ||
tasks::{check_login_state, start_device_link, wait_for_login, RunConfig}, | ||
util::task::run_task, | ||
tasks::{check_login_state, start_device_link, wait_for_login, RunConfig}, | ||
util::task::run_task, | ||
}; | ||
|
||
#[derive(Parser)] | ||
pub struct Opts { | ||
#[clap(long, default_value = "https://api.rivet.gg")] | ||
api_endpoint: String, | ||
#[clap(long, default_value = "https://api.rivet.gg")] | ||
api_endpoint: String, | ||
} | ||
|
||
impl Opts { | ||
pub async fn execute(&self) -> GlobalResult<()> { | ||
let run_config = RunConfig::empty(); | ||
pub async fn execute(&self) -> ExitCode { | ||
let run_config = RunConfig::empty(); | ||
|
||
// Check if linked | ||
let output = | ||
run_task::<check_login_state::Task>(run_config.clone(), check_login_state::Input {}) | ||
.await?; | ||
if output.logged_in { | ||
eprintln!("Already logged in. Sign out with `rivet unlink`."); | ||
return Ok(()); | ||
} | ||
// Check if linked | ||
match run_task::<check_login_state::Task>(run_config.clone(), check_login_state::Input {}).await { | ||
Ok(output) => { | ||
if output.logged_in { | ||
eprintln!("Already logged in. Sign out with `rivet unlink`."); | ||
return ExitCode::SUCCESS; | ||
} | ||
} | ||
Err(e) => { | ||
eprintln!("Error checking login state: {}", e); | ||
return ExitCode::from(1); | ||
} | ||
} | ||
|
||
// Start device link | ||
let output = run_task::<start_device_link::Task>( | ||
run_config.clone(), | ||
start_device_link::Input { | ||
api_endpoint: self.api_endpoint.clone(), | ||
}, | ||
) | ||
.await?; | ||
eprintln!("{}", output.device_link_url); | ||
// Start device link | ||
let device_link_output = match run_task::<start_device_link::Task>( | ||
run_config.clone(), | ||
start_device_link::Input { | ||
api_endpoint: self.api_endpoint.clone(), | ||
}, | ||
).await { | ||
Ok(output) => output, | ||
Err(e) => { | ||
eprintln!("Error starting device link: {}", e); | ||
return ExitCode::from(2); | ||
} | ||
}; | ||
eprintln!("{}", device_link_output.device_link_url); | ||
|
||
// Wait for finish | ||
run_task::<wait_for_login::Task>( | ||
run_config.clone(), | ||
wait_for_login::Input { | ||
api_endpoint: self.api_endpoint.clone(), | ||
device_link_token: output.device_link_token, | ||
}, | ||
) | ||
.await?; | ||
eprintln!("Logged in"); | ||
|
||
Ok(()) | ||
} | ||
} | ||
// Wait for finish | ||
match run_task::<wait_for_login::Task>( | ||
run_config.clone(), | ||
wait_for_login::Input { | ||
api_endpoint: self.api_endpoint.clone(), | ||
device_link_token: device_link_output.device_link_token, | ||
}, | ||
).await { | ||
Ok(_) => { | ||
eprintln!("Logged in"); | ||
ExitCode::SUCCESS | ||
} | ||
Err(e) => { | ||
eprintln!("Error waiting for login: {}", e); | ||
ExitCode::from(3) | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,26 @@ | ||
use clap::Parser; | ||
use global_error::prelude::*; | ||
use std::process::ExitCode; | ||
use toolchain::{ | ||
tasks::{unlink, RunConfig}, | ||
util::task::run_task, | ||
tasks::{unlink, RunConfig}, | ||
util::task::run_task, | ||
}; | ||
|
||
#[derive(Parser)] | ||
pub struct Opts {} | ||
|
||
impl Opts { | ||
pub async fn execute(&self) -> GlobalResult<()> { | ||
let run_config = RunConfig::empty(); | ||
pub async fn execute(&self) -> ExitCode { | ||
let run_config = RunConfig::empty(); | ||
|
||
run_task::<unlink::Task>(run_config.clone(), unlink::Input {}).await?; | ||
eprintln!("Logged out"); | ||
|
||
Ok(()) | ||
} | ||
} | ||
match run_task::<unlink::Task>(run_config.clone(), unlink::Input {}).await { | ||
Ok(_) => { | ||
eprintln!("Logged out"); | ||
ExitCode::SUCCESS | ||
} | ||
Err(e) => { | ||
eprintln!("Error logging out: {}", e); | ||
ExitCode::from(1) | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,26 +1,29 @@ | ||
pub mod login; | ||
pub mod logout; | ||
pub mod task; | ||
pub mod deploy; | ||
|
||
use clap::Parser; | ||
use global_error::prelude::*; | ||
use std::process::ExitCode; | ||
|
||
#[derive(Parser)] | ||
pub enum SubCommand { | ||
Login(login::Opts), | ||
Task { | ||
#[clap(subcommand)] | ||
subcommand: task::SubCommand, | ||
}, | ||
Logout(logout::Opts), | ||
Login(login::Opts), | ||
Task { | ||
#[clap(subcommand)] | ||
subcommand: task::SubCommand, | ||
}, | ||
Logout(logout::Opts), | ||
Deploy(deploy::Opts), | ||
} | ||
|
||
impl SubCommand { | ||
pub async fn execute(&self) -> GlobalResult<()> { | ||
match self { | ||
SubCommand::Login(opts) => opts.execute().await, | ||
SubCommand::Task { subcommand } => subcommand.execute().await, | ||
SubCommand::Logout(opts) => opts.execute().await, | ||
} | ||
} | ||
} | ||
pub async fn execute(&self) -> ExitCode { | ||
match self { | ||
SubCommand::Login(opts) => opts.execute().await, | ||
SubCommand::Task { subcommand } => subcommand.execute().await, | ||
SubCommand::Logout(opts) => opts.execute().await, | ||
SubCommand::Deploy(opts) => opts.execute().await, | ||
} | ||
} | ||
} |
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