Skip to content

Commit

Permalink
feat: use clap to improve usage from cl; make tracing level & config …
Browse files Browse the repository at this point in the history
…file configurable from cl
  • Loading branch information
wzslr321 committed Aug 18, 2024
1 parent b7b259b commit 79a2278
Show file tree
Hide file tree
Showing 4 changed files with 245 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
example/repo/
193 changes: 193 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 @@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.5.16", features = ["derive"] }
config = "0.14.0"
git2 = "0.19.0"
serde = "1.0.208"
Expand Down
52 changes: 50 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,63 @@ mod config;
mod git;
mod utils;

use clap::Parser;
use config::Config;
use git::clone_repo;
use std::error::Error;
use tracing::{error, info, warn, Level};

#[derive(Parser, Debug)]
#[command(
version,
about = "Impactifier is a tool for analyzing code changes and assessing their impact.",
long_about = r#"
Impactifier is an early-stage tool designed to help developers understand the impact of their code changes before they are merged.
It simplifies the process of identifying potential issues and dependencies by analyzing code changes within a repository.
Key features include:
- Analyzing changes to identify potential impacts on other parts of the codebase.
- Integrating with CI/CD pipelines to automate impact analysis on pull requests and commits.
- Configurable to work with different repository setups and trigger actions.
"#
)]
struct Args {
/// Path to the config file.
/// Currently, only .yaml files are supported.
///
/// Example config file can be found at: github.com/impactifier/example
#[arg(short, long, default_value_t = String::from("impactifier-config.yaml"))]
config: String,

/// Sets max tracing level. Available options:
///
/// 0 = Trace
/// 1 = Debug
/// 2 = Info
/// 3 = Warn
/// 4 = Error
#[arg(long, default_value_t = 2)]
tracing_level: u8,
}

fn main() -> Result<(), Box<dyn Error>> {
tracing_subscriber::fmt().with_max_level(Level::DEBUG).init();
let args = Args::parse();

let tracing_level = match args.tracing_level {
0 => Level::TRACE,
1 => Level::DEBUG,
2 => Level::INFO,
3 => Level::WARN,
4 => Level::ERROR,
_ => Level::INFO,
};

tracing_subscriber::fmt()
.with_max_level(tracing_level)
.init();

let configuration_file = "impactifier-config.yaml";
let configuration_file = args.config;
info!("Starting loading config from {}", configuration_file);
let config = match Config::load_from_file(&configuration_file) {
Ok(config) => {
Expand Down

0 comments on commit 79a2278

Please sign in to comment.