metapac/cli.rs
1//! The clap declarative command line interface
2
3use crate::prelude::*;
4use clap::{Args, Parser, Subcommand};
5use std::path::PathBuf;
6
7#[derive(Parser)]
8#[command(
9 version,
10 author,
11 about,
12 arg_required_else_help(true),
13 subcommand_required(true)
14)]
15pub struct Command {
16 #[arg(long)]
17 /// specify a different hostname
18 pub hostname: Option<String>,
19 #[arg(long)]
20 /// specify a different config directory
21 pub config_dir: Option<PathBuf>,
22 #[command(subcommand)]
23 pub subcommand: MainSubcommand,
24}
25
26#[derive(Subcommand)]
27pub enum MainSubcommand {
28 Update(UpdateCommand),
29 UpdateAll(UpdateAllCommand),
30 Clean(CleanCommand),
31 Sync(SyncCommand),
32 Unmanaged(UnmanagedCommand),
33 Backends(BackendsCommand),
34 CleanCache(CleanCacheCommand),
35 Completions(CompletionsCommand),
36}
37
38#[derive(Args)]
39/// update packages for the given backend
40pub struct UpdateCommand {
41 #[arg(long)]
42 /// the backend for the packages
43 pub backend: AnyBackend,
44 #[arg(long, required=true, num_args=1..)]
45 /// the package names
46 pub packages: Vec<String>,
47 #[arg(long)]
48 /// do not ask for any confirmation
49 pub no_confirm: bool,
50}
51
52#[derive(Args)]
53/// update all packages for the given backends
54pub struct UpdateAllCommand {
55 #[arg(long)]
56 /// the backends to operate on
57 ///
58 /// - if no backends are passed then the enabled_backend config is used
59 ///
60 /// - if "all" is passed by itself then all backends are used
61 ///
62 /// - otherwise the list will be parsed as a list of backends to be used
63 pub backends: Vec<String>,
64 #[arg(long)]
65 /// do not ask for any confirmation
66 pub no_confirm: bool,
67}
68
69#[derive(Args)]
70/// uninstall unmanaged packages
71pub struct CleanCommand {
72 #[arg(long)]
73 /// do not ask for any confirmation
74 pub no_confirm: bool,
75}
76
77#[derive(Args)]
78/// install missing packages from groups
79pub struct SyncCommand {
80 #[arg(long)]
81 /// do not ask for any confirmation
82 pub no_confirm: bool,
83}
84
85#[derive(Args)]
86/// show explicitly installed packages not required by metapac
87///
88/// the output is in valid toml group file format to allow writing
89/// the output to a file which can help in importing packages
90/// installed on your system into your group files
91pub struct UnmanagedCommand {}
92
93#[derive(Args)]
94/// show the backends found by metapac
95pub struct BackendsCommand {}
96
97#[derive(Args)]
98/// clean the caches for the given backends
99pub struct CleanCacheCommand {
100 #[arg(long)]
101 /// the backends to operate on
102 ///
103 /// - if no backends are passed then the enabled_backend config is used
104 ///
105 /// - if "all" is passed by itself then all backends are used
106 ///
107 /// - otherwise the list will be parsed as a list of backends to be used
108 pub backends: Vec<String>,
109}
110
111#[derive(Args)]
112/// generate shell completions
113pub struct CompletionsCommand {
114 #[arg(long)]
115 /// the shell to generate completions for
116 pub shell: AnyShell,
117}