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
2939244
commit 81a0c93
Showing
11 changed files
with
301 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[workspace] | ||
members = [ | ||
members = [ "rivet-cli", | ||
"rivet-toolchain", | ||
] | ||
|
||
|
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,12 @@ | ||
[package] | ||
name = "rivet-cli" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
clap = { version = "4.5.9", features = ["derive"] } | ||
global-error = { git = "https://github.com/rivet-gg/rivet.git", rev = "22baf31efa3ffcdad65ecc72ce25425ab61b9c6f" } | ||
toolchain = { version = "0.1.0", path = "../rivet-toolchain", package = "rivet-toolchain" } | ||
tokio = { version = "1.38.1", features = ["full"] } | ||
serde_json = "1.0.120" | ||
|
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,50 @@ | ||
use clap::Parser; | ||
use global_error::prelude::*; | ||
use toolchain::{ | ||
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, | ||
} | ||
|
||
impl Opts { | ||
pub async fn execute(&self) -> GlobalResult<()> { | ||
let (run_config, _temp_dir) = RunConfig::with_temp_dir()?; | ||
|
||
// 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(()); | ||
} | ||
|
||
// 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); | ||
|
||
// 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(()) | ||
} | ||
} |
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,20 @@ | ||
use clap::Parser; | ||
use global_error::prelude::*; | ||
use toolchain::{ | ||
tasks::{unlink, RunConfig}, | ||
util::task::run_task, | ||
}; | ||
|
||
#[derive(Parser)] | ||
pub struct Opts {} | ||
|
||
impl Opts { | ||
pub async fn execute(&self) -> GlobalResult<()> { | ||
let (run_config, _temp_dir) = RunConfig::with_temp_dir()?; | ||
|
||
run_task::<unlink::Task>(run_config.clone(), unlink::Input {}).await?; | ||
eprintln!("Logged out"); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pub mod login; | ||
pub mod logout; | ||
pub mod task; | ||
|
||
use clap::Parser; | ||
use global_error::prelude::*; | ||
|
||
#[derive(Parser)] | ||
pub enum SubCommand { | ||
Login(login::Opts), | ||
Task { | ||
#[clap(subcommand)] | ||
subcommand: task::SubCommand, | ||
}, | ||
Logout(logout::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, | ||
} | ||
} | ||
} |
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,35 @@ | ||
use clap::Parser; | ||
use global_error::prelude::*; | ||
|
||
/// EXPERIMENTAL | ||
#[derive(Parser)] | ||
pub enum SubCommand { | ||
Run(RunOpts), | ||
} | ||
|
||
impl SubCommand { | ||
pub async fn execute(&self) -> GlobalResult<()> { | ||
match self { | ||
SubCommand::Run(opts) => opts.execute().await, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Parser)] | ||
pub struct RunOpts { | ||
#[clap(long)] | ||
run_config: String, | ||
#[clap(long)] | ||
name: String, | ||
#[clap(long)] | ||
input: String, | ||
} | ||
|
||
impl RunOpts { | ||
pub async fn execute(&self) -> GlobalResult<()> { | ||
let run_config = serde_json::from_str(&self.run_config)?; | ||
let output = toolchain::tasks::run_task_json(run_config, &self.name, &self.input).await; | ||
println!("{output}"); | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
pub mod commands; | ||
|
||
use clap::Parser; | ||
use global_error::GlobalResult; | ||
|
||
#[derive(Parser)] | ||
#[clap(author, version, about, long_about = None)] | ||
struct Cli { | ||
#[command(subcommand)] | ||
command: commands::SubCommand, | ||
} | ||
|
||
#[tokio::main] | ||
async fn main() -> GlobalResult<()> { | ||
let cli = Cli::parse(); | ||
cli.command.execute().await?; | ||
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
Oops, something went wrong.