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

Commit

Permalink
0.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dejankos committed May 14, 2020
1 parent 240278e commit cee1825
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 177 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gm-utils"
version = "0.1.1"
version = "0.1.2"
authors = ["Dejan Kos <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -12,7 +12,8 @@ description = "Cli tool for managing git branch and maven project version at the
structopt = "0.3"
roxmltree = "0.7.3"
exitcode = "1.1.2"
colored = "1.8"
simplelog = "0.7.6"
log = "0.4.8"

[[bin]]
name = "gm"
Expand Down
30 changes: 16 additions & 14 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Although there is a lot of options for this [use case](https://stackoverflow.com
## Usage
```
~> gm --help
gm-utils 0.1.1
gm-utils 0.1.2
USAGE:
gm [FLAGS] [new-version]
Expand All @@ -32,24 +32,26 @@ Although there is a lot of options for this [use case](https://stackoverflow.com
## Examples
Change git branch and maven project version from project root:
```
>gm test123
Checking if branch test123 already exists...
Creating new git branch test123 from master
Branch test123 successfully created from master
Current mvn project version 0.0.1-SNAPSHOT
Changing mvn project version to 0.0.1-test123-SNAPSHOT
Done
>gm test123 -d
18:17:09 [DEBUG] (1) gm::app: Received cli args = CliArgs { new_version: Some("test123"), debug: true, reset: false }
18:17:09 [DEBUG] (1) gm::app: Checking git is installed...
18:17:09 [DEBUG] (1) gm::app: Git installed.
18:17:09 [DEBUG] (1) gm::app: Checking maven is installed...
18:17:09 [DEBUG] (1) gm::app: Maven installed.
18:17:09 [DEBUG] (1) gm::app: Project working dir = "/home/user/current_project"
18:17:09 [ INFO] Creating new git branch test123 from master
18:17:09 [ INFO] Branch test successfully created from master
18:17:09 [ INFO] Current mvn project version 0.0.1-SNAPSHOT
18:17:09 [ INFO] Changing mvn project version to 0.0.1-test123-SNAPSHOT
18:17:11 [ INFO] Done
```

Reset version:
```
> gm -r
Current mvn project version 0.0.1-test123-SNAPSHOT
Changing mvn project version to 0.0.1-SNAPSHOT
Done
18:23:27 [ INFO] Current mvn project version 0.0.1-test123-SNAPSHOT
18:23:27 [ INFO] Changing mvn project version to 0.0.1-SNAPSHOT
18:23:28 [ INFO] Done
```

For debug output set flag `-d`.
Expand Down
24 changes: 10 additions & 14 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,30 @@
use std::{env, io};

use crate::git_utils::Git;
use crate::log::Logger;
use crate::mvn_utils::Mvn;
use crate::mvn_utils::{reset_version, set_new_version};
use crate::{validation, CliArgs};

pub fn run(args: &CliArgs) -> io::Result<()> {
let log = Logger::new(args.debug, "app");

validation::validate_args(&args)?;
log.f_debug("Received cli args = ", &args);
debug!("Received cli args = {:?}", &args);

log.debug("Checking git is installed...");
debug!("Checking git is installed...");
validation::git_available()?;
log.debug("Git installed.");
debug!("Git installed");

log.debug("Checking maven is installed...");
debug!("Checking maven is installed...");
validation::mvn_available()?;
log.debug("Maven installed.");
debug!("Maven installed");

let path = env::current_dir()?;
log.f_debug("Project working dir =", &path);
debug!("Project working dir = {:?}", &path);

let mvn = Mvn::new(&args);
if let Some(ver) = &args.new_version {
let git = Git::open(path.clone(), &args)?;
let git = Git::open(path.clone())?;
git.new_branch(ver)?;
mvn.set_new_version(ver, path.clone())?;
set_new_version(ver, path.clone())?;
} else if args.reset {
mvn.reset_version(path.clone())?;
reset_version(path.clone())?;
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/file_utils.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use io::Result;
use std::ffi::{OsString};
use std::ffi::OsString;
use std::fs::read_dir;
use std::path::PathBuf;
use std::{fs, io};
Expand Down
32 changes: 6 additions & 26 deletions src/git_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,12 @@ use std::io::{Error, ErrorKind};
use std::path::PathBuf;
use std::process::{Command, Output};

use crate::log::Logger;
use crate::CliArgs;

const ERR_MSG: &str = "Error executing git command";

pub struct Git {
log: Logger,
repository: Repository,
}

#[derive(Debug)]
pub struct Repository {
project_path: PathBuf,
}
Expand All @@ -39,35 +34,20 @@ impl OutputHandler for Output {
}

impl Git {
pub fn open(project_path: PathBuf, args: &CliArgs) -> Result<Self> {
pub fn open(project_path: PathBuf) -> Result<Self> {
let repo = Repository::open(project_path)?;
Ok(Git {
log: Logger::new(args.debug, "git-utils"),
repository: repo,
})
Ok(Git { repository: repo })
}

pub fn new_branch(&self, b_name: &str) -> Result<()> {
self.log
.info(format!("Checking if branch {} already exists...", b_name).as_str());
self.repository.branch_exists(b_name)?;

let current_branch = self.repository.current_branch()?;
self.log.info(
format!(
"Creating new git branch {} from {} ",
b_name, current_branch
)
.as_str(),
);
info!("Creating new git branch {} from {}", b_name, current_branch);

self.repository.new_branch(b_name, current_branch.trim())?;
self.log.info(
format!(
"Branch {} successfully created from {}",
b_name, current_branch
)
.as_str(),
info!(
"Branch {} successfully created from {}",
b_name, current_branch,
);

Ok(())
Expand Down
34 changes: 0 additions & 34 deletions src/log.rs

This file was deleted.

22 changes: 16 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#[macro_use]
extern crate log;
extern crate simplelog;

use std::process::exit;

use exitcode::{OK, USAGE};
use simplelog::{Config, LevelFilter, TermLogger, TerminalMode};
use structopt::StructOpt;

use crate::log::Logger;

mod app;
mod file_utils;
mod git_utils;
mod log;
mod mvn_utils;
mod validation;

Expand All @@ -24,15 +26,23 @@ pub struct CliArgs {

fn main() {
let args = CliArgs::from_args();
let log = Logger::new(args.debug, "main");
TermLogger::init(log_lvl(args.debug), Config::default(), TerminalMode::Mixed).unwrap();
match app::run(&args) {
Ok(_) => {
log.info("Done");
info!("Done");
exit(OK);
}
Err(e) => {
log.error(&e);
error!("{}", &e);
exit(USAGE);
}
}
}

fn log_lvl(debug: bool) -> LevelFilter {
if debug {
LevelFilter::Debug
} else {
LevelFilter::Info
}
}
Loading

0 comments on commit cee1825

Please sign in to comment.