chore: add version flag

This commit is contained in:
Jesús Pérez Lorenzo 2021-08-31 23:01:15 +01:00
parent 1588e7bec0
commit 099fe105a3
4 changed files with 56 additions and 40 deletions

1
.gitignore vendored
View File

@ -2,6 +2,7 @@ target
.k .k
OLD OLD
tries tries
home
tmp tmp
# enviroment to load on bin/build # enviroment to load on bin/build
.env .env

65
Cargo.lock generated
View File

@ -3854,7 +3854,38 @@ checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd"
[[package]] [[package]]
name = "zterton" name = "zterton"
version = "0.1.0" version = "0.1.1"
dependencies = [
"anyhow",
"app_auth",
"app_auth_handlers",
"app_env",
"app_errors",
"app_tools",
"async-std",
"async-trait",
"base64",
"clap",
"dotenv",
"envmnt 0.9.0",
"glob",
"json",
"kloud",
"once_cell",
"parking_lot",
"pretty_env_logger",
"serde",
"serde_derive",
"serde_json",
"serde_yaml",
"tempfile",
"thiserror",
"toml",
]
[[package]]
name = "zterton"
version = "0.1.2"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"app_auth", "app_auth",
@ -3874,6 +3905,7 @@ dependencies = [
"casbin", "casbin",
"chrono", "chrono",
"clds", "clds",
"dotenv",
"envmnt 0.9.0", "envmnt 0.9.0",
"futures-util", "futures-util",
"gql_playground", "gql_playground",
@ -3904,34 +3936,3 @@ dependencies = [
"warp", "warp",
"zterton 0.1.1", "zterton 0.1.1",
] ]
[[package]]
name = "zterton"
version = "0.1.1"
dependencies = [
"anyhow",
"app_auth",
"app_auth_handlers",
"app_env",
"app_errors",
"app_tools",
"async-std",
"async-trait",
"base64",
"clap",
"dotenv",
"envmnt 0.9.0",
"glob",
"json",
"kloud",
"once_cell",
"parking_lot",
"pretty_env_logger",
"serde",
"serde_derive",
"serde_json",
"serde_yaml",
"tempfile",
"thiserror",
"toml",
]

View File

@ -1,6 +1,6 @@
[package] [package]
name = "zterton" name = "zterton"
version = "0.1.0" version = "0.1.2"
authors = ["JesusPerez <jpl@jesusperez.pro>"] authors = ["JesusPerez <jpl@jesusperez.pro>"]
edition = "2018" edition = "2018"
publish = false publish = false
@ -25,6 +25,7 @@ base64 = "0.13.0"
bytes = "1.0.1" bytes = "1.0.1"
casbin = "2.0.7" casbin = "2.0.7"
chrono = "0.4.19" chrono = "0.4.19"
dotenv = "0.15.0"
envmnt = "0.9.0" envmnt = "0.9.0"
futures-util = "0.3.14" futures-util = "0.3.14"
http = "0.2.4" http = "0.2.4"

View File

@ -39,9 +39,10 @@ use reqenv::ReqEnv;
// extern crate kloud_entries_macro_derive; // extern crate kloud_entries_macro_derive;
static WEBSERVER: AtomicUsize = AtomicUsize::new(0); static WEBSERVER: AtomicUsize = AtomicUsize::new(0);
const VERSION: &'static str = env!("CARGO_PKG_VERSION"); const PKG_VERSION: &'static str = env!("CARGO_PKG_VERSION");
// const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); // const PKG_VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
const AUTHORS: &'static str = env!("CARGO_PKG_AUTHORS"); const PKG_NAME: &'static str = env!("CARGO_PKG_NAME");
const PKG_AUTHORS: &'static str = env!("CARGO_PKG_AUTHORS");
pub mod defs; pub mod defs;
pub mod graphql; pub mod graphql;
@ -88,8 +89,8 @@ async fn up_web_server() -> Result<()> {
let mut app_env = AppEnv::default(); let mut app_env = AppEnv::default();
app_env.info = AppInfo::new( app_env.info = AppInfo::new(
"Zterton", "Zterton",
format!("version: {}",VERSION), format!("version: {}",PKG_VERSION),
format!("Authors: {}",AUTHORS), format!("Authors: {}",PKG_AUTHORS),
).await; ).await;
println!("Web services: init {} ___________ ", chrono::Utc::now().timestamp()); println!("Web services: init {} ___________ ", chrono::Utc::now().timestamp());
zterton::init_app(&mut app_env,"").await?; zterton::init_app(&mut app_env,"").await?;
@ -285,8 +286,16 @@ pub async fn run_check_clouds() {
pub fn main() -> Result<()> { pub fn main() -> Result<()> {
let args: Vec<String> = std::env::args().collect(); let args: Vec<String> = std::env::args().collect();
// println!("I got {:?} arguments: {:?}.", args.len() - 1, &args[1..]); // println!("I got {:?} arguments: {:?}.", args.len() - 1, &args[1..]);
if args.len() > 1 && ( args[1] == "-h" || args[1] == "--help") { if args.len() > 1 {
println!("{} USAGE: -c config-toml -e env.file",&args[0]); match args[1].as_str() {
"-h" | "--help" =>
println!("{} USAGE: -c config-toml -e env.file",PKG_NAME),
"-v" | "--version" => {
println!("{} version: {}",PKG_NAME,PKG_VERSION);
return Ok(());
},
_ => println!("{}",PKG_NAME),
}
} }
let mut arg_cfg_path = String::from(""); let mut arg_cfg_path = String::from("");
let mut arg_env_path = String::from(""); let mut arg_env_path = String::from("");
@ -297,6 +306,10 @@ pub fn main() -> Result<()> {
arg_env_path=args[idx+1].to_owned(); arg_env_path=args[idx+1].to_owned();
} }
}); });
if !arg_env_path.is_empty() {
let env_path = std::path::Path::new(&arg_env_path);
dotenv::from_path(env_path)?;
}
// assert!(output.is_ok()); // assert!(output.is_ok());
let loop_duration: u64; let loop_duration: u64;
let run_cache: bool; let run_cache: bool;