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 { action } => commands::rollback::run(action),
94
95 Commands::Reinstall {
96 names,
97 trust_mode,
98 force,
99 dry_run,
100 } => commands::reinstall::run(names, trust_mode, force, dry_run).await,
101
102 Commands::Upgrade {
103 names,
104 force,
105 check,
106 machine_readable,
107 json,
108 trust_mode,
109 dry_run,
110 } => {
111 commands::upgrade::run(
112 names,
113 force,
114 check,
115 machine_readable,
116 json,
117 trust_mode,
118 dry_run,
119 )
120 .await
121 }
122
123 Commands::List { name, json } => commands::list::run(name, json),
124
125 Commands::Changelog {
126 name,
127 from_tag,
128 to_tag,
129 } => commands::changelog::run(name, from_tag, to_tag).await,
130
131 Commands::Probe {
132 repo_slug,
133 provider,
134 base_url,
135 channel,
136 limit,
137 verbose,
138 json,
139 } => {
140 commands::probe::run(repo_slug, provider, base_url, channel, limit, verbose, json)
141 .await
142 }
143 Commands::Search {
144 query_words,
145 provider,
146 base_url,
147 limit,
148 language,
149 topic,
150 min_stars,
151 max_stars,
152 pushed_after,
153 include_forks,
154 include_archived,
155 json,
156 } => {
157 commands::search::run(
158 query_words,
159 provider,
160 base_url,
161 limit,
162 language,
163 topic,
164 min_stars,
165 max_stars,
166 pushed_after,
167 include_forks,
168 include_archived,
169 json,
170 )
171 .await
172 }
173 Commands::Find {
174 query_words,
175 provider,
176 base_url,
177 limit,
178 language,
179 topic,
180 min_stars,
181 max_stars,
182 pushed_after,
183 include_forks,
184 include_archived,
185 name,
186 kind,
187 channel,
188 match_pattern,
189 exclude_pattern,
190 desktop,
191 trust_mode,
192 dry_run,
193 } => {
194 commands::find::run(
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 .await
216 }
217
218 Commands::Config { action } => match action {
219 ConfigAction::Set { keys } => commands::config::run_set(keys),
220 ConfigAction::Get { keys } => commands::config::run_get(keys),
221 ConfigAction::List => commands::config::run_list(),
222 ConfigAction::Edit => commands::config::run_edit(),
223 ConfigAction::Reset => commands::config::run_reset(),
224 },
225
226 Commands::Package { action } => match action {
227 PackageAction::Pin { name, reason } => commands::package::run_pin(name, reason),
228 PackageAction::Unpin { name } => commands::package::run_unpin(name),
229 PackageAction::Rename { old_name, new_name } => {
230 commands::package::run_rename(old_name, new_name)
231 }
232 },
233
234 Commands::Export { path, full } => commands::export::run_export(path, full).await,
235 Commands::Migrate => commands::migrate::run(),
236 Commands::Import {
237 path,
238 skip_failed,
239 import_as,
240 } => {
241 let forced_kind = import_as.map(|value| match value {
242 ImportAs::Keys => commands::import::ImportKindArg::Keys,
243 ImportAs::Manifest => commands::import::ImportKindArg::Manifest,
244 ImportAs::Snapshot => commands::import::ImportKindArg::Snapshot,
245 });
246 commands::import::run_import(path, skip_failed, forced_kind).await
247 }
248 Commands::Doctor {
249 names,
250 verbose,
251 fix,
252 json,
253 } => commands::doctor::run(names, verbose, fix, json),
254 }
255 }
256}