Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to clap 4 + rework to declarative style #32

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 65 additions & 13 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ categories = ["command-line-utilities"]
bat = { version = "0.21.0", default-features = false, features = ["paging", "regex-fancy"]}
colored = { git = "https://github.com/mackwic/colored" }
chrono = "0.4.19"
clap = { version = "3.2.16", features = ["cargo", "env"] }
clap = { version = "4", features = ["cargo", "derive", "env"] }
dirs = "4.0.0"
edit = "0.1.4"
exitcode = "1.1.2"
flate2 = "1.0.24"
itertools = "0.10.5"
lazy_static = "1.4.0"
makedeb-srcinfo = "0.8.0"
quit = "1.1.4"
regex = "1.6.0"
reqwest = { version = "0.11.11", features = ["blocking", "json"] }
rust-apt = { git = "https://gitlab.com/volian/rust-apt", branch = "fix/tagfile-parsing" }
rust-apt = { git = "https://gitlab.com/volian/rust-apt" }
serde = { version = "1.0.142", features = ["derive"] }
serde_json = "1.0.83"
tempfile = "3.3.0"
Expand Down
188 changes: 188 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
use clap::{Args, Parser, Subcommand, ValueEnum};

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}

#[derive(Subcommand)]
pub enum Commands {
/// Clone a package base from the MPR
Clone {
/// The package to clone
#[arg(required = true)]
package_name: String,

#[command(flatten)]
mpr_url: MprURL,
},
/// Comment on a package page
Comment {
/// The package to comment on
#[arg(required = true)]
package_name: String,

/// The comment to post
#[arg(short, long = "msg")]
message: Option<String>,

#[command(flatten)]
mpr_url: MprURL,

#[command(flatten)]
mpr_token: MprToken,
},
/// Install packages from APT and the MPR
Install {
/// The package(s) to install
#[arg(required = true)]
package_names: Vec<String>,

#[command(flatten)]
mpr_url: MprURL,
},
/// List packages available via APT and the MPR
List {
#[command(flatten)]
mpr_url: MprURL,

/// Output the package's name without any extra details
#[arg(long = "name-only", default_value_t = false)]
name_only: bool,

/// Only installed packages
#[arg(long = "installed-only", default_value_t = false)]
installed_only: bool,

#[arg(long, value_enum, default_value_t=SearchMode::None)]
mode: SearchMode,

/// The package(s) to get information for
#[arg(required = false)]
package_names: Vec<String>,
},
/// List the comments on a package
ListComments {
#[command(flatten)]
mpr_url: MprURL,

/// When to send output to a pager
#[arg(long, value_enum, default_value_t=Paging::Auto)]
paging: Paging,

/// The package(s) to get information for
#[arg(required = true)]
package_name: String,
},
/// Remove packages from the system
Remove {
#[command(flatten)]
mpr_url: MprURL,

/// Remove configuration files along with the package(s)
#[arg(long)]
purge: bool,

/// Remove configuration files along with the package(s)
#[arg(long)]
autoremove: bool,

/// The package(s) to get information for
#[arg(required = true)]
package_names: Vec<String>,
},
/// Search for an APT/MPR package
Search {
#[command(flatten)]
mpr_url: MprURL,

/// Output the package's name without any extra details
#[arg(long = "name-only", default_value_t = false)]
name_only: bool,

#[arg(long, value_enum, default_value_t=SearchMode::None)]
mode: SearchMode,

/// Only installed packages
#[arg(long = "installed-only", default_value_t = false)]
installed_only: bool,

/// The package(s) to get information for
#[arg(required = true)]
query: Vec<String>,
},
/// Update the APT cache on the system
Update {
#[command(flatten)]
mpr_url: MprURL,
},
/// Upgrade the packages on the system
Upgrade {
#[command(flatten)]
mpr_url: MprURL,

#[arg(long, value_enum, default_value_t=UpgradeMode::Both)]
mode: UpgradeMode,
},
/// Show the currently authenticated user
Whoami {
#[command(flatten)]
mpr_url: MprURL,

#[command(flatten)]
mpr_token: MprToken,
},
}

#[derive(Clone, Debug, ValueEnum)]
pub enum UpgradeMode {
/// Upgrade both APT and MPR packages
Both,
/// Only upgrade APT packages
AptOnly,
/// Only upgrade MPR packages
MprOnly,
}

#[derive(Clone, Debug, ValueEnum)]
pub enum Paging {
Auto,
Always,
Never,
}

#[derive(Args)]
pub struct MprURL {
/// URL to access the MPR from
#[arg(
env = "MPR_URL",
default_value = "https://mpr.makedeb.org",
long = "mpr-url"
)]
pub url: String,
}

#[derive(Args)]
pub struct MprToken {
/// The API token to authenticate to the MPR with
#[arg(
env = "MPR_TOKEN",
required = true,
hide_env_values = true,
long = "token"
)]
pub token: String,
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
pub enum SearchMode {
/// No filter applied
None,
/// Only packages available on the MPR
MprOnly,
/// Only packages available via APT
AptOnly,
}
Loading