aboutsummaryrefslogtreecommitdiff
path: root/src/cli/ops_cmd.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-04-16 23:24:52 +0800
committer魏曹先生 <1992414357@qq.com>2026-04-16 23:24:52 +0800
commit6e36fc3707e791c3c748133d648957706b54fd3a (patch)
tree3851ed69d60f331a803a6c19c97a56829a11f2f5 /src/cli/ops_cmd.rs
parent363fbc6e98f832471a17a10ec18e8823df6a2ed5 (diff)
Add CLI commands for bill management and persistence
Diffstat (limited to 'src/cli/ops_cmd.rs')
-rw-r--r--src/cli/ops_cmd.rs80
1 files changed, 0 insertions, 80 deletions
diff --git a/src/cli/ops_cmd.rs b/src/cli/ops_cmd.rs
deleted file mode 100644
index 4b0eea7..0000000
--- a/src/cli/ops_cmd.rs
+++ /dev/null
@@ -1,80 +0,0 @@
-use std::{
- env::current_dir,
- fs::{self, create_dir_all},
- path::PathBuf,
-};
-
-use mingling::{
- AnyOutput,
- macros::{chain, dispatcher, pack, r_println, renderer},
- marker::NextProcess,
- parser::Picker,
-};
-
-use crate::{
- ThisProgram,
- cli::{consts::BILL_WORKSPACE_CONFIG_FILE, io_error::IOError},
-};
-
-dispatcher!("init", InitHereCommand => InitEntry);
-dispatcher!("create", CreateCommand => CreateEntry);
-
-pack!(StateCreateWorkspace = PathBuf);
-
-#[chain]
-pub async fn handle_init_command(_prev: InitEntry) -> NextProcess {
- let current_dir = match current_dir() {
- Ok(d) => d,
- Err(e) => return AnyOutput::new(IOError::from(e)).route_renderer(),
- };
- StateCreateWorkspace::new(current_dir).to_chain()
-}
-
-#[chain]
-pub async fn handle_create_command(prev: CreateEntry) -> NextProcess {
- let path = pick_path(prev.inner);
- StateCreateWorkspace::new(path).to_chain()
-}
-
-#[chain]
-pub async fn handle_state_create_workspace(prev: StateCreateWorkspace) -> NextProcess {
- let dir = prev.inner;
- let file = dir.join(BILL_WORKSPACE_CONFIG_FILE);
-
- match create_dir_all(&dir) {
- Ok(d) => d,
- Err(e) => return AnyOutput::new(IOError::from(e)).route_renderer(),
- };
-
- if file.exists() {
- return AnyOutput::new(WorkspaceConfigAlreadyExists::new(dir)).route_renderer();
- }
-
- if let Err(e) = fs::write(file, "") {
- return AnyOutput::new(IOError::from(e)).route_renderer();
- }
-
- StateWorkspaceCreated::new(dir).to_render()
-}
-
-pack!(StateWorkspaceCreated = PathBuf);
-
-#[renderer]
-pub fn render_workspace_created(prev: StateWorkspaceCreated) {
- r_println!("Workspace created at: {:?}", prev.inner);
-}
-
-pack!(WorkspaceConfigAlreadyExists = PathBuf);
-
-#[renderer]
-pub fn render_workspace_config_already_exists(prev: WorkspaceConfigAlreadyExists) {
- r_println!("Workspace config already exists: {:?}", prev.inner);
-}
-
-fn pick_path(args: Vec<String>) -> PathBuf {
- let path = Picker::<()>::new(args)
- .pick::<String>(())
- .unpack_directly()
- .0;
- PathBuf::from(path)
-}