MCPcopy Create free account
hub / github.com/bytehunt/rustycli / run_rustycli

Function run_rustycli

src/interface/run.rs:45–76  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43}
44
45pub async fn run_rustycli() -> Result<(), Box<dyn std::error::Error>> {
46 let cli = Cli::parse();
47 let filename = &cli.run;
48 let raw_code = tokio::fs::read_to_string(filename).await?;
49 let spinner = Spinner::new(spinners::Dots, "Compiling... ", Color::Green);
50
51 // Trim leading and trailing whitespaces from the code before executing it
52 let code = raw_code.trim();
53 let request_payload = RequestPayload::new(code);
54
55 let client = Client::new();
56
57 let request_builder = client
58 .post(PLAYGROUND_URL)
59 .header(CONTENT_TYPE, "application/json")
60 .json(&request_payload);
61
62 let resp_json = request_builder
63 .send()
64 .await?
65 .json::<ResponsePayload>()
66 .await?;
67
68 let match_result = match (resp_json.stdout, resp_json.stderr) {
69 (Some(stdout), _) if !stdout.is_empty() => stdout,
70 (_, Some(stderr)) => stderr,
71 _ => String::from("Error: No stdout or stderr found in the response."),
72 };
73
74 spinner.success(&match_result);
75 Ok(())
76}

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected