shortcircut loading state with git command; switch as top level command

This commit is contained in:
aaron-jack-manning 2022-08-22 18:17:37 +10:00
parent a0fd9b01d7
commit 4f44f6d894
2 changed files with 110 additions and 106 deletions

View File

@ -44,3 +44,6 @@ Run `--help` alongside any command to get details on what it does.
- Due dates
- Taken as input when creating notes
- Displayed in list view by default (with number of days remaining)
- Git integration
- Command to add default gitignore file
- `clean` command to delete discarded tasks

View File

@ -75,6 +75,10 @@ enum Command {
/// Commands for interacting with vaults.
#[clap(subcommand)]
Vault(VaultCommand),
/// Switches to the specified vault.
Switch {
name : String,
},
}
#[derive(clap::Subcommand, Debug)]
@ -108,10 +112,6 @@ enum VaultCommand {
},
/// Lists all configured vaults.
List,
/// Switches to the specified vault.
Switch {
name : String,
},
}
fn main() {
@ -135,8 +135,7 @@ fn program() -> Result<(), error::Error> {
let mut config = config::Config::load()?;
use Command::*;
match command {
Vault(command) => {
if let Vault(command) = command {
use VaultCommand::*;
match command {
New { name, path } => {
@ -158,13 +157,9 @@ fn program() -> Result<(), error::Error> {
List => {
config.list_vaults()?;
},
Switch { name } => {
config.switch(&name)?;
println!("Switched to vault {}", colour::vault(&name));
},
}
},
Config(command) => {
}
else if let Config(command) = command {
use ConfigCommand::*;
match command {
Editor { editor } => {
@ -179,8 +174,17 @@ fn program() -> Result<(), error::Error> {
}
}
}
},
command => {
}
else if let Switch { name } = command {
config.switch(&name)?;
println!("Switched to vault {}", colour::vault(&name));
}
else if let Git { args } = command {
let vault_folder = &config.current_vault()?.1;
git::run_command(args, vault_folder)?;
}
// Commands that require loading in the state.
else {
let vault_folder = &config.current_vault()?.1;
let mut state = state::State::load(vault_folder)?;
@ -227,18 +231,15 @@ fn program() -> Result<(), error::Error> {
task.save()?;
println!("Marked task {} as complete", colour::id(&id.to_string()));
},
Git { args } => {
git::run_command(args, vault_folder)?;
},
List {} => {
tasks::list(vault_folder)?;
}
Vault(_) | Config(_) => unreachable!(),
},
// All commands which are dealt with in if let chain at start.
Vault(_) | Config(_) | Git { args : _ } | Switch { name : _ } => unreachable!(),
}
state.save()?;
}
}
config.save()?;