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