aboutsummaryrefslogtreecommitdiff
path: root/mling/src/cli/list.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-07 02:25:27 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-07 02:25:27 +0800
commit81528b273c18693ebd3f05c6f8057ff8e632f4a0 (patch)
tree85026c27535337c0123d4650c844ae364bc9780a /mling/src/cli/list.rs
parente41e8bda221b44d09d7e93ffc43675147ab60a6d (diff)
Refactor mling to use new program architecture and install scripts
Diffstat (limited to 'mling/src/cli/list.rs')
-rw-r--r--mling/src/cli/list.rs123
1 files changed, 0 insertions, 123 deletions
diff --git a/mling/src/cli/list.rs b/mling/src/cli/list.rs
deleted file mode 100644
index a2a9434..0000000
--- a/mling/src/cli/list.rs
+++ /dev/null
@@ -1,123 +0,0 @@
-use colored::Colorize;
-use mingling::{
- Groupped, RenderResult, ShellContext, Suggest,
- macros::{chain, completion, dispatcher, pack, r_println, renderer, suggest},
- parser::Picker,
-};
-use serde::Serialize;
-
-use crate::{Next, namespace_manager::list_namespaces};
-
-dispatcher!("ls-namespace", ListInstalledCommand => ListInstalledEntry);
-
-#[completion(ListInstalledEntry)]
-pub(crate) fn comp_list_installed(ctx: &ShellContext) -> Suggest {
- if ctx.typing_argument() {
- return suggest! {
- "--trusted": "Show only trusted namespaces",
- "--untrusted": "Show only untrusted namespaces",
- };
- }
- return suggest!();
-}
-
-#[derive(Debug, Serialize, Default, Groupped)]
-pub(crate) enum StateListInstalledOptions {
- #[default]
- All,
- OnlyTrusted,
- OnlyUntrusted,
-}
-
-pack!(MutexErrorListInstalled = ());
-
-#[chain]
-pub(crate) fn handle_list_installed_entry(prev: ListInstalledEntry) -> Next {
- let picker = Picker::new(prev.inner);
- let r = picker
- .pick::<bool>("--trusted")
- .pick::<bool>("--untrusted")
- .unpack();
-
- let option: StateListInstalledOptions = match r {
- // (show_trusted, show_untrusted)
- (true, false) => StateListInstalledOptions::OnlyTrusted,
- (false, true) => StateListInstalledOptions::OnlyUntrusted,
- (false, false) => StateListInstalledOptions::All,
- (true, true) => return MutexErrorListInstalled::default().to_render(),
- };
-
- option.to_chain()
-}
-
-#[renderer]
-pub(crate) fn render_list_installed_mutex_error(_prev: MutexErrorListInstalled) {
- r_println!("Error: cannot use both --trusted and --untrusted options at the same time")
-}
-
-#[derive(Debug, Groupped, Serialize)]
-pub(crate) struct ResultInstalledNamespaces {
- trusted: Vec<String>,
- untrusted: Vec<String>,
- untagged: Vec<String>,
- option: StateListInstalledOptions,
-}
-
-#[chain]
-pub(crate) fn handle_state_list_installed_option(prev: StateListInstalledOptions) -> Next {
- ResultInstalledNamespaces {
- trusted: list_namespaces(true, false, false),
- untrusted: list_namespaces(false, true, false),
- untagged: list_namespaces(false, false, true),
- option: prev,
- }
-}
-
-#[renderer]
-pub(crate) fn render_installed(prev: ResultInstalledNamespaces) {
- match prev.option {
- StateListInstalledOptions::All => {
- print_list(
- &"Trusted".bright_green().bold().to_string(),
- &prev.trusted,
- __renderer_inner_result,
- );
- print_list(
- &"Untrusted".bright_red().bold().to_string(),
- &prev.untrusted,
- __renderer_inner_result,
- );
- print_list(
- &"Untagged".bright_black().bold().to_string(),
- &prev.untagged,
- __renderer_inner_result,
- );
- }
- StateListInstalledOptions::OnlyTrusted => {
- print_list(
- &"Trusted".bright_green().bold().to_string(),
- &prev.trusted,
- __renderer_inner_result,
- );
- }
- StateListInstalledOptions::OnlyUntrusted => {
- print_list(
- &"Untrusted".bright_red().bold().to_string(),
- &prev.untrusted,
- __renderer_inner_result,
- );
- }
- }
-}
-
-fn print_list(title: &str, list: &[String], __renderer_inner_result: &mut RenderResult) {
- if list.is_empty() {
- return;
- }
-
- r_println!("{title}");
-
- for (i, namespace) in (1..).zip(list.iter()) {
- r_println!(" {}. {}", i.to_string(), namespace.bold());
- }
-}