diff --git a/Cargo.toml b/Cargo.toml index f38f3c403..c7f5d34c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,6 +63,7 @@ typed_index_collection = "1" walkdir = "2" wkt = "0.8" zip = { version = "0.5", default-features = false, features = ["deflate"] } +git-version = "0.3" [[test]] name = "write_netex_france" diff --git a/gtfs2netexfr/Cargo.toml b/gtfs2netexfr/Cargo.toml index 9caeccefa..1e0e457a0 100644 --- a/gtfs2netexfr/Cargo.toml +++ b/gtfs2netexfr/Cargo.toml @@ -23,3 +23,4 @@ slog-stdlog = "4.0" slog-term = "2.4" structopt = "0.3" transit_model = { version = "0.34", path = "../", features = ["proj"] } +lazy_static = "1" diff --git a/gtfs2netexfr/src/main.rs b/gtfs2netexfr/src/main.rs index e6cf74e02..2785fc085 100644 --- a/gtfs2netexfr/src/main.rs +++ b/gtfs2netexfr/src/main.rs @@ -23,8 +23,16 @@ use std::path::PathBuf; use structopt::StructOpt; use transit_model::{read_utils, Result}; +lazy_static::lazy_static! { + pub static ref GIT_VERSION: String = transit_model::binary_full_version(env!("CARGO_PKG_VERSION")); +} + +fn get_version() -> &'static str { + &GIT_VERSION +} + #[derive(Debug, StructOpt)] -#[structopt(name = "gtfs2netexfr", about = "Convert a GTFS to NeTEx France.")] +#[structopt(name = "gtfs2netexfr", about = "Convert a GTFS to NeTEx France.", version = get_version())] struct Opt { /// Input directory. #[structopt(short, long, parse(from_os_str), default_value = ".")] diff --git a/gtfs2ntfs/Cargo.toml b/gtfs2ntfs/Cargo.toml index ecb1c3186..674052f30 100644 --- a/gtfs2ntfs/Cargo.toml +++ b/gtfs2ntfs/Cargo.toml @@ -23,3 +23,4 @@ slog-stdlog = "4.0" slog-term = "2.4" structopt = "0.3" transit_model = { version = "0.34", path = "../" } +lazy_static = "1" diff --git a/gtfs2ntfs/src/main.rs b/gtfs2ntfs/src/main.rs index c3bf5f7e1..4c56af11c 100644 --- a/gtfs2ntfs/src/main.rs +++ b/gtfs2ntfs/src/main.rs @@ -23,8 +23,16 @@ use std::path::PathBuf; use structopt::StructOpt; use transit_model::{read_utils, transfers::generates_transfers, PrefixConfiguration, Result}; +lazy_static::lazy_static! { + pub static ref GIT_VERSION: String = transit_model::binary_full_version(env!("CARGO_PKG_VERSION")); +} + +fn get_version() -> &'static str { + &GIT_VERSION +} + #[derive(Debug, StructOpt)] -#[structopt(name = "gtfs2ntfs", about = "Convert a GTFS to an NTFS.")] +#[structopt(name = "gtfs2ntfs", about = "Convert a GTFS to an NTFS.", version = get_version())] struct Opt { /// Input directory. #[structopt(short, long, parse(from_os_str), default_value = ".")] diff --git a/ntfs2gtfs/Cargo.toml b/ntfs2gtfs/Cargo.toml index 91ebc8575..0860dbbfb 100644 --- a/ntfs2gtfs/Cargo.toml +++ b/ntfs2gtfs/Cargo.toml @@ -23,3 +23,4 @@ slog-stdlog = "4.0" slog-term = "2.4" structopt = "0.3" transit_model = { version = "0.34", path = "../" } +lazy_static = "1" diff --git a/ntfs2gtfs/src/main.rs b/ntfs2gtfs/src/main.rs index 7e185db6f..e86ebc03f 100644 --- a/ntfs2gtfs/src/main.rs +++ b/ntfs2gtfs/src/main.rs @@ -22,8 +22,16 @@ use std::path::PathBuf; use structopt::StructOpt; use transit_model::Result; +lazy_static::lazy_static! { + pub static ref GIT_VERSION: String = transit_model::binary_full_version(env!("CARGO_PKG_VERSION")); +} + +fn get_version() -> &'static str { + &GIT_VERSION +} + #[derive(Debug, StructOpt)] -#[structopt(name = "ntfs2gtfs", about = "Convert an NTFS to a GTFS.")] +#[structopt(name = "ntfs2gtfs", about = "Convert an NTFS to a GTFS.", version = get_version())] struct Opt { /// Input directory. #[structopt(short, long, parse(from_os_str), default_value = ".")] diff --git a/ntfs2netexfr/Cargo.toml b/ntfs2netexfr/Cargo.toml index b913611c4..81fb47786 100644 --- a/ntfs2netexfr/Cargo.toml +++ b/ntfs2netexfr/Cargo.toml @@ -23,3 +23,4 @@ slog-stdlog = "4.0" slog-term = "2.4" structopt = "0.3" transit_model = { version = "0.34", path = "../", features = ["proj"] } +lazy_static = "1" diff --git a/ntfs2netexfr/src/main.rs b/ntfs2netexfr/src/main.rs index d26842d53..8c8f0c216 100644 --- a/ntfs2netexfr/src/main.rs +++ b/ntfs2netexfr/src/main.rs @@ -22,8 +22,16 @@ use std::path::PathBuf; use structopt::StructOpt; use transit_model::Result; +lazy_static::lazy_static! { + pub static ref GIT_VERSION: String = transit_model::binary_full_version(env!("CARGO_PKG_VERSION")); +} + +fn get_version() -> &'static str { + &GIT_VERSION +} + #[derive(Debug, StructOpt)] -#[structopt(name = "ntfs2netexfr", about = "Convert a NTFS to NeTEx France.")] +#[structopt(name = "ntfs2netexfr", about = "Convert a NTFS to NeTEx France.", version = get_version())] struct Opt { /// Input directory. #[structopt(short, long, parse(from_os_str), default_value = ".")] diff --git a/ntfs2ntfs/Cargo.toml b/ntfs2ntfs/Cargo.toml index 3beb7b22f..c624281e3 100644 --- a/ntfs2ntfs/Cargo.toml +++ b/ntfs2ntfs/Cargo.toml @@ -23,3 +23,4 @@ slog-stdlog = "4.0" slog-term = "2.4" structopt = "0.3" transit_model = { version = "0.34", path = "../" } +lazy_static = "1" diff --git a/ntfs2ntfs/src/main.rs b/ntfs2ntfs/src/main.rs index a042708ca..1df03568a 100644 --- a/ntfs2ntfs/src/main.rs +++ b/ntfs2ntfs/src/main.rs @@ -22,8 +22,16 @@ use std::path::PathBuf; use structopt::StructOpt; use transit_model::{transfers::generates_transfers, Result}; +lazy_static::lazy_static! { + pub static ref GIT_VERSION: String = transit_model::binary_full_version(env!("CARGO_PKG_VERSION")); +} + +fn get_version() -> &'static str { + &GIT_VERSION +} + #[derive(Debug, StructOpt)] -#[structopt(name = "ntfs2ntfs", about = "Convert an NTFS to an NTFS.")] +#[structopt(name = "ntfs2ntfs", about = "Convert an NTFS to an NTFS.", version = get_version())] struct Opt { /// Input directory. #[structopt(short = "i", long = "input", parse(from_os_str), default_value = ".")] diff --git a/src/lib.rs b/src/lib.rs index 8024f2318..1fa25da76 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -56,6 +56,7 @@ pub mod read_utils; pub mod test_utils; pub mod transfers; pub mod validity_period; +mod version_utils; pub mod vptranslator; /// Current version of the NTFS format @@ -82,3 +83,5 @@ pub type Error = failure::Error; pub type Result = std::result::Result; pub use crate::model::Model; + +pub use crate::version_utils::{binary_full_version, GIT_VERSION}; diff --git a/src/version_utils.rs b/src/version_utils.rs new file mode 100644 index 000000000..dceddc972 --- /dev/null +++ b/src/version_utils.rs @@ -0,0 +1,25 @@ +// Copyright (C) 2017 Kisio Digital and/or its affiliates. +// +// This program is free software: you can redistribute it and/or modify it +// under the terms of the GNU Affero General Public License as published by the +// Free Software Foundation, version 3. + +// This program is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +// FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more +// details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see +//! Some utility to get the transit_model version + +/// Precise git version of transit_model +/// the version will be: +/// v{last github tag}-{commit number}-{commit hash}{"-modified" if some changes have been done since last commit} +pub const GIT_VERSION: &str = + git_version::git_version!(args = ["--tags", "--dirty=-modified"], fallback = "unknown"); + +/// get the binary version and the transit_model version +pub fn binary_full_version(binary_version: &str) -> String { + format!("{} (transit_model = {})", binary_version, GIT_VERSION) +}