Skip to content

Commit

Permalink
refactor(run,readme): removed unnecessary codes, fix typos
Browse files Browse the repository at this point in the history
  • Loading branch information
pwnwriter committed Jul 26, 2023
1 parent 95a5c5d commit 5b61457
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 14 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,7 +3,7 @@
<img src="https://github.com/pwnwriter/rustycli/blob/images/rustycli-crop.gif" width="300" style="border-radius: 50%;">
</a>

<h4><strong><code>rustycli</code></strong> — 🦀 Access the rust playground right in terminal 🍥</h4>
<h4><strong><code>rustycli</code></strong> — 🦀 Access the rust playground right in your terminal 🍥</h4>


<a href="https://crates.io/crates/rustycli/"><img src="https://img.shields.io/crates/v/rustycli?style=flat&amp;labelColor=56534b&amp;color=c1c1b6&amp;logo=Rust&amp;logoColor=white" alt="Crate Release"></a>
Expand Down
13 changes: 0 additions & 13 deletions src/interface/run.rs
Expand Up @@ -28,8 +28,6 @@ struct ResponsePayload {

// Implementation of RequestPayload with a constructor function for easy creation
impl RequestPayload {
// Constructor function to create a new RequestPayload instance
// Takes a code string as input, and uses CLI arguments to populate other fields
fn new(code: &str) -> RequestPayload {
let cli = Cli::parse();
RequestPayload {
Expand All @@ -56,34 +54,23 @@ pub async fn run_rustycli() -> Result<(), Box<dyn std::error::Error>> {

let client = Client::new();

// Build the POST request with the playground URL, headers, and serialized JSON payload
let request_builder = client
.post(PLAYGROUND_URL)
.header(CONTENT_TYPE, "application/json")
.json(&request_payload);

// Get a string representation of the request and print it
// let request_str = format!("{:#?}", request_builder);
// println!("{:?}", request_str);

// Make the HTTP request to the playground and await the response
let resp_json = request_builder
.send()
.await?
.json::<ResponsePayload>()
.await?;

// println!("{:?}", resp_json);

// Display the output of the executed code (if any) or show an error message

let match_result = match (resp_json.stdout, resp_json.stderr) {
(Some(stdout), _) if !stdout.is_empty() => stdout,
(_, Some(stderr)) => stderr,
_ => String::from("Error: No stdout or stderr found in the response."),
};

spinner.success(&match_result);
// println!("{}", match_result);
Ok(())
}

0 comments on commit 5b61457

Please sign in to comment.