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