mirror of https://github.com/raftario/filite.git
Add init command (closes #7)
This commit is contained in:
parent
5bb1fc46e0
commit
7dcf7c3746
|
@ -18,7 +18,8 @@ lazy_static! {
|
|||
|
||||
#[cfg(not(feature = "dev"))]
|
||||
lazy_static! {
|
||||
pub static ref CONFIG: crate::setup::Config = crate::setup::init();
|
||||
pub static ref CONFIG: crate::setup::Config =
|
||||
crate::setup::init(std::env::args().any(|a| &a == "init"));
|
||||
pub static ref PASSWORD_HASH: Vec<u8> = {
|
||||
let password_path = crate::setup::get_password_path();
|
||||
std::fs::read(&password_path).unwrap_or_else(|e| {
|
||||
|
|
16
src/setup.rs
16
src/setup.rs
|
@ -252,14 +252,14 @@ pub fn logger_middleware() -> Logger {
|
|||
|
||||
/// Performs the initial setup
|
||||
#[cfg(not(feature = "dev"))]
|
||||
pub fn init() -> Config {
|
||||
pub fn init(init: bool) -> Config {
|
||||
fs::create_dir_all(get_config_dir()).unwrap_or_else(|e| {
|
||||
eprintln!("Can't create config directory: {}.", e);
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
let password_path = get_password_path();
|
||||
if !password_path.exists() {
|
||||
if init {
|
||||
let mut password;
|
||||
loop {
|
||||
password = PasswordInput::new()
|
||||
|
@ -294,19 +294,27 @@ pub fn init() -> Config {
|
|||
eprintln!("Can't write password: {}", e);
|
||||
process::exit(1);
|
||||
});
|
||||
} else if !get_password_path().exists() {
|
||||
eprintln!("No password file found. Try running `filite init`.");
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
let config_path = get_config_path();
|
||||
if !config_path.exists() {
|
||||
if init {
|
||||
println!("Generating config file at {}", config_path.display());
|
||||
let config = Config::default();
|
||||
config.write_file().unwrap_or_else(|e| {
|
||||
eprintln!("Can't write config file: {}", e);
|
||||
process::exit(1);
|
||||
});
|
||||
return config;
|
||||
} else if !config_path.exists() {
|
||||
eprintln!("No config file found. Try running `filite init`.");
|
||||
process::exit(1);
|
||||
}
|
||||
|
||||
if init {
|
||||
process::exit(0);
|
||||
}
|
||||
Config::read_file().unwrap_or_else(|e| {
|
||||
eprintln!("{}", e);
|
||||
process::exit(1);
|
||||
|
|
Loading…
Reference in New Issue