add streaming flag
This commit is contained in:
parent
f8a773fa63
commit
f268a07764
4 changed files with 67 additions and 30 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -115,7 +115,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "giterator"
|
name = "giterator"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term",
|
"ansi_term",
|
||||||
"clap",
|
"clap",
|
||||||
|
|
11
Cargo.toml
11
Cargo.toml
|
@ -1,9 +1,14 @@
|
||||||
[package]
|
[package]
|
||||||
name = "giterator"
|
name = "giterator"
|
||||||
version = "0.1.0"
|
version = "0.2.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
authors = ["JMARyA <jmarya@hydrar.de>"]
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
description = "A versatile command-line tool for iterating over Git commit histories."
|
||||||
|
license = "MIT"
|
||||||
|
repository = "https://git.hydrar.de/jmarya/giterator"
|
||||||
|
homepage = "https://git.hydrar.de/jmarya/giterator"
|
||||||
|
documentation = "https://git.hydrar.de/jmarya/giterator/blob/main/README.md"
|
||||||
|
keywords = ["git", "iteration", "command-line", "tool"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ansi_term = "0.12.1"
|
ansi_term = "0.12.1"
|
||||||
|
|
|
@ -33,6 +33,13 @@ pub fn get_args() -> ArgMatches {
|
||||||
.num_args(0)
|
.num_args(0)
|
||||||
.required(false),
|
.required(false),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
clap::Arg::new("streaming")
|
||||||
|
.long("streaming")
|
||||||
|
.help("Output results as soon as they are available")
|
||||||
|
.num_args(0)
|
||||||
|
.required(false),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
clap::Arg::new("csv")
|
clap::Arg::new("csv")
|
||||||
.short('c')
|
.short('c')
|
||||||
|
|
29
src/main.rs
29
src/main.rs
|
@ -171,6 +171,7 @@ impl OutMode {
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = args::get_args();
|
let args = args::get_args();
|
||||||
|
|
||||||
|
let streaming = args.get_flag("streaming");
|
||||||
let repo = args.get_one::<String>("repository").unwrap();
|
let repo = args.get_one::<String>("repository").unwrap();
|
||||||
let allow_dirty = args.get_flag("allow-dirty");
|
let allow_dirty = args.get_flag("allow-dirty");
|
||||||
let command = if args.get_flag("script_file") {
|
let command = if args.get_flag("script_file") {
|
||||||
|
@ -184,11 +185,34 @@ fn main() {
|
||||||
|
|
||||||
if is_repository_clean(repo) || allow_dirty {
|
if is_repository_clean(repo) || allow_dirty {
|
||||||
let commits = get_commit_list(repo).unwrap();
|
let commits = get_commit_list(repo).unwrap();
|
||||||
|
|
||||||
|
if streaming && matches!(outmode, OutMode::Csv) {
|
||||||
|
let mut wtr = csv::Writer::from_writer(std::io::stdout());
|
||||||
|
|
||||||
|
wtr.write_record([
|
||||||
|
"repo", "hash", "datetime", "name", "status", "stdout", "stderr",
|
||||||
|
])
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
for commit in commits {
|
for commit in commits {
|
||||||
out.push(commit.run_command(&command));
|
let commit_out = commit.run_command(&command);
|
||||||
|
if streaming {
|
||||||
|
match outmode {
|
||||||
|
OutMode::Text => commit_out.print_text(),
|
||||||
|
OutMode::Json => println!("{}", commit_out.as_json()),
|
||||||
|
OutMode::Csv => {
|
||||||
|
let mut wtr = csv::Writer::from_writer(std::io::stdout());
|
||||||
|
wtr.write_record(&commit_out.as_csv()).unwrap();
|
||||||
|
wtr.flush().unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.push(commit_out);
|
||||||
}
|
}
|
||||||
checkout(repo, "main").unwrap();
|
checkout(repo, "main").unwrap();
|
||||||
|
|
||||||
|
if !streaming {
|
||||||
match outmode {
|
match outmode {
|
||||||
OutMode::Text => {
|
OutMode::Text => {
|
||||||
for i in out {
|
for i in out {
|
||||||
|
@ -218,7 +242,8 @@ fn main() {
|
||||||
wtr.flush().unwrap();
|
wtr.flush().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("Repository is not clean. If you want to allow operating over an unclean repository, pass the `--allow-dirty` flag.");
|
eprintln!("{}: Repository is not clean. If you want to allow operating over an unclean repository, pass the {} flag.", Color::Red.paint("Error"), Color::Blue.paint("`--allow-dirty`"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue