This repository was archived by the owner on Nov 21, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Update to clap 4 + rework to declarative style #32
Open
tonky
wants to merge
5
commits into
makedeb:main
Choose a base branch
from
tonky:clap_4_declarative
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4a315ef
initial clap4 migration with declarative style refactor
tonky 434d98b
change to 'rust-apt' main branch
tonky ac16642
removed debug prints
tonky 3d4a43f
fix cargo fmt and clippy warnings
tonky 7960890
fix sudo checks, added missing permission check, fixed '--installed' …
tonky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| 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, | ||
|
|
||
| #[arg(long, value_enum, default_value_t=SearchMode::None)] | ||
| mode: SearchMode, | ||
|
|
||
| /// The package(s) to get information for | ||
| #[arg(required = true)] | ||
| 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, | ||
|
|
||
| /// 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, | ||
| /// Only installed packages | ||
| Installed, | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.