diff --git a/src/cmd/init.rs b/src/cmd/init.rs deleted file mode 100644 index 9aaf6403a9468da37da98e8bcd2c7380be31b063..0000000000000000000000000000000000000000 --- a/src/cmd/init.rs +++ /dev/null @@ -1,18 +0,0 @@ -use anyhow::Result; -use std::path::Path; - -pub fn run(root: &Path, name: &str, json: bool) -> Result<()> { - crate::db::init(root, name)?; - - if json { - println!( - "{}", - serde_json::json!({"success": true, "project": name, "bound_path": root}) - ); - } else { - let c = crate::color::stderr_theme(); - eprintln!("{}info:{} initialized project '{name}'", c.blue, c.reset); - } - - Ok(()) -} diff --git a/src/cmd/mod.rs b/src/cmd/mod.rs index 26b3b2e0be8e3dd80c8f59bb55929fd657531d31..1a6aafe17db5a45b0932b824ee131b9d43c0c9cb 100644 --- a/src/cmd/mod.rs +++ b/src/cmd/mod.rs @@ -3,12 +3,11 @@ mod dep; mod done; mod export; mod import; -mod init; mod label; mod list; mod log; mod next; -mod projects; +mod project; mod ready; mod reopen; mod rm; @@ -19,7 +18,6 @@ mod stats; pub mod sync; mod tidy; mod update; -mod r#use; use crate::cli::{Cli, Command}; use crate::db; @@ -35,12 +33,7 @@ pub fn dispatch(cli: &Cli) -> Result<()> { } match &cli.command { - Command::Init { name } => { - let root = std::env::current_dir()?; - init::run(&root, name, cli.json) - } - Command::Use { name } => r#use::run(name, cli.json), - Command::Projects => projects::run(cli.json), + Command::Project { action } => project::run(action, cli.json), Command::Create { title, priority, diff --git a/src/cmd/project.rs b/src/cmd/project.rs new file mode 100644 index 0000000000000000000000000000000000000000..78556b5e1967d2b9e737039880d709ce3c993225 --- /dev/null +++ b/src/cmd/project.rs @@ -0,0 +1,88 @@ +use anyhow::Result; +use std::path::Path; + +use crate::cli::ProjectAction; + +pub fn run(action: &ProjectAction, json: bool) -> Result<()> { + let cwd = std::env::current_dir()?; + + match action { + ProjectAction::Init { name } => init(&cwd, name, json), + ProjectAction::Bind { name } => bind(&cwd, name, json), + ProjectAction::Unbind => unbind(&cwd, json), + ProjectAction::Delete { name } => delete(name, json), + ProjectAction::List => list(json), + } +} + +fn init(cwd: &Path, name: &str, json: bool) -> Result<()> { + crate::db::init(cwd, name)?; + + if json { + println!( + "{}", + serde_json::json!({"success": true, "project": name, "bound_path": cwd}) + ); + } else { + let c = crate::color::stderr_theme(); + eprintln!("{}info:{} initialized project '{name}'", c.blue, c.reset); + } + + Ok(()) +} + +fn bind(cwd: &Path, name: &str, json: bool) -> Result<()> { + crate::db::use_project(cwd, name)?; + + if json { + println!( + "{}", + serde_json::json!({"success": true, "project": name, "bound_path": cwd}) + ); + } else { + let c = crate::color::stdout_theme(); + println!("{}bound{} {} -> {name}", c.green, c.reset, cwd.display()); + } + + Ok(()) +} + +fn unbind(cwd: &Path, json: bool) -> Result<()> { + crate::db::unbind_project(cwd)?; + + if json { + println!("{}", serde_json::json!({"success": true})); + } else { + let c = crate::color::stderr_theme(); + eprintln!("{}info:{} unbound {}", c.blue, c.reset, cwd.display()); + } + + Ok(()) +} + +fn delete(name: &str, json: bool) -> Result<()> { + crate::db::delete_project(name)?; + + if json { + println!("{}", serde_json::json!({"success": true, "project": name})); + } else { + let c = crate::color::stderr_theme(); + eprintln!("{}info:{} deleted project '{name}'", c.blue, c.reset); + } + + Ok(()) +} + +fn list(json: bool) -> Result<()> { + let projects = crate::db::list_projects()?; + + if json { + println!("{}", serde_json::to_string(&projects)?); + } else { + for project in projects { + println!("{project}"); + } + } + + Ok(()) +} diff --git a/src/cmd/projects.rs b/src/cmd/projects.rs deleted file mode 100644 index 0e3090a62c90e2dcfd0557bf8d9bf25449fe1f4c..0000000000000000000000000000000000000000 --- a/src/cmd/projects.rs +++ /dev/null @@ -1,15 +0,0 @@ -use anyhow::Result; - -pub fn run(json: bool) -> Result<()> { - let projects = crate::db::list_projects()?; - - if json { - println!("{}", serde_json::to_string(&projects)?); - } else { - for project in projects { - println!("{project}"); - } - } - - Ok(()) -} diff --git a/src/cmd/sync.rs b/src/cmd/sync.rs index 48e8400fb90db61498ce9424fce4c390b2eb27d5..059a8b00f485411f92f35386597d3df8d1419a7b 100644 --- a/src/cmd/sync.rs +++ b/src/cmd/sync.rs @@ -114,7 +114,7 @@ pub async fn exchange(store: &db::Store, mut wormhole: Wormhole) -> Result' on both machines", my_project_name, my_project_id, project_name, @@ -220,7 +220,7 @@ async fn bootstrap_exchange( SyncHandshake::Bootstrap { .. } => { let _ = wormhole.close().await; bail!( - "both peers are in bootstrap mode. Run 'td init ' on one machine first, then run 'td sync' on the other" + "both peers are in bootstrap mode. Run 'td project init ' on one machine first, then run 'td sync' on the other" ); } }; diff --git a/src/cmd/use.rs b/src/cmd/use.rs deleted file mode 100644 index daa586214745112b24fc49cdf5363ee915a6a663..0000000000000000000000000000000000000000 --- a/src/cmd/use.rs +++ /dev/null @@ -1,18 +0,0 @@ -use anyhow::Result; - -pub fn run(name: &str, json: bool) -> Result<()> { - let cwd = std::env::current_dir()?; - crate::db::use_project(&cwd, name)?; - - if json { - println!( - "{}", - serde_json::json!({"success": true, "project": name, "bound_path": cwd}) - ); - } else { - let c = crate::color::stdout_theme(); - println!("{}bound{} {} -> {name}", c.green, c.reset, cwd.display()); - } - - Ok(()) -}