Compare commits
2 Commits
62617473bd
...
05fb399530
| Author | SHA1 | Date |
|---|---|---|
|
|
05fb399530 | |
|
|
695e31c7e4 |
|
|
@ -7,6 +7,7 @@ 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"
|
||||||
|
|
|
||||||
|
|
@ -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,
|
||||||
|
}
|
||||||
56
src/main.rs
56
src/main.rs
|
|
@ -1,6 +1,10 @@
|
||||||
|
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};
|
||||||
|
|
@ -11,19 +15,25 @@ 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::Write;
|
use std::io::{self, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::str;
|
use std::{env, 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
|
||||||
|
|
||||||
fn main() {
|
#[derive(Debug)]
|
||||||
|
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
|
||||||
|
|
@ -36,7 +46,10 @@ fn main() {
|
||||||
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
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,18 +61,27 @@ fn main() {
|
||||||
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(
|
||||||
&data_dir.to_str().unwrap(),
|
format!(
|
||||||
e
|
"Could not create defult directory: {}",
|
||||||
);
|
&data_dir.to_str().unwrap(),
|
||||||
|
),
|
||||||
|
e,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
println!("dir = {}", data_dir.to_str().unwrap());
|
println!("dir = {}", data_dir.to_str().unwrap());
|
||||||
|
|
@ -126,6 +148,8 @@ fn main() {
|
||||||
.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