1
0
mirror of https://github.com/jht5945/rust_util.git synced 2026-01-13 15:50:05 +08:00

Compare commits

..

2 Commits

Author SHA1 Message Date
4b39ac48fd feat: add git_rev_parse_head 2021-01-24 22:38:19 +08:00
cb1b8187fa feat: update dependency version, add clap run_with 2021-01-24 22:31:11 +08:00
3 changed files with 19 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
[package] [package]
name = "rust_util" name = "rust_util"
version = "0.6.27" version = "0.6.29"
authors = ["Hatter Jiang <jht5945@gmail.com>"] authors = ["Hatter Jiang <jht5945@gmail.com>"]
edition = "2018" edition = "2018"
description = "Hatter's Rust Util" description = "Hatter's Rust Util"
@@ -13,10 +13,10 @@ default = [] #["serde", "serde_json"]
use_clap = ["clap"] use_clap = ["clap"]
[dependencies] [dependencies]
libc = "0.2.65" libc = "0.2.82"
term = "0.5.2" term = "0.7.0"
term_size = "0.3.1" term_size = "0.3.2"
lazy_static = "1.3.0" lazy_static = "1.4.0"
clap = { version = "2.0", optional = true } clap = { version = "2.0", optional = true }
# serde = { version = "1.0", features = ["derive"], optional = true } # serde = { version = "1.0", features = ["derive"], optional = true }
# serde_json = { version = "1.0", optional = true } # serde_json = { version = "1.0", optional = true }

View File

@@ -59,9 +59,13 @@ impl CommandExecutor {
} }
pub fn run(&self) -> XResult<()> { pub fn run(&self) -> XResult<()> {
let mut app = App::new(env!("CARGO_PKG_NAME")) let app = App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION")) .version(env!("CARGO_PKG_VERSION"))
.about(env!("CARGO_PKG_DESCRIPTION")); .about(env!("CARGO_PKG_DESCRIPTION"));
self.run_with(app)
}
pub fn run_with<'a>(&self, mut app: App<'a, 'a>) -> XResult<()> {
if let Some(default_cmd) = &self.default_cmd { if let Some(default_cmd) = &self.default_cmd {
app = default_cmd.process_command(app); app = default_cmd.process_command(app);
} }

View File

@@ -25,6 +25,15 @@ pub fn git_status_change(working_dir: Option<&str>) -> XResult<GitStatusChange>
parse_git_status_change(&git_status) parse_git_status_change(&git_status)
} }
pub fn git_rev_parse_head(working_dir: Option<&str>) -> XResult<String> {
let mut cmd = new_git_command(working_dir);
cmd.args(vec!["rev-parse", "HEAD"]);
util_msg::print_info(&format!("Exec: {:?}", cmd));
let output = cmd.output()?;
let rev_parse_head = String::from_utf8(output.stdout)?;
Ok(rev_parse_head.trim().to_string())
}
pub fn git_fetch_dry_run(working_dir: Option<&str>) -> XResult<bool> { pub fn git_fetch_dry_run(working_dir: Option<&str>) -> XResult<bool> {
let mut cmd = new_git_command(working_dir); let mut cmd = new_git_command(working_dir);
cmd.args(vec!["fetch", "--dry-run"]); cmd.args(vec!["fetch", "--dry-run"]);