aboutsummaryrefslogtreecommitdiff
path: root/mling/src/cli.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-04-28 17:47:01 +0800
committer魏曹先生 <1992414357@qq.com>2026-04-28 17:47:01 +0800
commit5aa9bcb7e92bb344f86ac595ebcf0aa6c80dee9d (patch)
tree388161e6e9e0ce2f1d38a106a7b8030d4af3225c /mling/src/cli.rs
parent6a907b71f945bf49d27a001f279bf116ad7297d8 (diff)
Add terminal colored rendering and guide text
Diffstat (limited to 'mling/src/cli.rs')
-rw-r--r--mling/src/cli.rs46
1 files changed, 38 insertions, 8 deletions
diff --git a/mling/src/cli.rs b/mling/src/cli.rs
index ed5dd06..65ba02a 100644
--- a/mling/src/cli.rs
+++ b/mling/src/cli.rs
@@ -1,9 +1,11 @@
use mingling::{
- macros::renderer,
+ macros::{r_println, renderer},
setup::{BasicProgramSetup, GeneralRendererSetup},
};
-use crate::{__completion_gen::CompletionDispatcher, DispatcherNotFound, ThisProgram};
+use crate::{
+ __completion_gen::CompletionDispatcher, DispatcherNotFound, ThisProgram, display::markdown,
+};
pub mod list;
pub use list::*;
@@ -18,28 +20,56 @@ pub mod install;
pub use install::*;
pub fn cli_entry() {
+ // Facade
+ if std::env::args().len() == 1 {
+ println!("{}", include_str!("../res/guide.txt").trim_end());
+ return;
+ }
+
let mut program = ThisProgram::new();
+ // Plugins
program.with_setup(BasicProgramSetup);
program.with_setup(GeneralRendererSetup);
program.with_dispatcher(CompletionDispatcher);
+ // Help
+ if program.user_context.help {
+ println!(
+ "{}",
+ markdown(include_str!("../res/help-mling.txt").trim_end())
+ );
+ return;
+ }
+
+ // Context query commands
program.with_dispatcher(ListInstalledCommand);
program.with_dispatchers((
+ ReadTargetDirCommand,
+ ReadWorkspaceRootCommand,
+ ReadBinariesCommand,
+ ));
+
+ // Namespace manage commands
+ program.with_dispatchers((
TrustNamespaceCommand,
UntrustNamespaceCommand,
SetTrustNamespaceCommand,
RemoveNamespaceCommand,
));
+
+ // Install binaries command
program.with_dispatcher(InstallCommand);
- program.with_dispatchers((
- ReadTargetDirCommand,
- ReadWorkspaceRootCommand,
- ReadBinariesCommand,
- ));
+
+ // Colored Setup
+ #[cfg(windows)]
+ colored::control::set_virtual_terminal(true).unwrap();
program.exec();
}
#[renderer]
-pub(crate) fn render_help(_prev: DispatcherNotFound) {}
+pub(crate) fn fallback_disp(prev: DispatcherNotFound) {
+ r_println!("Error: command \"{}\" not found!", prev.join(" "));
+ r_println!("Use \"mling --help\" for more information.");
+}