1use anyhow::Result;
2
3use crate::application::cli::arguments::{
4 Cli, Commands, ConfigAction, HooksAction, ImportAs, PackageAction,
5};
6use crate::application::commands;
7use crate::output;
8use crate::services::storage::lock_storage::LockStorage;
9use crate::utils::static_paths::UpstreamPaths;
10
11impl Cli {
12 pub async fn run(self) -> Result<()> {
13 output::set_assume_yes(self.yes);
14 let command = self.command;
15 let paths = UpstreamPaths::new()?;
16 let _lock = if command.requires_lock() {
17 Some(LockStorage::acquire(&paths, &command)?)
18 } else {
19 None
20 };
21
22 match command {
23 Commands::Hooks { action } => match action {
24 HooksAction::Init => commands::hooks::run_hooks_init(),
25 HooksAction::Check => commands::hooks::run_hooks_check(),
26 HooksAction::Clean => commands::hooks::run_hooks_clean(),
27 HooksAction::Purge => commands::hooks::run_hooks_purge(),
28 },
29 Commands::Install {
30 name,
31 repo_slug,
32 kind,
33 tag,
34 provider,
35 base_url,
36 channel,
37 match_pattern,
38 exclude_pattern,
39 desktop,
40 trust_mode,
41 dry_run,
42 } => {
43 commands::install::run(
44 name,
45 repo_slug,
46 kind,
47 tag,
48 provider,
49 base_url,
50 channel,
51 match_pattern,
52 exclude_pattern,
53 desktop,
54 trust_mode,
55 dry_run,
56 )
57 .await
58 }
59 Commands::Build {
60 name,
61 repo_slug,
62 tag,
63 branch,
64 provider,
65 base_url,
66 channel,
67 desktop,
68 build_profile,
69 dry_run,
70 } => {
71 commands::build::run(
72 name,
73 repo_slug,
74 tag,
75 branch,
76 provider,
77 base_url,
78 channel,
79 desktop,
80 build_profile,
81 dry_run,
82 )
83 .await
84 }
85
86 Commands::Remove {
87 names,
88 purge: purge_option,
89 force,
90 dry_run,
91 } => commands::remove::run(names, purge_option, force, dry_run),
92
93 Commands::Rollback {
94 names,
95 prune,
96 dry_run,
97 } => commands::rollback::run(names, prune, dry_run),
98
99 Commands::Reinstall {
100 names,
101 trust_mode,
102 force,
103 dry_run,
104 } => commands::reinstall::run(names, trust_mode, force, dry_run).await,
105
106 Commands::Upgrade {
107 names,
108 force,
109 check,
110 machine_readable,
111 json,
112 trust_mode,
113 dry_run,
114 } => {
115 commands::upgrade::run(
116 names,
117 force,
118 check,
119 machine_readable,
120 json,
121 trust_mode,
122 dry_run,
123 )
124 .await
125 }
126
127 Commands::List { name, json } => commands::list::run(name, json),
128
129 Commands::Changelog {
130 name,
131 from_tag,
132 to_tag,
133 } => commands::changelog::run(name, from_tag, to_tag).await,
134
135 Commands::Probe {
136 repo_slug,
137 provider,
138 base_url,
139 channel,
140 limit,
141 verbose,
142 json,
143 } => {
144 commands::probe::run(repo_slug, provider, base_url, channel, limit, verbose, json)
145 .await
146 }
147 Commands::Search {
148 query_words,
149 provider,
150 base_url,
151 limit,
152 language,
153 topic,
154 min_stars,
155 max_stars,
156 pushed_after,
157 include_forks,
158 include_archived,
159 json,
160 } => {
161 commands::search::run(
162 query_words,
163 provider,
164 base_url,
165 limit,
166 language,
167 topic,
168 min_stars,
169 max_stars,
170 pushed_after,
171 include_forks,
172 include_archived,
173 json,
174 )
175 .await
176 }
177 Commands::Find {
178 query_words,
179 provider,
180 base_url,
181 limit,
182 name,
183 kind,
184 channel,
185 match_pattern,
186 exclude_pattern,
187 desktop,
188 trust_mode,
189 dry_run,
190 } => {
191 commands::find::run(
192 query_words,
193 provider,
194 base_url,
195 limit,
196 name,
197 kind,
198 channel,
199 match_pattern,
200 exclude_pattern,
201 desktop,
202 trust_mode,
203 dry_run,
204 )
205 .await
206 }
207
208 Commands::Config { action } => match action {
209 ConfigAction::Set { keys } => commands::config::run_set(keys),
210 ConfigAction::Get { keys } => commands::config::run_get(keys),
211 ConfigAction::List => commands::config::run_list(),
212 ConfigAction::Edit => commands::config::run_edit(),
213 ConfigAction::Reset => commands::config::run_reset(),
214 },
215
216 Commands::Package { action } => match action {
217 PackageAction::Pin { name, reason } => commands::package::run_pin(name, reason),
218 PackageAction::Unpin { name } => commands::package::run_unpin(name),
219 PackageAction::Rename { old_name, new_name } => {
220 commands::package::run_rename(old_name, new_name)
221 }
222 },
223
224 Commands::Export { path, full } => commands::export::run_export(path, full).await,
225 Commands::Migrate => commands::migrate::run(),
226 Commands::Import {
227 path,
228 skip_failed,
229 import_as,
230 } => {
231 let forced_kind = import_as.map(|value| match value {
232 ImportAs::Keys => commands::import::ImportKindArg::Keys,
233 ImportAs::Manifest => commands::import::ImportKindArg::Manifest,
234 ImportAs::Snapshot => commands::import::ImportKindArg::Snapshot,
235 });
236 commands::import::run_import(path, skip_failed, forced_kind).await
237 }
238 Commands::Doctor {
239 names,
240 verbose,
241 fix,
242 json,
243 } => commands::doctor::run(names, verbose, fix, json),
244 }
245 }
246}