aboutsummaryrefslogtreecommitdiff
path: root/mling/src/proj_mgr
diff options
context:
space:
mode:
Diffstat (limited to 'mling/src/proj_mgr')
-rw-r--r--mling/src/proj_mgr/generator.rs39
-rw-r--r--mling/src/proj_mgr/mod.rs7
2 files changed, 46 insertions, 0 deletions
diff --git a/mling/src/proj_mgr/generator.rs b/mling/src/proj_mgr/generator.rs
new file mode 100644
index 0000000..bcc6e5b
--- /dev/null
+++ b/mling/src/proj_mgr/generator.rs
@@ -0,0 +1,39 @@
+use std::path::{self, PathBuf};
+
+use mingling::{Groupped, macros::{chain, pack, r_println, renderer, route}};
+
+use crate::{EntryGenerateProject, Next, res::ResCurrentDir};
+
+pack!(StateGenerateProjectReady = PathBuf);
+pack!(ResultGenerateProjectChecklistCreated = PathBuf);
+
+pack!(StateGenerateProjectExecBegin = PathBuf);
+pack!(StateGenerateProjectExecuting = ());
+
+const CHECK_LIST_NAME: &str = "CHECKLIST.md";
+const CHECK_LIST_CONTENT: &str = include_str!("../../res/CHECKLIST.md");
+
+#[chain]
+pub fn handle_generate(_args: EntryGenerateProject, cwd: &ResCurrentDir) -> Next {
+ let checklist_path = cwd.path.join(CHECK_LIST_NAME);
+
+ if !checklist_path.exists() {
+ StateGenerateProjectReady::new(checklist_path).to_chain()
+ } else {
+ StateGenerateProjectExecBegin::new(checklist_path).to_chain()
+ }
+}
+
+#[chain]
+pub fn handle_state_gen_proj_ready(prev: StateGenerateProjectReady) -> Next {
+ let path = prev.inner;
+ route!(std::fs::write(&path, CHECK_LIST_CONTENT));
+ ResultGenerateProjectChecklistCreated::new(path).to_render()
+}
+
+#[renderer]
+pub fn render_gen_proj_checklist_created(result: ResultGenerateProjectChecklistCreated) {
+ r_println!("Successfully create {} at \"{}\"", CHECK_LIST_NAME, result.to_string_lossy());
+ r_println!("");
+ r_println!("Please fill in {CHECK_LIST_NAME} and run `mling gen` again to continue generating");
+}
diff --git a/mling/src/proj_mgr/mod.rs b/mling/src/proj_mgr/mod.rs
index b282203..04353b7 100644
--- a/mling/src/proj_mgr/mod.rs
+++ b/mling/src/proj_mgr/mod.rs
@@ -4,6 +4,9 @@ use mingling::{
macros::{dispatcher, program_setup},
};
+mod generator;
+pub use generator::*;
+
pub mod metadata;
mod show_binaries;
@@ -12,6 +15,8 @@ pub use show_binaries::*;
mod show_directories;
pub use show_directories::*;
+dispatcher!("gen", CMDGenerateProject => EntryGenerateProject);
+
dispatcher!("show.binaries");
dispatcher!("show.workspace-dir",
CMDShowWorkspaceDirectory => EntryShowWorkspaceDirectory
@@ -22,6 +27,8 @@ dispatcher!("show.target-dir",
#[program_setup]
pub fn project_manager_setup(p: &mut Program<ThisProgram>) {
+ p.with_dispatcher(CMDGenerateProject);
+
p.with_dispatcher(CMDShowBinaries);
p.with_dispatcher(CMDShowWorkspaceDirectory);
p.with_dispatcher(CMDShowTargetDirectories);