-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(snot-cli): start and stop test cmds
- Loading branch information
Showing
8 changed files
with
114 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use anyhow::Result; | ||
use clap::Parser; | ||
|
||
#[derive(Debug, Parser)] | ||
#[clap(name = "snot-cli", author = "MONADIC.US")] | ||
pub struct Cli { | ||
// /// The subcommand to run. | ||
#[clap(subcommand)] | ||
pub subcommand: crate::commands::Commands, | ||
} | ||
|
||
impl Cli { | ||
/// Runs the subcommand. | ||
pub fn run(self) -> Result<()> { | ||
self.subcommand.run() | ||
} | ||
} |
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,17 @@ | ||
use anyhow::Result; | ||
use clap::Parser; | ||
|
||
mod test; | ||
|
||
#[derive(Debug, Parser)] | ||
pub enum Commands { | ||
Test(test::Test), | ||
} | ||
|
||
impl Commands { | ||
pub fn run(self) -> Result<()> { | ||
match self { | ||
Commands::Test(test) => test.run(), | ||
} | ||
} | ||
} |
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 std::path::PathBuf; | ||
|
||
use anyhow::Result; | ||
use clap::Parser; | ||
|
||
/// For interacting with snot tests. | ||
#[derive(Debug, Parser)] | ||
pub struct Test { | ||
/// The url the agent is on. | ||
#[clap(short, long, default_value = "http://localhost:1234")] | ||
url: url::Url, | ||
#[clap(subcommand)] | ||
command: Commands, | ||
} | ||
|
||
/// Test commands | ||
#[derive(Debug, Parser)] | ||
enum Commands { | ||
Start { | ||
/// The test spec file. | ||
spec: PathBuf, | ||
}, | ||
Stop, | ||
} | ||
|
||
impl Test { | ||
const START_ENDPOINT: &'static str = "api/v1/test/prepare"; | ||
const STOP_ENDPOINT: &'static str = "api/v1/test"; | ||
|
||
pub fn run(self) -> Result<()> { | ||
let client = reqwest::blocking::Client::new(); | ||
use Commands::*; | ||
match self.command { | ||
Start { spec } => { | ||
let file: String = std::fs::read_to_string(spec)?; | ||
client | ||
.post(&format!("{}{}", self.url, Self::START_ENDPOINT)) | ||
.body(file) | ||
.send()?; | ||
Ok(()) | ||
} | ||
Stop => { | ||
client | ||
.delete(&format!("{}{}", self.url, Self::STOP_ENDPOINT)) | ||
.send()?; | ||
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 |
---|---|---|
@@ -1,3 +1,18 @@ | ||
fn main() { | ||
println!("Hello, world!"); | ||
use std::process::exit; | ||
|
||
use anyhow::Result; | ||
use clap::Parser; | ||
|
||
mod cli; | ||
mod commands; | ||
|
||
fn main() -> Result<()> { | ||
let cli = cli::Cli::parse(); | ||
|
||
if let Err(err) = cli.run() { | ||
eprintln!("⚠️ {err}"); | ||
exit(1); | ||
} | ||
|
||
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