added cli interface options and some error msgs
This commit is contained in:
parent
695e31c7e4
commit
05fb399530
|
|
@ -0,0 +1,13 @@
|
||||||
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
|
#[derive(Parser, Debug)]
|
||||||
|
#[command(version, about)]
|
||||||
|
pub struct Args {
|
||||||
|
/// set config file to use
|
||||||
|
#[arg(short, long, value_name = "FILE")]
|
||||||
|
pub config: Option<String>,
|
||||||
|
|
||||||
|
/// show current config file
|
||||||
|
#[arg(short = 'C', long)]
|
||||||
|
pub current_config: bool,
|
||||||
|
}
|
||||||
42
src/main.rs
42
src/main.rs
|
|
@ -15,13 +15,8 @@ use comrak::{parse_document, Arena};
|
||||||
use comrak::{ComrakExtensionOptions, ComrakOptions, ComrakParseOptions};
|
use comrak::{ComrakExtensionOptions, ComrakOptions, ComrakParseOptions};
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
<<<<<<< Updated upstream
|
|
||||||
use std::env;
|
|
||||||
use std::fs::{create_dir_all, metadata, read, read_dir, File};
|
use std::fs::{create_dir_all, metadata, read, read_dir, File};
|
||||||
=======
|
use std::io::{self, Write};
|
||||||
use std::fs::{read, read_dir, File};
|
|
||||||
>>>>>>> Stashed changes
|
|
||||||
use std::io::Write;
|
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::{env, str};
|
use std::{env, str};
|
||||||
|
|
@ -35,6 +30,7 @@ use std::{env, str};
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
enum ExitError {
|
enum ExitError {
|
||||||
ConfigError(String),
|
ConfigError(String),
|
||||||
|
IOError(String, io::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), ExitError> {
|
fn main() -> Result<(), ExitError> {
|
||||||
|
|
@ -50,7 +46,10 @@ fn main() -> Result<(), ExitError> {
|
||||||
if cfg_files.len() <= 0 {
|
if cfg_files.len() <= 0 {
|
||||||
let status = Config::write_default(expected_cfg_files[0].to_str().unwrap());
|
let status = Config::write_default(expected_cfg_files[0].to_str().unwrap());
|
||||||
if let Err(e) = status {
|
if let Err(e) = status {
|
||||||
println!("Could not write to default cfg location: {:#?}", e);
|
return Err(ExitError::ConfigError(format!(
|
||||||
|
"Could not write to default cfg location: {:#?}",
|
||||||
|
e
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,18 +61,27 @@ fn main() -> Result<(), ExitError> {
|
||||||
let cfg = Config::load(cfg_file).unwrap();
|
let cfg = Config::load(cfg_file).unwrap();
|
||||||
|
|
||||||
println!("{:#?}", cfg);
|
println!("{:#?}", cfg);
|
||||||
let data_dir = get_data_dir(
|
let data_dir = match &cfg.notes_dir {
|
||||||
&cfg.notes_dir
|
Some(dir) => get_data_dir(dir),
|
||||||
.clone()
|
_ => {
|
||||||
.expect("Could not get notes dir from config"),
|
return Err(ExitError::ConfigError(
|
||||||
);
|
"Could not get notes dir from config".to_string(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if !metadata(&data_dir).is_ok() {
|
if !metadata(&data_dir).is_ok() {
|
||||||
if let Err(e) = create_dir_all(&data_dir) {
|
match create_dir_all(&data_dir) {
|
||||||
println!(
|
Err(e) => {
|
||||||
"Could not create defult directory({}): {:#?}",
|
return Err(ExitError::IOError(
|
||||||
|
format!(
|
||||||
|
"Could not create defult directory: {}",
|
||||||
&data_dir.to_str().unwrap(),
|
&data_dir.to_str().unwrap(),
|
||||||
e
|
),
|
||||||
);
|
e,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
println!("dir = {}", data_dir.to_str().unwrap());
|
println!("dir = {}", data_dir.to_str().unwrap());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue