1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// SPDX-FileCopyrightText: 2022 Aurélien Gâteau <mail@agateau.com>
//
// SPDX-License-Identifier: GPL-3.0-or-later
use anyhow::Result;
use clap::{Args, Parser, Subcommand};
use crate::app::App;
use crate::install::install;
use crate::list::list;
use crate::search::search;
use crate::setup::setup;
use crate::show::show;
use crate::ui::Ui;
use crate::uninstall::uninstall;
use crate::update::update;
use crate::upgrade::upgrade;
#[derive(Debug, Parser)]
#[clap(name = "clyde", version, about)]
pub struct Cli {
#[clap(flatten)]
global_opts: GlobalOpts,
#[clap(subcommand)]
command: Command,
}
#[derive(Debug, Subcommand)]
enum Command {
/// Setup Clyde
Setup {},
/// Update Clyde store
Update {},
/// Install applications
Install {
/// Application name, optionally suffixed with @version
///
/// @version must follow Cargo's interpretation of Semantic Versioning:
/// <https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html>
#[clap(required = true, value_name = "APPLICATION_NAME")]
package_names: Vec<String>,
},
/// Uninstall applications (alias: remove)
#[clap(alias("remove"))]
Uninstall {
/// Application name
#[clap(required = true, value_name = "APPLICATION_NAME")]
package_names: Vec<String>,
},
/// Show details about an application
Show {
/// List application files instead of showing information
#[clap(short, long)]
list: bool,
/// Application name
package_name: String,
},
/// Search for available applications
Search {
/// Search query
query: String,
},
/// List installed applications
List {},
/// Upgrade all installed applications, enforcing pinning
Upgrade {},
}
#[derive(Debug, Args)]
struct GlobalOpts {
/// Verbosity level (can be specified multiple times)
#[clap(long, short, global = true, parse(from_occurrences))]
verbose: usize,
}
impl Cli {
pub fn exec(self) -> Result<()> {
let ui = Ui::default();
let home = App::find_home(&ui)?;
match self.command {
Command::Setup {} => setup(&ui, &home),
Command::Update {} => {
let app = App::new(&home)?;
update(&app, &ui)
}
Command::Install { package_names } => {
let app = App::new(&home)?;
install(&app, &ui, &package_names)
}
Command::Uninstall { package_names } => {
let app = App::new(&home)?;
uninstall(&app, &ui, &package_names)
}
Command::Show { package_name, list } => {
let app = App::new(&home)?;
show(&app, &package_name, list)
}
Command::Search { query } => {
let app = App::new(&home)?;
search(&app, &query)
}
Command::List {} => {
let app = App::new(&home)?;
list(&app)
}
Command::Upgrade {} => {
let app = App::new(&home)?;
upgrade(&app, &ui)
}
}
}
}