2022-08-24 10:38:47 +00:00
|
|
|
mod vcs;
|
2022-08-21 00:59:09 +00:00
|
|
|
mod edit;
|
2022-08-30 09:47:23 +00:00
|
|
|
mod args;
|
2022-08-20 04:01:43 +00:00
|
|
|
mod vault;
|
2022-08-25 00:44:22 +00:00
|
|
|
mod index;
|
2022-08-20 04:01:43 +00:00
|
|
|
mod error;
|
|
|
|
mod tasks;
|
|
|
|
mod state;
|
2022-08-25 06:40:56 +00:00
|
|
|
mod graph;
|
2022-08-23 23:56:23 +00:00
|
|
|
mod stats;
|
2022-08-20 04:01:43 +00:00
|
|
|
mod config;
|
2022-08-30 09:47:23 +00:00
|
|
|
mod format;
|
2022-08-20 04:01:43 +00:00
|
|
|
|
2022-08-30 09:47:23 +00:00
|
|
|
use args::*;
|
2022-08-20 04:01:43 +00:00
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let result = program();
|
|
|
|
|
|
|
|
match result {
|
2022-08-30 09:47:23 +00:00
|
|
|
Ok(()) => {
|
|
|
|
std::process::exit(0);
|
|
|
|
},
|
2022-08-25 06:40:56 +00:00
|
|
|
Err(err) => {
|
|
|
|
println!("{}", err);
|
2022-08-30 09:47:23 +00:00
|
|
|
std::process::exit(1);
|
2022-08-20 04:01:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn program() -> Result<(), error::Error> {
|
2022-08-30 09:47:23 +00:00
|
|
|
let command = Args::accept_command();
|
2022-08-20 04:01:43 +00:00
|
|
|
|
|
|
|
let mut config = config::Config::load()?;
|
|
|
|
|
2022-08-30 09:47:23 +00:00
|
|
|
if let Command::Vault(command) = command {
|
2022-08-22 08:17:37 +00:00
|
|
|
match command {
|
2022-08-30 09:47:23 +00:00
|
|
|
VaultCommand::New { name, path } => {
|
2022-08-22 08:17:37 +00:00
|
|
|
vault::new(name.clone(), path, &mut config)?;
|
2022-08-30 09:47:23 +00:00
|
|
|
println!("Created vault {}", format::vault(&name));
|
2022-08-22 08:17:37 +00:00
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
VaultCommand::Disconnect { name } => {
|
2022-08-22 08:17:37 +00:00
|
|
|
vault::disconnect(&name, &mut config)?;
|
2022-08-30 09:47:23 +00:00
|
|
|
println!("Disconnected vault {}", format::vault(&name));
|
2022-08-22 08:17:37 +00:00
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
VaultCommand::Connect { name , path } => {
|
2022-08-22 08:17:37 +00:00
|
|
|
vault::connect(name.clone(), path, &mut config)?;
|
2022-08-30 09:47:23 +00:00
|
|
|
println!("Connected vault {}", format::vault(&name));
|
2022-08-22 08:17:37 +00:00
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
VaultCommand::Delete { name } => {
|
2022-08-22 08:17:37 +00:00
|
|
|
vault::delete(&name, &mut config)?;
|
2022-08-30 09:47:23 +00:00
|
|
|
println!("Deleted vault {}", format::vault(&name));
|
2022-08-22 08:17:37 +00:00
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
VaultCommand::List => {
|
2022-08-22 08:17:37 +00:00
|
|
|
config.list_vaults()?;
|
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
VaultCommand::Rename { old_name, new_name } => {
|
2022-08-23 11:05:28 +00:00
|
|
|
config.rename_vault(&old_name, new_name.clone())?;
|
2022-08-30 09:47:23 +00:00
|
|
|
println!("Renamed vault {} to {}", format::vault(&old_name), format::vault(&new_name));
|
2022-08-23 11:05:28 +00:00
|
|
|
}
|
2022-08-22 08:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 09:47:23 +00:00
|
|
|
else if let Command::Config(command) = command {
|
2022-08-22 08:17:37 +00:00
|
|
|
use ConfigCommand::*;
|
|
|
|
match command {
|
|
|
|
Editor { editor } => {
|
|
|
|
match editor {
|
|
|
|
Some(editor) => {
|
|
|
|
config.editor = editor;
|
|
|
|
println!("Updated editor command to: {}", config.editor);
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
println!("Current editor command: {}", config.editor);
|
2022-08-21 07:34:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-08-22 08:17:37 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-30 09:47:23 +00:00
|
|
|
else if let Command::Switch { name } = command {
|
2022-08-22 08:17:37 +00:00
|
|
|
config.switch(&name)?;
|
2022-08-30 09:47:23 +00:00
|
|
|
println!("Switched to vault {}", format::vault(&name));
|
2022-08-22 08:17:37 +00:00
|
|
|
}
|
2022-08-30 09:47:23 +00:00
|
|
|
else if let Command::Git { args } = command {
|
2022-08-22 08:17:37 +00:00
|
|
|
let vault_folder = &config.current_vault()?.1;
|
2022-08-24 10:38:47 +00:00
|
|
|
vcs::command(args, vcs::Vcs::Git, vault_folder)?;
|
2022-08-22 08:17:37 +00:00
|
|
|
}
|
2022-08-30 22:45:37 +00:00
|
|
|
else if let Command::Svn { args } = command {
|
|
|
|
let vault_folder = &config.current_vault()?.1;
|
|
|
|
vcs::command(args, vcs::Vcs::Svn, vault_folder)?;
|
|
|
|
}
|
2022-08-30 09:47:23 +00:00
|
|
|
else if command == Command::GitIgnore {
|
2022-08-22 08:51:54 +00:00
|
|
|
let vault_folder = &config.current_vault()?.1;
|
2022-08-24 10:38:47 +00:00
|
|
|
vcs::create_gitignore(vault_folder)?;
|
2022-08-30 09:47:23 +00:00
|
|
|
println!("Default {} file created", format::file(".gitignore"));
|
2022-08-22 08:51:54 +00:00
|
|
|
}
|
2022-08-30 22:45:37 +00:00
|
|
|
else if command == Command::SvnIgnore {
|
2022-08-24 10:38:47 +00:00
|
|
|
let vault_folder = &config.current_vault()?.1;
|
2022-08-30 22:45:37 +00:00
|
|
|
vcs::set_svn_ignore(vault_folder)?;
|
|
|
|
println!("Default svn:ignore property set");
|
2022-08-24 10:38:47 +00:00
|
|
|
}
|
2022-08-22 08:17:37 +00:00
|
|
|
// Commands that require loading in the state.
|
|
|
|
else {
|
|
|
|
let vault_folder = &config.current_vault()?.1;
|
|
|
|
let mut state = state::State::load(vault_folder)?;
|
|
|
|
|
|
|
|
match command {
|
2022-08-30 09:47:23 +00:00
|
|
|
Command::New { name, info, tag, dependency, priority, due } => {
|
|
|
|
let task = tasks::Task::new(name, info, tag, dependency, priority, due, vault_folder, &mut state)?;
|
|
|
|
println!("Created task {} (ID: {})", format::task(&task.data.name), format::id(task.data.id));
|
2022-08-22 08:17:37 +00:00
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
Command::Delete { id_or_name } => {
|
2022-08-25 00:44:22 +00:00
|
|
|
let id = state.data.index.lookup(&id_or_name)?;
|
2022-08-22 08:17:37 +00:00
|
|
|
let task = tasks::Task::load(id, vault_folder, false)?;
|
|
|
|
let name = task.data.name.clone();
|
2022-08-25 00:44:22 +00:00
|
|
|
state.data.index.remove(task.data.name.clone(), task.data.id);
|
2022-08-25 06:40:56 +00:00
|
|
|
state.data.deps.remove_node(task.data.id);
|
2022-08-22 08:17:37 +00:00
|
|
|
task.delete()?;
|
|
|
|
|
2022-08-30 09:47:23 +00:00
|
|
|
println!("Deleted task {} (ID: {})", format::task(&name), format::id(id));
|
2022-08-22 08:17:37 +00:00
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
Command::View { id_or_name } => {
|
2022-08-25 00:44:22 +00:00
|
|
|
let id = state.data.index.lookup(&id_or_name)?;
|
2022-08-22 08:17:37 +00:00
|
|
|
let task = tasks::Task::load(id, vault_folder, true)?;
|
2022-08-25 06:40:56 +00:00
|
|
|
task.display(vault_folder, &state)?;
|
2022-08-22 08:17:37 +00:00
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
Command::Edit { id_or_name, info } => {
|
2022-08-25 00:44:22 +00:00
|
|
|
let id = state.data.index.lookup(&id_or_name)?;
|
2022-08-22 08:17:37 +00:00
|
|
|
if info {
|
|
|
|
edit::edit_info(id, vault_folder.clone(), &config.editor)?;
|
2022-08-20 23:58:05 +00:00
|
|
|
}
|
2022-08-22 08:17:37 +00:00
|
|
|
else {
|
|
|
|
edit::edit_raw(id, vault_folder.clone(), &config.editor, &mut state)?;
|
|
|
|
}
|
2022-08-30 09:47:23 +00:00
|
|
|
println!("Updated task {}", format::id(id));
|
2022-08-22 08:17:37 +00:00
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
Command::Track { id_or_name, hours, minutes, date, message } => {
|
2022-08-25 00:44:22 +00:00
|
|
|
let id = state.data.index.lookup(&id_or_name)?;
|
2022-08-22 10:27:17 +00:00
|
|
|
let mut task = tasks::Task::load(id, vault_folder, false)?;
|
2022-08-30 08:23:23 +00:00
|
|
|
let entry = tasks::TimeEntry::new(hours, minutes, date, message);
|
2022-08-22 10:27:17 +00:00
|
|
|
task.data.time_entries.push(entry);
|
|
|
|
task.save()?;
|
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
Command::Stats(command) => {
|
2022-08-23 23:56:23 +00:00
|
|
|
use StatsCommand::*;
|
|
|
|
match command {
|
|
|
|
Tracked { days } => {
|
|
|
|
stats::time_per_tag(days, vault_folder)?;
|
2022-08-24 23:15:15 +00:00
|
|
|
},
|
|
|
|
Completed { days } => {
|
|
|
|
stats::completed_tasks(days, vault_folder)?;
|
2022-08-23 23:56:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
Command::Complete { id_or_name } => {
|
2022-08-25 00:44:22 +00:00
|
|
|
let id = state.data.index.lookup(&id_or_name)?;
|
2022-08-22 08:17:37 +00:00
|
|
|
let mut task = tasks::Task::load(id, vault_folder, false)?;
|
2022-08-24 22:30:52 +00:00
|
|
|
task.data.completed = Some(chrono::Local::now().naive_local());
|
2022-08-22 08:17:37 +00:00
|
|
|
task.save()?;
|
2022-08-30 09:47:23 +00:00
|
|
|
println!("Marked task {} as complete", format::id(id));
|
2022-08-22 08:17:37 +00:00
|
|
|
},
|
2022-08-30 09:47:23 +00:00
|
|
|
Command::List { options } => {
|
2022-08-29 07:34:22 +00:00
|
|
|
tasks::list(options, vault_folder, &state)?;
|
2022-08-22 08:17:37 +00:00
|
|
|
},
|
|
|
|
// All commands which are dealt with in if let chain at start.
|
2022-08-30 22:45:37 +00:00
|
|
|
Command::Vault(_) | Command::Config(_) | Command::Git { args : _ } | Command::Svn { args : _ } | Command::Switch { name : _ } | Command::GitIgnore | Command::SvnIgnore => unreachable!(),
|
2022-08-20 04:01:43 +00:00
|
|
|
}
|
2022-08-22 08:17:37 +00:00
|
|
|
|
|
|
|
state.save()?;
|
2022-08-20 04:01:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config.save()?;
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|