Skip to main content

upstream_rs/application/cli/
dispatch.rs

1use anyhow::Result;
2
3use crate::application::cli::arguments::{Cli, Commands, ConfigAction, PackageAction};
4use crate::application::features;
5use crate::services::storage::lock_storage::LockStorage;
6use crate::utils::static_paths::UpstreamPaths;
7
8impl Cli {
9    pub async fn run(self) -> Result<()> {
10        let command = self.command;
11        let paths = UpstreamPaths::new();
12        let _lock = if command.requires_lock() {
13            Some(LockStorage::acquire(&paths, &command)?)
14        } else {
15            None
16        };
17
18        match command {
19            Commands::Init { clean, check } => features::init::run(clean, check),
20            Commands::Install {
21                name,
22                repo_slug,
23                kind,
24                tag,
25                provider,
26                base_url,
27                channel,
28                match_pattern,
29                exclude_pattern,
30                desktop,
31                ignore_checksums,
32            } => {
33                features::install::run(
34                    name,
35                    repo_slug,
36                    kind,
37                    tag,
38                    provider,
39                    base_url,
40                    channel,
41                    match_pattern,
42                    exclude_pattern,
43                    desktop,
44                    ignore_checksums,
45                )
46                .await
47            }
48
49            Commands::Remove {
50                names,
51                purge: purge_option,
52            } => features::remove::run(names, purge_option),
53
54            Commands::Upgrade {
55                names,
56                force,
57                check,
58                machine_readable,
59                ignore_checksums,
60            } => {
61                features::upgrade::run(names, force, check, machine_readable, ignore_checksums)
62                    .await
63            }
64
65            Commands::List { name } => features::list::run(name),
66
67            Commands::Probe {
68                repo_slug,
69                provider,
70                base_url,
71                channel,
72                limit,
73                verbose,
74            } => features::probe::run(repo_slug, provider, base_url, channel, limit, verbose).await,
75
76            Commands::Config { action } => match action {
77                ConfigAction::Set { keys } => features::config::run_set(keys),
78                ConfigAction::Get { keys } => features::config::run_get(keys),
79                ConfigAction::List => features::config::run_list(),
80                ConfigAction::Edit => features::config::run_edit(),
81                ConfigAction::Reset => features::config::run_reset(),
82            },
83
84            Commands::Package { action } => match action {
85                PackageAction::Pin { name } => features::package::run_pin(name),
86                PackageAction::Unpin { name } => features::package::run_unpin(name),
87                PackageAction::SetKey { name, keys } => features::package::run_set_key(name, keys),
88                PackageAction::Rename { old_name, new_name } => {
89                    features::package::run_rename(old_name, new_name)
90                }
91                PackageAction::GetKey { name, keys } => features::package::run_get_key(name, keys),
92                PackageAction::Metadata { name } => features::package::run_metadata(name),
93            },
94
95            Commands::Export { path, full } => features::export::run_export(path, full).await,
96            Commands::Import { path, skip_failed } => {
97                features::import::run_import(path, skip_failed).await
98            }
99            Commands::Doctor { names } => features::doctor::run(names),
100        }
101    }
102}