Compare commits
No commits in common. "05fb399530c4e9c3f06b909b5e57a1aa85242a07" and "62617473bda9c86ded6a0951574bfa93e17c7a0e" have entirely different histories.
05fb399530
...
62617473bd
|
|
@ -7,7 +7,6 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
chrono = "0.4.26"
|
||||
clap = { version = "4.5.1", features = ["derive"] }
|
||||
comrak = "0.18.0"
|
||||
figment = { version = "0.10.10", features = ["env", "serde_json", "json"] }
|
||||
regex = "1.8.4"
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
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,
|
||||
}
|
||||
56
src/main.rs
56
src/main.rs
|
|
@ -1,10 +1,6 @@
|
|||
mod cli;
|
||||
mod config;
|
||||
mod todo;
|
||||
|
||||
use crate::cli::Args;
|
||||
use clap::Parser;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::todo::File as TodoFile;
|
||||
use crate::todo::{Status as TaskStatus, TaskGroup};
|
||||
|
|
@ -15,25 +11,19 @@ use comrak::{parse_document, Arena};
|
|||
use comrak::{ComrakExtensionOptions, ComrakOptions, ComrakParseOptions};
|
||||
use std::borrow::Borrow;
|
||||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs::{create_dir_all, metadata, read, read_dir, File};
|
||||
use std::io::{self, Write};
|
||||
use std::io::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::process::Command;
|
||||
use std::{env, str};
|
||||
use std::str;
|
||||
|
||||
//TODO handle unwraps and errors more uniformly
|
||||
//TODO refactor creating new file
|
||||
//TODO clean up verbose printing
|
||||
//TODO create custom errors for better error handling
|
||||
//TODO Default path for note_dir should start with curent path not home
|
||||
|
||||
#[derive(Debug)]
|
||||
enum ExitError {
|
||||
ConfigError(String),
|
||||
IOError(String, io::Error),
|
||||
}
|
||||
|
||||
fn main() -> Result<(), ExitError> {
|
||||
fn main() {
|
||||
let expected_cfg_files = Config::expected_locations().unwrap();
|
||||
println!("{:#?}", expected_cfg_files);
|
||||
let cfg_files: Vec<&Path> = expected_cfg_files
|
||||
|
|
@ -46,10 +36,7 @@ fn main() -> Result<(), ExitError> {
|
|||
if cfg_files.len() <= 0 {
|
||||
let status = Config::write_default(expected_cfg_files[0].to_str().unwrap());
|
||||
if let Err(e) = status {
|
||||
return Err(ExitError::ConfigError(format!(
|
||||
"Could not write to default cfg location: {:#?}",
|
||||
e
|
||||
)));
|
||||
println!("Could not write to default cfg location: {:#?}", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -61,27 +48,18 @@ fn main() -> Result<(), ExitError> {
|
|||
let cfg = Config::load(cfg_file).unwrap();
|
||||
|
||||
println!("{:#?}", cfg);
|
||||
let data_dir = match &cfg.notes_dir {
|
||||
Some(dir) => get_data_dir(dir),
|
||||
_ => {
|
||||
return Err(ExitError::ConfigError(
|
||||
"Could not get notes dir from config".to_string(),
|
||||
))
|
||||
}
|
||||
};
|
||||
|
||||
let data_dir = get_data_dir(
|
||||
&cfg.notes_dir
|
||||
.clone()
|
||||
.expect("Could not get notes dir from config"),
|
||||
);
|
||||
if !metadata(&data_dir).is_ok() {
|
||||
match create_dir_all(&data_dir) {
|
||||
Err(e) => {
|
||||
return Err(ExitError::IOError(
|
||||
format!(
|
||||
"Could not create defult directory: {}",
|
||||
&data_dir.to_str().unwrap(),
|
||||
),
|
||||
e,
|
||||
))
|
||||
}
|
||||
_ => (),
|
||||
if let Err(e) = create_dir_all(&data_dir) {
|
||||
println!(
|
||||
"Could not create defult directory({}): {:#?}",
|
||||
&data_dir.to_str().unwrap(),
|
||||
e
|
||||
);
|
||||
};
|
||||
}
|
||||
println!("dir = {}", data_dir.to_str().unwrap());
|
||||
|
|
@ -148,8 +126,6 @@ fn main() -> Result<(), ExitError> {
|
|||
.args([current_file])
|
||||
.status()
|
||||
.expect(format!("failed to launch editor {}", "vim").as_str());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_filepath(data_dir: &PathBuf, date: &NaiveDate) -> PathBuf {
|
||||
|
|
|
|||
Loading…
Reference in New Issue