diff --git a/.gitignore b/.gitignore index a65f5c1..5905067 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,9 @@ Cargo.lock .cmake/ .cargo/ + +pretty-git-prompt-*.crate + +# RPM building +SRPMS/ +x86_64/ diff --git a/.packit.yaml b/.packit.yaml index 7660517..76d1a69 100644 --- a/.packit.yaml +++ b/.packit.yaml @@ -1,6 +1,14 @@ --- downstream_package_name: rust-pretty-git-prompt +srpm_build_deps: +- cargo +- rust actions: create-archive: - cargo publish --dry-run --allow-dirty - bash -c "ls -1 target/package/*.crate" +jobs: + - job: copr_build + trigger: pull_request + targets: + - fedora-all diff --git a/Cargo.toml b/Cargo.toml index 4aece50..bec1588 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ name = "pretty-git-prompt" version = "0.2.1" authors = ["Tomas Tomecek "] description = "Your current git repository information inside a beautiful shell prompt." -license-file = "LICENSE" +license = "MIT" documentation = "https://github.com/TomasTomecek/pretty-git-prompt/blob/master/README.md" homepage = "https://github.com/TomasTomecek/pretty-git-prompt" repository = "https://github.com/TomasTomecek/pretty-git-prompt" @@ -14,14 +14,14 @@ path = "src/main.rs" name = "pretty-git-prompt" [dependencies] -yaml-rust = "0.4.2" +yaml-rust = "0.4.5" [dependencies.clap] -version = "3.0" +version = "4.*" default-features = false -features = ["std"] +features = ["std", "cargo"] [dependencies.git2] -version = "0.13" +version = "0.14.*" default-features = false features = [] diff --git a/Makefile b/Makefile index 208bcc4..84ee0d6 100644 --- a/Makefile +++ b/Makefile @@ -36,10 +36,6 @@ exec-stable-build: target/release/pretty-git-prompt exec-nightly-build: target/debug/pretty-git-prompt -export GIT_REPO_IS_DIRTY := $(shell if git diff-index --quiet HEAD -- ; then echo "no"; else echo "yes"; fi) -ifeq ($(origin TRAVIS_COMMIT), undefined) - export TRAVIS_COMMIT := $(shell git rev-parse --short HEAD) -endif target/release/pretty-git-prompt: $(DEPS) LIBZ_SYS_STATIC=1 cargo build --release target/debug/pretty-git-prompt: $(DEPS) diff --git a/rust-pretty-git-prompt.spec b/rust-pretty-git-prompt.spec index 2fdc6fb..b440239 100644 --- a/rust-pretty-git-prompt.spec +++ b/rust-pretty-git-prompt.spec @@ -5,36 +5,44 @@ Name: rust-%{crate} Version: 0.2.1 -Release: 1%{?dist} +Release: %autorelease Summary: Your current git repository information inside a beautiful shell prompt License: MIT URL: https://crates.io/crates/pretty-git-prompt -Source0: https://crates.io/api/v1/crates/%{crate}/%{version}/download#/%{crate}-%{version}.crate +Source0: %{crates_source} ExclusiveArch: %{rust_arches} -BuildRequires: rust-packaging -# [dependencies] -BuildRequires: (crate(clap) >= 2.19.0 with crate(clap) < 3.0.0) -BuildRequires: (crate(git2) >= 0.7.0 with crate(git2) < 0.8.0) -BuildRequires: (crate(yaml-rust) >= 0.3.4 with crate(yaml-rust) < 0.4.0) +BuildRequires: rust-packaging >= 23 %description %{summary}. %package -n %{crate} Summary: %{summary} +# MIT +# MIT AND GPL-2.0-only WITH GCC-exception-2.0 AND BSD-3-Clause +# MIT OR Apache-2.0 +# MIT OR Apache-2.0 OR Zlib +# Zlib OR Apache-2.0 OR MIT +License: MIT AND BSD-3-Clause AND GPL-2.0-only WITH GCC-exception-2.0 AND (MIT OR Apache-2.0) AND (MIT OR Apache-2.0 OR Zlib) +# LICENSE.dependencies contains a full license breakdown %description -n %{crate} %{summary}. %prep -%autosetup -n %{crate}-%{version} -p1 +%autosetup -n %{crate}-%{version_no_tilde} -p1 %cargo_prep +%generate_buildrequires +%cargo_generate_buildrequires + %build %cargo_build +%cargo_license_summary +%{cargo_license} > LICENSE.dependencies %install %cargo_install @@ -47,31 +55,10 @@ Summary: %{summary} %files -n %{crate} %license LICENSE +%license LICENSE.dependencies %doc README.md %doc files %{_bindir}/pretty-git-prompt %changelog -* Mon Apr 06 2020 Tomas Tomecek - 0.2.1-1 -- new upstream release: 0.2.1 - -* Sat Feb 02 2019 Fedora Release Engineering - 0.2.0-7 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild - -* Fri Aug 10 2018 Josh Stone - 0.2.0-6 -- Rebuild with fixed rust-libgit2-sys-0.7.7 - -* Fri Aug 10 2018 Igor Gnatenko - 0.2.0-5 -- Rebuild for libgit2 0.27.x - -* Sat Jul 14 2018 Fedora Release Engineering - 0.2.0-4 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild - -* Mon Mar 12 2018 Igor Gnatenko - 0.2.0-3 -- Bump git2 to 0.7 - -* Fri Feb 09 2018 Fedora Release Engineering - 0.2.0-2 -- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild - -* Sun Jan 28 2018 Igor Gnatenko - 0.2.0-1 -- Initial package +%autochangelog diff --git a/src/constants.rs b/src/constants.rs index ed8bf2a..5d41d36 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -12,8 +12,6 @@ pub static CURRENT_CONFIG_VERSION: &'static str = "1"; pub static DEFAULT_CONFIG_NAME: &'static str = "pretty-git-prompt.yml"; -pub static CLI_DEFAULT_CONFIG_SUBC_NAME: &'static str = "create-default-config"; - pub fn get_default_config_path() -> PathBuf { let mut p = match env::var("XDG_CONFIG_HOME") { Ok(val) => PathBuf::from(&val), diff --git a/src/main.rs b/src/main.rs index 8d6d75a..9e5c249 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,7 @@ use constants::*; use models::{DisplayMaster}; use git2::Repository; -use clap::{App,Arg}; +use clap::{Arg, ArgAction, Command}; // util mod def needs to be first b/c of macro definitions and usage in other modules #[macro_use] @@ -23,97 +23,67 @@ mod conf; mod constants; mod models; - -fn get_version_str() -> String { - let version: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); - let commit: Option<&'static str> = option_env!("TRAVIS_COMMIT"); - let is_dirty: Option<&'static str> = option_env!("GIT_REPO_IS_DIRTY"); - format!( - "{} ({}{})", - match version { - Some(v) => v, - None => "", - }, - match commit { - Some(v) => v, - None => "" - }, - match is_dirty { - Some(_) => ", dirty", - None => "" - } - ) -} - -fn run_app() -> Result<(), String> { - let version = get_version_str(); - let version_ref: &str = version.as_str(); - let def_conf_desc: &str = &format!("Create default config at \"{}\".", get_default_config_path().to_str().unwrap()); - let app = App::new("pretty-git-prompt") - .version(version_ref) +fn main() { + let def_conf_desc: String = format!("Create default config at \"{}\".", get_default_config_path().to_str().unwrap()); + let matches = Command::new("pretty-git-prompt") + .version(option_env!("CARGO_PKG_VERSION")) .author("Tomas Tomecek ") .about("Get `git status` inside your shell prompt.") - .subcommand(App::new(CLI_DEFAULT_CONFIG_SUBC_NAME) - .about(def_conf_desc)) + .subcommand(Command::new("create-default-config") + .about(def_conf_desc)) .arg(Arg::new("config") - .short('c') - .long("config") - .value_name("FILE") - .help("Use the given config file.") - .takes_value(true)) + .short('c') + .long("config") + .value_name("FILE") + .help("Use the given config file.")) .arg(Arg::new("debug") - .short('d') - .long("debug") - .help("Print debug messages, useful for identifying issues.")); - let matches = app.get_matches(); + .short('d') + .long("debug") + .help("Print debug messages, useful for identifying issues.") + .action(ArgAction::SetTrue) + ).get_matches(); - let debug_enabled = matches.is_present("debug"); + let debug_enabled = matches.get_flag("debug"); if debug_enabled { println!("Debug messages are enabled."); } - let conf_path: Option = if matches.is_present("config") { - Some(String::from(matches.value_of("config").unwrap())) - } else { - None - }; - - // create default config command - if matches.is_present(CLI_DEFAULT_CONFIG_SUBC_NAME) { - let p = get_default_config_path(); - match create_default_config(&p) { - Ok(path) => { - println!("Configuration file created at \"{}\"", path); - return Ok(()); - } - Err(e) => { - return Err(format!("Failed to create configuration file \"{}\": {}", p.to_str().unwrap(), e)); - } - }; - } else { - // no command, run primary functionality - let repo = match Repository::discover(".") { - Ok(repo) => repo, - // not a git repository, ignore - Err(e) => { - if debug_enabled { println!("This is not a git repository: {:?}", e); } - return Ok(()); - } - }; - - let backend = Backend::new(repo, debug_enabled); - let dm: DisplayMaster = DisplayMaster::new(backend, debug_enabled); - let mut conf: Conf = get_configuration(conf_path, dm); - let out: String = conf.populate_values(); - println!("{}", out); - } - Ok(()) -} + match matches.subcommand() { + Some(("create-default-config", _sub_matches)) => { + let p = get_default_config_path(); + match create_default_config(&p) { + Ok(path) => { + println!("Configuration file created at \"{}\"", path); + ::std::process::exit(0); + } + Err(e) => { + if let Err(e2) = writeln!( + io::stderr(), + "Failed to create configuration file \"{}\": {}", + p.to_str().unwrap(), + e + ) { + println!("Writing error: {}", e2.to_string()); + } + ::std::process::exit(2); + } + }; + }, + _ => { + // no command, run primary functionality + let repo = match Repository::discover(".") { + Ok(repo) => repo, + // not a git repository, ignore + Err(e) => { + if debug_enabled { println!("This is not a git repository: {:?}", e); } + ::std::process::exit(0); + } + }; -fn main() { - ::std::process::exit(match run_app() { - Ok(_) => 0, - Err(err) => { - writeln!(io::stderr(), "{}", err).unwrap(); - 2 + let backend = Backend::new(repo, debug_enabled); + let dm: DisplayMaster = DisplayMaster::new(backend, debug_enabled); + let conf_path = matches.get_one::("config"); + let mut conf: Conf = get_configuration(conf_path.cloned(), dm); + let out: String = conf.populate_values(); + println!("{}", out); } - }); + } }