-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement call to run endpoint + refactor clap arguments
Signed-off-by: Charley <[email protected]>
- Loading branch information
1 parent
efdc54a
commit 6868159
Showing
6 changed files
with
84 additions
and
47 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
language: rust | ||
env_path: /home/charley/polytech/cloudlet/src/cli/config/example.env | ||
code_path: /home/charley/polytech/cloudlet/src/cli/src/main.rs | ||
env_path: /path/cloudlet/src/cli/config/example.env | ||
code_path: /path/cloudlet/src/cli/src/main.rs | ||
log_level: debug |
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 clap::Parser; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Parser, Debug)] | ||
#[command(version, about, long_about = None)] | ||
pub struct CliArgs { | ||
#[command(subcommand)] | ||
pub command: Commands, | ||
} | ||
|
||
#[derive(Parser, Debug)] | ||
pub enum Commands { | ||
Run { | ||
#[arg(short, long)] | ||
config_path: PathBuf, | ||
}, | ||
} |
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,41 @@ | ||
use crate::types::{Language, LogLevel}; | ||
use reqwest::Client; | ||
use serde::Serialize; | ||
use std::error::Error; | ||
|
||
#[derive(Serialize, Debug)] | ||
pub struct HttpRunRequest { | ||
pub language: Language, | ||
pub env_content: String, | ||
pub code_content: String, | ||
pub log_level: LogLevel, | ||
} | ||
|
||
impl HttpRunRequest { | ||
pub fn new( | ||
language: Language, | ||
env_content: String, | ||
code_content: String, | ||
log_level: LogLevel, | ||
) -> Self { | ||
HttpRunRequest { | ||
language, | ||
env_content, | ||
code_content, | ||
log_level, | ||
} | ||
} | ||
} | ||
|
||
pub async fn run_request(request: HttpRunRequest) -> Result<(), Box<dyn Error>> { | ||
let client = Client::new(); | ||
let res = client | ||
.post("http://127.0.0.1:3000/run") | ||
.body(serde_json::to_string(&request)?) | ||
.send() | ||
.await?; | ||
println!("Response Status: {}", res.status()); | ||
let body = res.text().await?; | ||
println!("Response body: {}", body); | ||
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