Skip to content

Commit

Permalink
Issue #44: Add support for piped input
Browse files Browse the repository at this point in the history
  • Loading branch information
AmrDeveloper committed Dec 1, 2023
1 parent 3b7e208 commit 7e359ba
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ gitql-parser = { path = "./crates/gitql-parser", version = "0.8.0" }
gitql-engine = { path = "./crates/gitql-engine", version = "0.9.0" }
gitql-cli = { path = "./crates/gitql-cli", version = "0.9.0" }
gix = { workspace = true, features = ["max-performance"] }
atty = "0.2.14"
23 changes: 17 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use atty::Stream;
use gitql_cli::arguments;
use gitql_cli::arguments::Arguments;
use gitql_cli::arguments::Command;
Expand Down Expand Up @@ -36,8 +37,7 @@ fn main() {
arguments::print_help_list();
}
Command::Version => {
let version = env!("CARGO_PKG_VERSION");
println!("GitQL version {}", version);
println!("GitQL version {}", env!("CARGO_PKG_VERSION"));
}
Command::Error(error_mssage) => {
println!("{}", error_mssage);
Expand All @@ -56,13 +56,24 @@ fn launch_gitql_repl(arguments: Arguments) {
let git_repositories = git_repos_result.ok().unwrap();

let mut input = String::new();

loop {
print!("gql > ");
std::io::Write::flush(&mut std::io::stdout()).expect("flush failed!");
// Render Promot only if input is received from terminal
if atty::is(Stream::Stdin) {
print!("gql > ");
}

std::io::Write::flush(&mut std::io::stdout()).expect("flush failed!");
match std::io::stdin().read_line(&mut input) {
Ok(_) => (),
Err(_err) => reporter.report_error("Invalid input"),
Ok(buffer_length) => {
if buffer_length == 0 {
break;
}
}
Err(error) => {
let error_message = format!("Error: {}", error);
reporter.report_error(&error_message)
}
}

let trimed_input = input.trim();
Expand Down

0 comments on commit 7e359ba

Please sign in to comment.