Skip to content
This repository has been archived by the owner on Jun 8, 2022. It is now read-only.

Commit

Permalink
Add README.md and fix args
Browse files Browse the repository at this point in the history
  • Loading branch information
emmatyping committed Jun 1, 2018
1 parent 106e440 commit 9a20421
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# cce - command line compiler explorer

Do you love [Compiler Explorer](https://godbolt.org/)? Do you like the command line? Well this is the tool for you!

This is very unstable at the moment. Use at your own risk!
5 changes: 3 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ fn main() {
)
.arg(
Arg::with_name("args")
.takes_value(true)
.multiple(true)
.allow_hyphen_values(true)
.help(" arguments to pass to the compiler"),
),
)
Expand All @@ -78,7 +79,7 @@ fn main() {
} else if let Some(matches) = matches.subcommand_matches("compile") {
let src = edit_snippet();
let compiler = matches.value_of("id").unwrap();
let args = matches.value_of("id").unwrap_or("").to_string();
let args = matches.value_of("args").unwrap_or("").to_string();
let asm = compile(client, src, compiler, args);
println!("Compiling with {} compiler outputs:", compiler);
println!("");
Expand Down
19 changes: 13 additions & 6 deletions src/requests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use reqwest::Client;

use compiler::Compiler;
use language::Language;
use source::{Asm, Filters, Options, Source};
use source::{Output, Filters, Options, Source};

pub fn get_languages(client: Client) -> Vec<Language> {
client
Expand Down Expand Up @@ -46,17 +46,24 @@ pub fn compile(client: Client, src: String, compiler: &str, args: String) -> Str
source: src,
options: options,
};
let asm: Asm = client
let output: Output = client
.post(format!("https://www.godbolt.org/api/compiler/{}/compile", &compiler).as_str())
.json(&source)
.send()
.unwrap()
.json()
.unwrap();
let mut res = String::new();
for line in asm.asm {
res.push_str(&line.text);
res.push('\n');
}
if output.code != 0 {
for line in output.stderr {
res.push_str(&line.text);
res.push('\n');
}
} else {
for line in output.asm {
res.push_str(&line.text);
res.push('\n');
}
}
return res;
}
4 changes: 3 additions & 1 deletion src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub struct Text {
}

#[derive(Serialize, Deserialize, Debug)]
pub struct Asm {
pub struct Output {
pub code: i32,
pub stderr: Vec<Text>,
pub asm: Vec<Text>,
}

0 comments on commit 9a20421

Please sign in to comment.