implementing arguments for configs
This commit is contained in:
parent
05fb399530
commit
875ea1e53e
|
|
@ -1,4 +1,4 @@
|
||||||
use clap::{Parser, Subcommand};
|
use clap::Parser;
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(version, about)]
|
#[command(version, about)]
|
||||||
|
|
|
||||||
27
src/main.rs
27
src/main.rs
|
|
@ -13,7 +13,6 @@ use chrono::{Datelike, Local};
|
||||||
use comrak::nodes::{AstNode, NodeValue};
|
use comrak::nodes::{AstNode, NodeValue};
|
||||||
use comrak::{parse_document, Arena};
|
use comrak::{parse_document, Arena};
|
||||||
use comrak::{ComrakExtensionOptions, ComrakOptions, ComrakParseOptions};
|
use comrak::{ComrakExtensionOptions, ComrakOptions, ComrakParseOptions};
|
||||||
use std::borrow::Borrow;
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
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::{self, Write};
|
||||||
|
|
@ -34,14 +33,14 @@ enum ExitError {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), ExitError> {
|
fn main() -> Result<(), ExitError> {
|
||||||
|
let args = Args::parse();
|
||||||
|
|
||||||
let expected_cfg_files = Config::expected_locations().unwrap();
|
let expected_cfg_files = Config::expected_locations().unwrap();
|
||||||
println!("{:#?}", expected_cfg_files);
|
|
||||||
let cfg_files: Vec<&Path> = expected_cfg_files
|
let cfg_files: Vec<&Path> = expected_cfg_files
|
||||||
.iter()
|
.iter()
|
||||||
.map(|file| Path::new(file))
|
.map(|file| Path::new(file))
|
||||||
.filter(|file| file.exists())
|
.filter(|file| file.exists())
|
||||||
.collect();
|
.collect();
|
||||||
println!("{:#?}", cfg_files);
|
|
||||||
|
|
||||||
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());
|
||||||
|
|
@ -53,12 +52,20 @@ fn main() -> Result<(), ExitError> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let cfg_file = match cfg_files.last() {
|
let cfg_file = match args.config {
|
||||||
None => expected_cfg_files[0].to_str().unwrap(),
|
Some(file) => file,
|
||||||
Some(file) => file.to_str().unwrap(),
|
None => match cfg_files.last() {
|
||||||
|
None => expected_cfg_files[0].to_string_lossy().to_string(),
|
||||||
|
Some(file) => file.to_string_lossy().to_string(),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let cfg = Config::load(cfg_file).unwrap();
|
if args.current_config {
|
||||||
|
println!("{}", &cfg_file);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let cfg = Config::load(&cfg_file).unwrap();
|
||||||
|
|
||||||
println!("{:#?}", cfg);
|
println!("{:#?}", cfg);
|
||||||
let data_dir = match &cfg.notes_dir {
|
let data_dir = match &cfg.notes_dir {
|
||||||
|
|
@ -131,9 +138,7 @@ fn main() -> Result<(), ExitError> {
|
||||||
let data = sections
|
let data = sections
|
||||||
.iter()
|
.iter()
|
||||||
.map(|sec| TaskGroup::empty(sec.clone(), 2))
|
.map(|sec| TaskGroup::empty(sec.clone(), 2))
|
||||||
.collect();
|
.collect(); let content = generate_file_content(&data, &today);
|
||||||
|
|
||||||
let content = generate_file_content(&data, &today);
|
|
||||||
let file_path = get_filepath(&data_dir, &today);
|
let file_path = get_filepath(&data_dir, &today);
|
||||||
write_file(&file_path, &content);
|
write_file(&file_path, &content);
|
||||||
file_path
|
file_path
|
||||||
|
|
@ -220,7 +225,7 @@ fn extract_secitons<'a>(
|
||||||
}
|
}
|
||||||
|
|
||||||
let first_child_ref = &node.first_child();
|
let first_child_ref = &node.first_child();
|
||||||
let first_child = if let Some(child) = first_child_ref.borrow() {
|
let first_child = if let Some(child) = first_child_ref {
|
||||||
child
|
child
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
|
|
@ -163,7 +163,7 @@ impl<'a> TryFrom<&'a AstNode<'a>> for TaskGroup {
|
||||||
if let NodeValue::Heading(heading) = node_ref.value {
|
if let NodeValue::Heading(heading) = node_ref.value {
|
||||||
let level = heading.level;
|
let level = heading.level;
|
||||||
let first_child_ref = &node.first_child();
|
let first_child_ref = &node.first_child();
|
||||||
let first_child = if let Some(child) = first_child_ref.borrow() {
|
let first_child = if let Some(child) = first_child_ref {
|
||||||
child
|
child
|
||||||
} else {
|
} else {
|
||||||
return Err(TaskError::ParsingError("Node has no children"));
|
return Err(TaskError::ParsingError("Node has no children"));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue