Skip to content

Commit

Permalink
Add debug logging support
Browse files Browse the repository at this point in the history
  • Loading branch information
Timmmm committed Dec 17, 2021
1 parent dc2611b commit ce3c0f6
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 1 deletion.
81 changes: 81 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ repository = "https://github.com/Timmmm/autorebase"
anyhow = "1.0.40"
argh = "0.1.4"
colored = "2.0.0"
env_logger = "0.9.0"
git_commands = { path = "git_commands", version = "0.2.0" }
log = "0.4.14"
serde = { version = "1.0", features = ["derive"] }
toml = "0.5"

Expand Down
1 change: 1 addition & 0 deletions git_commands/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ description = "Internal crate for autorebase"
[dependencies]
anyhow = "1.0.40"
colored = "2.0.0"
log = "0.4.14"
5 changes: 4 additions & 1 deletion git_commands/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

use std::{io, fmt, path::Path, process::{self, Command}};
use colored::*;
use log::{debug};

// Define our error types. These may be customized for our error handling cases.
// Now we will be able to write our own errors, defer to an underlying error
Expand Down Expand Up @@ -59,7 +60,7 @@ pub fn git(args: &[&str], working_dir: &Path) -> Result<process::Output, Error>
}

pub fn git_internal(args: &[&str], working_dir: Option<&Path>) -> Result<process::Output, Error> {
// eprintln!("{} $ {} {}", working_dir.unwrap_or(Path::new("")).to_string_lossy(), "git".bold(), args.join(" ").bold());
debug!("{} $ {} {}", working_dir.unwrap_or(Path::new("")).to_string_lossy(), "git".bold(), args.join(" ").bold());

let mut command = Command::new("git");
if let Some(working_dir) = working_dir {
Expand All @@ -70,6 +71,8 @@ pub fn git_internal(args: &[&str], working_dir: Option<&Path>) -> Result<process
.args(args)
.output()?;

debug!("{:?}", output);

if !output.status.success() {
return Err(Error::Process(ProcessError {
output,
Expand Down
8 changes: 8 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@ struct CliOptions {
/// the target branch to pull and rebase onto (typically "master" or "develop")
#[argh(option, default = "String::from(\"master\")")]
onto: String,

/// if there are conflicts, try rebasing commit by commit backwards from the
/// target, instead of trying to determind the conflicting commit on the
/// target branch directly
#[argh(switch)]
slow: bool,

/// include branches which have an upstream, the default is to exclude these
#[argh(switch)]
all_branches: bool,

/// RUST_LOG-style logging string, e.g. --log debug
#[argh(option)]
log: Option<String>,
}

fn main() -> Result<()> {
Expand All @@ -37,6 +43,8 @@ fn main() -> Result<()> {
fn run() -> Result<()> {
let options: CliOptions = argh::from_env();

env_logger::Builder::new().parse_filters(&options.log.unwrap_or_default()).init();

autorebase(
&current_dir()?,
&options.onto,
Expand Down

0 comments on commit ce3c0f6

Please sign in to comment.