From 975559e7202821ff7357e94c132f4315a5ddf8a2 Mon Sep 17 00:00:00 2001 From: pvshvp-oss Date: Sun, 12 May 2024 13:21:21 -0500 Subject: [PATCH] WIP --- Cargo.toml | 2 + paxy-cli/src/lib.rs | 476 ++++-------------- paxy-cli/src/main.rs | 4 +- paxy-gui/src/lib.rs | 100 +--- paxy-gui/src/main.rs | 4 +- paxy/src/{actions/mod.rs => action.rs} | 16 +- .../package/mod.rs => action/package.rs} | 1 + paxy/src/action/package/downgrade.rs | 22 + .../{actions => action}/package/install.rs | 9 + .../repository => action/package}/list.rs | 9 + .../src/{actions => action}/package/search.rs | 9 + paxy/src/action/package/uninstall.rs | 22 + .../src/{actions => action}/package/update.rs | 9 + .../mod.rs => action/repository.rs} | 1 + paxy/src/action/repository/downgrade.rs | 22 + .../{actions => action}/repository/install.rs | 10 +- .../package => action/repository}/list.rs | 9 + paxy/src/action/repository/search.rs | 22 + paxy/src/action/repository/uninstall.rs | 22 + paxy/src/action/repository/update.rs | 22 + paxy/src/actions/package/downgrade.rs | 13 - paxy/src/actions/package/uninstall.rs | 13 - paxy/src/actions/repository/downgrade.rs | 13 - paxy/src/actions/repository/search.rs | 13 - paxy/src/actions/repository/uninstall.rs | 13 - paxy/src/actions/repository/update.rs | 13 - paxy/src/{app/mod.rs => app.rs} | 16 +- paxy/src/app/ui.rs | 124 +---- paxy/src/app/ui/console_template.rs | 125 +++++ paxy/src/app/ui/console_template/cli.rs | 370 ++++++++++++++ paxy/src/app/ui/console_template/gui.rs | 58 +++ paxy/src/{data/mod.rs => data.rs} | 20 +- paxy/src/lib.rs | 27 +- 33 files changed, 890 insertions(+), 719 deletions(-) rename paxy/src/{actions/mod.rs => action.rs} (52%) rename paxy/src/{actions/package/mod.rs => action/package.rs} (97%) create mode 100644 paxy/src/action/package/downgrade.rs rename paxy/src/{actions => action}/package/install.rs (62%) rename paxy/src/{actions/repository => action/package}/list.rs (50%) rename paxy/src/{actions => action}/package/search.rs (50%) create mode 100644 paxy/src/action/package/uninstall.rs rename paxy/src/{actions => action}/package/update.rs (50%) rename paxy/src/{actions/repository/mod.rs => action/repository.rs} (98%) create mode 100644 paxy/src/action/repository/downgrade.rs rename paxy/src/{actions => action}/repository/install.rs (88%) rename paxy/src/{actions/package => action/repository}/list.rs (50%) create mode 100644 paxy/src/action/repository/search.rs create mode 100644 paxy/src/action/repository/uninstall.rs create mode 100644 paxy/src/action/repository/update.rs delete mode 100644 paxy/src/actions/package/downgrade.rs delete mode 100644 paxy/src/actions/package/uninstall.rs delete mode 100644 paxy/src/actions/repository/downgrade.rs delete mode 100644 paxy/src/actions/repository/search.rs delete mode 100644 paxy/src/actions/repository/uninstall.rs delete mode 100644 paxy/src/actions/repository/update.rs rename paxy/src/{app/mod.rs => app.rs} (93%) create mode 100644 paxy/src/app/ui/console_template.rs create mode 100644 paxy/src/app/ui/console_template/cli.rs create mode 100644 paxy/src/app/ui/console_template/gui.rs rename paxy/src/{data/mod.rs => data.rs} (80%) diff --git a/Cargo.toml b/Cargo.toml index 509bce6..8112f84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,8 @@ license = "MPL-2.0" [workspace.dependencies] paxy = { path = "paxy" } +paxy-cli = {path = "paxy-cli"} +paxy-gui = {path = "paxy-gui"} # Logging tracing = "0.1" diff --git a/paxy-cli/src/lib.rs b/paxy-cli/src/lib.rs index 0006965..c11e701 100644 --- a/paxy-cli/src/lib.rs +++ b/paxy-cli/src/lib.rs @@ -1,12 +1,11 @@ -//! Has the [`run_cli`] function and the commandline interface template -//! [`cli_template::CliTemplate`] +//! Has the [`run_cli`] function /// Calls the [`ui::run_common::`] function supplying it with the commandline /// interface template as a type. Any errors are thrown back to the calling /// function. A debug message is then displayed conveying that the program is /// being run in the CLI mode. pub fn run_cli() -> Result<(), paxy::Error> { - let (_cli_input, _logging_worker_guards) = ui::run_common::()?; + let (cli_input, _logging_worker_guards) = ui::run_common::()?; tracing::debug!( "Running in {} mode... {}", @@ -14,6 +13,87 @@ pub fn run_cli() -> Result<(), paxy::Error> { console::Emoji("🔤", "") ); + if let Some(entity) = cli_input.entity { + match entity { + EntitySubcommand::Package(package_subcommand) => match package_subcommand { + PackageSubcommand::List(package_list_arguments) => { + package::list::run_list(package_list_arguments) + .context(paxy::action::package::CouldNotListSnafu {}) + .context(paxy::action::PackageSnafu) + .context(paxy::ActionSnafu)? + } + PackageSubcommand::Search(package_search_arguments) => { + package::search::run_search(package_search_arguments) + .context(paxy::action::package::CouldNotSearchSnafu {}) + .context(paxy::action::PackageSnafu) + .context(paxy::ActionSnafu)?; + } + PackageSubcommand::Install(package_install_arguments) => { + package::install::run_install(package_install_arguments) + .context(paxy::action::package::CouldNotInstallSnafu {}) + .context(paxy::action::PackageSnafu) + .context(paxy::ActionSnafu)?; + } + PackageSubcommand::Update(package_update_arguments) => { + package::update::run_update(package_update_arguments) + .context(paxy::action::package::CouldNotUpdateSnafu {}) + .context(paxy::action::PackageSnafu) + .context(paxy::ActionSnafu)?; + } + PackageSubcommand::Uninstall(package_uninstall_arguments) => { + package::uninstall::run_uninstall(package_uninstall_arguments) + .context(paxy::action::package::CouldNotUninstallSnafu {}) + .context(paxy::action::PackageSnafu) + .context(paxy::ActionSnafu)?; + } + PackageSubcommand::Downgrade(package_downgrade_arguments) => { + package::downgrade::run_downgrade(package_downgrade_arguments) + .context(paxy::action::package::CouldNotDowngradeSnafu {}) + .context(paxy::action::PackageSnafu) + .context(paxy::ActionSnafu)?; + } + }, + EntitySubcommand::Repository(repository_subcommand) => match repository_subcommand { + RepositorySubcommand::List(repository_list_arguments) => { + repository::list::run_list(repository_list_arguments) + .context(paxy::action::repository::CouldNotListSnafu {}) + .context(paxy::action::RepositorySnafu) + .context(paxy::ActionSnafu)?; + } + RepositorySubcommand::Search(repository_search_arguments) => { + repository::search::run_search(repository_search_arguments) + .context(paxy::action::repository::CouldNotSearchSnafu {}) + .context(paxy::action::RepositorySnafu) + .context(paxy::ActionSnafu)?; + } + RepositorySubcommand::Install(repository_install_arguments) => { + repository::install::run_install(repository_install_arguments) + .context(paxy::action::repository::CouldNotInstallSnafu {}) + .context(paxy::action::RepositorySnafu) + .context(paxy::ActionSnafu)?; + } + RepositorySubcommand::Update(repository_update_arguments) => { + repository::update::run_update(repository_update_arguments) + .context(paxy::action::repository::CouldNotUpdateSnafu {}) + .context(paxy::action::RepositorySnafu) + .context(paxy::ActionSnafu)?; + } + RepositorySubcommand::Uninstall(repository_uninstall_arguments) => { + repository::uninstall::run_uninstall(repository_uninstall_arguments) + .context(paxy::action::repository::CouldNotUninstallSnafu {}) + .context(paxy::action::RepositorySnafu) + .context(paxy::ActionSnafu)?; + } + RepositorySubcommand::Downgrade(repository_downgrade_arguments) => { + repository::downgrade::run_downgrade(repository_downgrade_arguments) + .context(paxy::action::repository::CouldNotDowngradeSnafu {}) + .context(paxy::action::RepositorySnafu) + .context(paxy::ActionSnafu)?; + } + }, + } + } + Ok(()) } @@ -28,390 +108,10 @@ pub enum Error { // region: IMPORTS use owo_colors::OwoColorize; -use paxy::app::ui; -use snafu::Snafu; +use paxy::{ + action::{package, repository}, + app::ui, +}; +use snafu::{ResultExt, Snafu}; // endregion: IMPORTS - -// region: MODULES - -/// This module is a [*derive* interface template](https://docs.rs/clap/latest/clap/_derive/_tutorial/chapter_0/index.html) specifically for -/// use with the `clap` library. Any other commandline-related code that is not -/// part of the `clap` derive template will not be in this module. -/// The CLI is designed to (as much as possible,) follow the guidelines in -/// https://clig.dev/ . As a consequence, the command structure follows the -/// 'application_name noun verb' order of subcommands. For example: -/// `paxy package list [args]`, `paxy repo add [args]` -mod cli_template { - - /// The base commandline template consists of global arguments, a subcommand - /// that denotes the entity that is being operated upon (like a package or - /// repository), and optionally, arguments for the default subcommand (in - /// this case, the 'package' entity is assumed chosen to act on, by - /// default). - #[derive(Debug, Parser)] - #[command( - version, - author, - about, - args_conflicts_with_subcommands = true, - propagate_version = true - )] - pub struct CliTemplate { - #[command(flatten)] - pub global_args: ui::cli_template::GlobalArgs, - - #[command(subcommand)] - pub entity: Option, - } - - /// Implement a trait that can extract standard global arguments from our - /// own CLI template - impl ui::GlobalArguments for CliTemplate { - fn config_filepath(&self) -> &Option { - self.global_args - .config_filepath() - } - - fn is_json(&self) -> bool { - self.global_args - .is_json() - } - - fn is_plain(&self) -> bool { - self.global_args - .is_plain() - } - - fn is_debug(&self) -> bool { - self.global_args - .is_debug() - } - - fn is_test(&self) -> bool { - self.global_args - .is_test() - } - - fn is_no_color(&self) -> bool { - self.global_args - .is_no_color() - } - - fn verbosity_filter(&self) -> log::LevelFilter { - self.global_args - .verbosity_filter() - } - } - - #[derive(Debug, Subcommand)] - #[command(args_conflicts_with_subcommands = true)] - pub enum EntitySubcommand { - #[command( - name = "package", - about = "Perform actions on package(s).", - subcommand, - display_order = 1 - )] - Package(PackageSubcommand), - - #[command( - subcommand, - name = "repository", - alias = "repo", - about = "Perform actions on repository(-ies).", - display_order = 2 - )] - Repository(RepositorySubcommand), - } - - #[derive(Debug, Subcommand)] - #[command(args_conflicts_with_subcommands = true)] - pub enum PackageSubcommand { - #[command(name = "list", about = "List installed packages.", display_order = 1)] - List(PackageListArguments), - - #[command( - name = "search", - alias = "find", - about = "Search for available packages.", - display_order = 2 - )] - Search(PackageSearchArguments), - - #[command( - name = "install", - alias = "add", - about = "Install packages.", - display_order = 3 - )] - Install(PackageInstallArguments), - - #[command( - name = "update", - alias = "upgrade", - about = "Update packages.", - display_order = 4 - )] - Update(PackageUpdateArguments), - - #[command( - name = "uninstall", - alias = "remove", - about = "Uninstall packages.", - display_order = 5 - )] - Uninstall(PackageUninstallArguments), - - #[command(name = "downgrade", about = "Downgrade a package.", display_order = 5)] - Downgrade(PackageDowngradeArguments), - } - - #[derive(Debug, Subcommand)] - #[command(args_conflicts_with_subcommands = true)] - pub enum RepositorySubcommand { - #[command( - name = "list", - about = "List installed repositories.", - display_order = 1 - )] - List(RepositoryListArguments), - - #[command( - name = "search", - alias = "find", - about = "Search for available repositories.", - display_order = 2 - )] - Search(RepositorySearchArguments), - - #[command( - name = "install", - alias = "add", - about = "Install repositories.", - display_order = 3 - )] - Install(RepositoryInstallArguments), - - #[command( - name = "update", - alias = "upgrade", - about = "Update repositories.", - display_order = 4 - )] - Update(RepositoryUpdateArguments), - - #[command( - name = "uninstall", - alias = "remove", - about = "Uninstall repositories.", - display_order = 5 - )] - Uninstall(RepositoryUninstallArguments), - - #[command( - name = "downgrade", - about = "Downgrade a repositories.", - display_order = 5 - )] - Downgrade(RepositoryDowngradeArguments), - } - - #[derive(Debug, Args)] - pub struct PackageListArguments { - #[arg( - long = "exclude", - alias = "ignore", - short = 'e', - help = "Partial or full name(s) of packages to exclude from the search among the installed packages.", - display_order = 1 - )] - pub excluded_partial_package_names: Vec, - - #[arg( - help = "Partial or full name(s) of the packages to search among the installed packages. Not specifying this argument will list all packages.", - display_order = usize::MAX - 1, - )] - pub partial_package_name: Vec, - } - - #[derive(Debug, Args)] - pub struct PackageSearchArguments { - #[arg( - long = "exclude", - alias = "ignore", - short = 'e', - help = "Partial or full name(s) of packages to exclude from the search among available packages.", - display_order = 1 - )] - pub excluded_partial_package_names: Vec, - - #[arg( - help = "Partial or full name(s) of the packages to search among available packages.", - last = true, - display_order = usize::MAX - 1 - )] - pub partial_package_name: Vec, - } - - #[derive(Debug, Args)] - pub struct PackageInstallArguments { - #[arg(help = "Full name(s) of the packages to install.", display_order = usize::MAX - 1)] - pub package_names: Vec, - } - - #[derive(Debug, Args)] - pub struct PackageUpdateArguments { - #[arg( - long = "exclude", - alias = "ignore", - short = 'e', - help = "Full name(s) of packages to exclude from updating.", - display_order = 1 - )] - pub excluded_package_names: Vec, - - #[arg( - help = "Full name(s) of the packages to update. Not specifying this argument will update all packages", - last = true, - display_order = usize::MAX - 1 - )] - pub package_names: Vec, - } - - #[derive(Debug, Args)] - pub struct PackageUninstallArguments { - #[arg( - help = "Full name(s) of the packages to uninstall.", - last = true, - display_order = usize::MAX - 1 - )] - pub package_names: Vec, - } - - #[derive(Debug, Args)] - pub struct PackageDowngradeArguments { - #[arg( - long = "version", - alias = "ver", - help = "The version to downgrade to.", - display_order = 1 - )] - pub version: Option, - - #[arg( - help = "Full name of the package to downgrade.", - last = true, - display_order = usize::MAX - 1 - )] - pub package_name: String, - } - - #[derive(Debug, Args)] - pub struct RepositoryListArguments { - #[arg( - long = "exclude", - alias = "ignore", - short = 'e', - help = "Partial or full name(s) of repositories to exclude from the search among the installed repositories.", - display_order = 1 - )] - pub excluded_partial_repository_names: Vec, - - #[arg( - help = "Partial or full name(s) of the repositories to search among the installed repositories. Not specifying this argument will list all repositories.", - last = true, - display_order = usize::MAX - 1, - )] - pub partial_repository_name: Vec, - } - - #[derive(Debug, Args)] - pub struct RepositorySearchArguments { - #[arg( - long = "exclude", - alias = "ignore", - short = 'e', - help = "Partial or full name(s) of repositories to exclude from the search among available repositories.", - display_order = 1 - )] - pub excluded_partial_repository_names: Vec, - - #[arg( - help = "Partial or full name(s) of the repositories to search among available repositories.", - last = true, - display_order = usize::MAX - 1 - )] - pub partial_repository_name: String, - } - - #[derive(Debug, Args)] - pub struct RepositoryInstallArguments { - #[arg(help = "Full name(s) of the repositories to install.", display_order = usize::MAX - 1)] - pub repository_names: Vec, - } - - #[derive(Debug, Args)] - pub struct RepositoryUpdateArguments { - #[arg( - long = "exclude", - alias = "ignore", - short = 'e', - help = "Full name(s) of repositories to exclude from updating.", - display_order = 1 - )] - pub excluded_repository_names: Vec, - - #[arg( - help = "Full name(s) of the repositories to update. Not specifying this argument will update all repositories", - last = true, - display_order = usize::MAX - 1 - )] - pub repository_names: Vec, - } - - #[derive(Debug, Args)] - pub struct RepositoryUninstallArguments { - #[arg( - help = "Full name(s) of the repositories to uninstall.", - last = true, - display_order = usize::MAX - 1 - )] - pub repository_names: Vec, - } - - #[derive(Debug, Args)] - pub struct RepositoryDowngradeArguments { - #[arg( - long = "version", - alias = "ver", - help = "The version to downgrade to.", - display_order = 1 - )] - pub version: Option, - - #[arg( - help = "Full name of the repository to downgrade.", - last = true, - display_order = usize::MAX - 1 - )] - pub repository_name: String, - } - - // region: IMPORTS - - use std::path::PathBuf; - - use clap::{Args, Parser, Subcommand}; - use paxy::app::ui; - - // endregion: IMPORTS -} - -// endregion: MODULES - -// region: RE-EXPORTS - -pub use cli_template::*; // Flatten the module heirarchy for easier access - -// endregion: RE-EXPORTS diff --git a/paxy-cli/src/main.rs b/paxy-cli/src/main.rs index 73509b7..f4b8c66 100644 --- a/paxy-cli/src/main.rs +++ b/paxy-cli/src/main.rs @@ -1,12 +1,12 @@ //! Starts execution at the [`main`] function. Offloads the implemenation //! details to its corresponding library crate. -/// Calls the [`paxy_cli::run_cli`] function and captures the returned +/// Calls the [`crate::run_cli`] function and captures the returned /// [`Result`]. If there was an error, the error message chain is printed to the /// standard error stream (`stderr`). The program then returns an `0` or `1` /// corresponding to "no error" or "error" based on the result. fn main() -> process::ExitCode { - let return_value = paxy_cli::run_cli(); + let return_value = crate::run_cli(); match return_value { Ok(_) => process::ExitCode::from(0), Err(err_value) => { diff --git a/paxy-gui/src/lib.rs b/paxy-gui/src/lib.rs index 4694307..eb00aae 100644 --- a/paxy-gui/src/lib.rs +++ b/paxy-gui/src/lib.rs @@ -1,12 +1,11 @@ -//! Has the [`run_gui`] function and the commandline interface template -//! [`gui_cli_template::CliTemplate`] +//! Has the [`run_gui`] function -/// Calls the [`ui::run_common::`] function supplying it with the commandline -/// interface template as a type. Any errors are thrown back to the calling -/// function. A debug message is then displayed conveying that the program is -/// being run in the GUI mode. +/// Calls the [`ui::run_common::`] function supplying it with the +/// commandline interface template as a type. Any errors are thrown +/// back to the calling function. A debug message is then displayed +/// conveying that the program is being run in the GUI mode. pub fn run_gui() -> Result<(), paxy::Error> { - let (_cli_input, _logging_worker_guards) = ui::run_common::()?; + let (_cli_input, _logging_worker_guards) = paxy::ui::run_common::()?; tracing::debug!( "Running in {} mode... {}", @@ -16,90 +15,3 @@ pub fn run_gui() -> Result<(), paxy::Error> { Ok(()) } - -#[derive(Debug, Snafu)] -#[non_exhaustive] -pub enum Error { - #[non_exhaustive] - #[snafu(display(""), visibility(pub))] - GuiDummy {}, // No errors implemented yet -} - -// region: IMPORTS - -use owo_colors::OwoColorize; -use paxy::app::ui; -use snafu::Snafu; - -// endregion: IMPORTS - -// region: MODULES - -/// The commandline interface for the GUI program. Allows one to specify flags -/// that control output on a console. -mod gui_cli_template { - - /// The base commandline template consists of global arguments - #[derive(Parser, Debug)] - #[command(version, author, about, args_conflicts_with_subcommands = true)] - pub struct CliTemplate { - #[clap(flatten)] - pub global_args: ui::cli_template::GlobalArgs, - } - - /// Implement a trait that can extract standard global arguments from our - /// own CLI template - impl ui::GlobalArguments for CliTemplate { - fn config_filepath(&self) -> &Option { - self.global_args - .config_filepath() - } - - fn is_json(&self) -> bool { - self.global_args - .is_json() - } - - fn is_plain(&self) -> bool { - self.global_args - .is_plain() - } - - fn is_debug(&self) -> bool { - self.global_args - .is_debug() - } - - fn is_test(&self) -> bool { - self.global_args - .is_test() - } - - fn is_no_color(&self) -> bool { - self.global_args - .is_no_color() - } - - fn verbosity_filter(&self) -> log::LevelFilter { - self.global_args - .verbosity_filter() - } - } - - // region: IMPORTS - - use std::path::PathBuf; - - use clap::Parser; - use paxy::app::ui; - - // endregion: IMPORTS -} - -// endregion: MODULES - -// region: RE-EXPORTS - -pub use gui_cli_template::*; // Flatten the module heirarchy for easier access - -// endregion: RE-EXPORTS diff --git a/paxy-gui/src/main.rs b/paxy-gui/src/main.rs index f96597b..ab0a734 100644 --- a/paxy-gui/src/main.rs +++ b/paxy-gui/src/main.rs @@ -1,12 +1,12 @@ //! Starts execution at the [`main`] function. Offloads the implemenation //! details to its corresponding library crate. -/// Calls the [`paxy_gui::run_gui`] function and captures the returned +/// Calls the [`crate::run_gui`] function and captures the returned /// [`Result`]. If there was an error, the error message chain is printed to the /// standard error stream (`stderr`). The program then returns an `0` or `1` /// corresponding to "no error" or "error" based on the result. fn main() -> process::ExitCode { - let return_value = paxy_gui::run_gui(); + let return_value = crate::run_gui(); match return_value { Ok(_) => process::ExitCode::from(0), Err(err_value) => { diff --git a/paxy/src/actions/mod.rs b/paxy/src/action.rs similarity index 52% rename from paxy/src/actions/mod.rs rename to paxy/src/action.rs index 1c95950..3336f0c 100644 --- a/paxy/src/actions/mod.rs +++ b/paxy/src/action.rs @@ -1,28 +1,30 @@ +// region: ERRORS + #[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] - #[snafu(display("Could not list:\n {source}"))] + #[snafu(display("Could not complete package action:\n {source}"))] PackageError { source: package::Error }, #[non_exhaustive] - #[snafu(display("Could not search:\n {source}"))] + #[snafu(display("Could not complete repository action:\n {source}"))] RepositoryError { source: repository::Error }, } +// endregion: ERRORS + // region: IMPORTS use snafu::Snafu; // endregion: IMPORTS -// region: MODULES +// region: EXTERNAL-SUBMODULES pub mod package; pub mod repository; -// endregion: MODULES - -// region: RE-EXPORTS +// region: EXTERNAL-SUBMODULES -// endregion: RE-EXPORTS diff --git a/paxy/src/actions/package/mod.rs b/paxy/src/action/package.rs similarity index 97% rename from paxy/src/actions/package/mod.rs rename to paxy/src/action/package.rs index 2f29ebf..a283272 100644 --- a/paxy/src/actions/package/mod.rs +++ b/paxy/src/action/package.rs @@ -1,4 +1,5 @@ #[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] diff --git a/paxy/src/action/package/downgrade.rs b/paxy/src/action/package/downgrade.rs new file mode 100644 index 0000000..b8bb501 --- /dev/null +++ b/paxy/src/action/package/downgrade.rs @@ -0,0 +1,22 @@ +pub fn run_downgrade( + package_downgrade_arguments: ui::cli_template::PackageDowngradeArguments, +) -> Result<(), Error> { + todo!() +} + +#[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] +#[non_exhaustive] +pub enum Error { + #[non_exhaustive] + #[snafu(display(""))] + Dummy {}, +} + +// region: IMPORTS + +use snafu::Snafu; + +use crate::app::ui; + +// endregion: IMPORTS diff --git a/paxy/src/actions/package/install.rs b/paxy/src/action/package/install.rs similarity index 62% rename from paxy/src/actions/package/install.rs rename to paxy/src/action/package/install.rs index f82bb36..e0ca03c 100644 --- a/paxy/src/actions/package/install.rs +++ b/paxy/src/action/package/install.rs @@ -1,4 +1,11 @@ +pub fn run_install( + package_install_arguments: ui::cli_template::PackageInstallArguments, +) -> Result<(), Error> { + todo!() +} + #[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] @@ -12,6 +19,8 @@ use std::path::PathBuf; use snafu::Snafu; +use crate::app::ui; + // endregion: IMPORTS #[allow(dead_code)] #[allow(unused_variables)] diff --git a/paxy/src/actions/repository/list.rs b/paxy/src/action/package/list.rs similarity index 50% rename from paxy/src/actions/repository/list.rs rename to paxy/src/action/package/list.rs index 6e9cd4b..f3b5c0c 100644 --- a/paxy/src/actions/repository/list.rs +++ b/paxy/src/action/package/list.rs @@ -1,4 +1,11 @@ +pub fn run_list( + package_list_arguments: ui::cli_template::PackageListArguments, +) -> Result<(), Error> { + todo!() +} + #[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] @@ -10,4 +17,6 @@ pub enum Error { use snafu::Snafu; +use crate::app::ui; + // endregion: IMPORTS diff --git a/paxy/src/actions/package/search.rs b/paxy/src/action/package/search.rs similarity index 50% rename from paxy/src/actions/package/search.rs rename to paxy/src/action/package/search.rs index 6e9cd4b..3636629 100644 --- a/paxy/src/actions/package/search.rs +++ b/paxy/src/action/package/search.rs @@ -1,4 +1,11 @@ +pub fn run_search( + package_search_arguments: ui::cli_template::PackageSearchArguments, +) -> Result<(), Error> { + todo!() +} + #[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] @@ -10,4 +17,6 @@ pub enum Error { use snafu::Snafu; +use crate::app::ui; + // endregion: IMPORTS diff --git a/paxy/src/action/package/uninstall.rs b/paxy/src/action/package/uninstall.rs new file mode 100644 index 0000000..4da4f47 --- /dev/null +++ b/paxy/src/action/package/uninstall.rs @@ -0,0 +1,22 @@ +pub fn run_uninstall( + package_uninstall_arguments: ui::cli_template::PackageUninstallArguments, +) -> Result<(), Error> { + todo!() +} + +#[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] +#[non_exhaustive] +pub enum Error { + #[non_exhaustive] + #[snafu(display(""))] + Dummy {}, +} + +// region: IMPORTS + +use snafu::Snafu; + +use crate::app::ui; + +// endregion: IMPORTS diff --git a/paxy/src/actions/package/update.rs b/paxy/src/action/package/update.rs similarity index 50% rename from paxy/src/actions/package/update.rs rename to paxy/src/action/package/update.rs index 6e9cd4b..80d1244 100644 --- a/paxy/src/actions/package/update.rs +++ b/paxy/src/action/package/update.rs @@ -1,4 +1,11 @@ +pub fn run_update( + package_update_arguments: ui::cli_template::PackageUpdateArguments, +) -> Result<(), Error> { + todo!() +} + #[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] @@ -10,4 +17,6 @@ pub enum Error { use snafu::Snafu; +use crate::app::ui; + // endregion: IMPORTS diff --git a/paxy/src/actions/repository/mod.rs b/paxy/src/action/repository.rs similarity index 98% rename from paxy/src/actions/repository/mod.rs rename to paxy/src/action/repository.rs index 9f32561..ad618d4 100644 --- a/paxy/src/actions/repository/mod.rs +++ b/paxy/src/action/repository.rs @@ -24,6 +24,7 @@ pub fn ensure_path(path: Option<&PathBuf>) { } #[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] diff --git a/paxy/src/action/repository/downgrade.rs b/paxy/src/action/repository/downgrade.rs new file mode 100644 index 0000000..75aaab3 --- /dev/null +++ b/paxy/src/action/repository/downgrade.rs @@ -0,0 +1,22 @@ +pub fn run_downgrade( + repository_downgrade_arguments: ui::cli_template::RepositoryDowngradeArguments, +) -> Result<(), Error> { + todo!() +} + +#[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] +#[non_exhaustive] +pub enum Error { + #[non_exhaustive] + #[snafu(display(""))] + Dummy {}, +} + +// region: IMPORTS + +use snafu::Snafu; + +use crate::app::ui; + +// endregion: IMPORTS diff --git a/paxy/src/actions/repository/install.rs b/paxy/src/action/repository/install.rs similarity index 88% rename from paxy/src/actions/repository/install.rs rename to paxy/src/action/repository/install.rs index f34d834..a06eaba 100644 --- a/paxy/src/actions/repository/install.rs +++ b/paxy/src/action/repository/install.rs @@ -1,3 +1,9 @@ +pub fn run_install( + repository_install_arguments: ui::cli_template::RepositoryInstallArguments, +) -> Result<(), Error> { + todo!() +} + #[allow(unused)] fn add_repo(repo: &str, name: &str) { let mut file = super::home!(); @@ -35,6 +41,7 @@ fn plugin(manifest: PathBuf) -> PathBuf { } #[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] @@ -54,7 +61,8 @@ use git2::Repository; use log::{info, warn}; use snafu::Snafu; -use crate::actions::repository::ensure_path; +use crate::action::repository::ensure_path; +use crate::app::ui; // endregion: IMPORTS diff --git a/paxy/src/actions/package/list.rs b/paxy/src/action/repository/list.rs similarity index 50% rename from paxy/src/actions/package/list.rs rename to paxy/src/action/repository/list.rs index 6e9cd4b..2fdf8ed 100644 --- a/paxy/src/actions/package/list.rs +++ b/paxy/src/action/repository/list.rs @@ -1,4 +1,11 @@ +pub fn run_list( + repository_list_arguments: ui::cli_template::RepositoryListArguments, +) -> Result<(), Error> { + todo!() +} + #[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] @@ -10,4 +17,6 @@ pub enum Error { use snafu::Snafu; +use crate::app::ui; + // endregion: IMPORTS diff --git a/paxy/src/action/repository/search.rs b/paxy/src/action/repository/search.rs new file mode 100644 index 0000000..6d05a00 --- /dev/null +++ b/paxy/src/action/repository/search.rs @@ -0,0 +1,22 @@ +pub fn run_search( + repository_search_arguments: ui::cli_template::RepositorySearchArguments, +) -> Result<(), Error> { + todo!() +} + +#[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] +#[non_exhaustive] +pub enum Error { + #[non_exhaustive] + #[snafu(display(""))] + Dummy {}, +} + +// region: IMPORTS + +use snafu::Snafu; + +use crate::app::ui; + +// endregion: IMPORTS diff --git a/paxy/src/action/repository/uninstall.rs b/paxy/src/action/repository/uninstall.rs new file mode 100644 index 0000000..6fa0065 --- /dev/null +++ b/paxy/src/action/repository/uninstall.rs @@ -0,0 +1,22 @@ +pub fn run_uninstall( + repository_uninstall_arguments: ui::cli_template::RepositoryUninstallArguments, +) -> Result<(), Error> { + todo!() +} + +#[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] +#[non_exhaustive] +pub enum Error { + #[non_exhaustive] + #[snafu(display(""))] + Dummy {}, +} + +// region: IMPORTS + +use snafu::Snafu; + +use crate::app::ui; + +// endregion: IMPORTS diff --git a/paxy/src/action/repository/update.rs b/paxy/src/action/repository/update.rs new file mode 100644 index 0000000..971f9dc --- /dev/null +++ b/paxy/src/action/repository/update.rs @@ -0,0 +1,22 @@ +pub fn run_update( + repository_update_arguments: ui::cli_template::RepositoryUpdateArguments, +) -> Result<(), Error> { + todo!() +} + +#[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] +#[non_exhaustive] +pub enum Error { + #[non_exhaustive] + #[snafu(display(""))] + Dummy {}, +} + +// region: IMPORTS + +use snafu::Snafu; + +use crate::app::ui; + +// endregion: IMPORTS diff --git a/paxy/src/actions/package/downgrade.rs b/paxy/src/actions/package/downgrade.rs deleted file mode 100644 index 6e9cd4b..0000000 --- a/paxy/src/actions/package/downgrade.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[derive(Debug, Snafu)] -#[non_exhaustive] -pub enum Error { - #[non_exhaustive] - #[snafu(display(""))] - Dummy {}, -} - -// region: IMPORTS - -use snafu::Snafu; - -// endregion: IMPORTS diff --git a/paxy/src/actions/package/uninstall.rs b/paxy/src/actions/package/uninstall.rs deleted file mode 100644 index 6e9cd4b..0000000 --- a/paxy/src/actions/package/uninstall.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[derive(Debug, Snafu)] -#[non_exhaustive] -pub enum Error { - #[non_exhaustive] - #[snafu(display(""))] - Dummy {}, -} - -// region: IMPORTS - -use snafu::Snafu; - -// endregion: IMPORTS diff --git a/paxy/src/actions/repository/downgrade.rs b/paxy/src/actions/repository/downgrade.rs deleted file mode 100644 index 6e9cd4b..0000000 --- a/paxy/src/actions/repository/downgrade.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[derive(Debug, Snafu)] -#[non_exhaustive] -pub enum Error { - #[non_exhaustive] - #[snafu(display(""))] - Dummy {}, -} - -// region: IMPORTS - -use snafu::Snafu; - -// endregion: IMPORTS diff --git a/paxy/src/actions/repository/search.rs b/paxy/src/actions/repository/search.rs deleted file mode 100644 index 6e9cd4b..0000000 --- a/paxy/src/actions/repository/search.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[derive(Debug, Snafu)] -#[non_exhaustive] -pub enum Error { - #[non_exhaustive] - #[snafu(display(""))] - Dummy {}, -} - -// region: IMPORTS - -use snafu::Snafu; - -// endregion: IMPORTS diff --git a/paxy/src/actions/repository/uninstall.rs b/paxy/src/actions/repository/uninstall.rs deleted file mode 100644 index 6e9cd4b..0000000 --- a/paxy/src/actions/repository/uninstall.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[derive(Debug, Snafu)] -#[non_exhaustive] -pub enum Error { - #[non_exhaustive] - #[snafu(display(""))] - Dummy {}, -} - -// region: IMPORTS - -use snafu::Snafu; - -// endregion: IMPORTS diff --git a/paxy/src/actions/repository/update.rs b/paxy/src/actions/repository/update.rs deleted file mode 100644 index 6e9cd4b..0000000 --- a/paxy/src/actions/repository/update.rs +++ /dev/null @@ -1,13 +0,0 @@ -#[derive(Debug, Snafu)] -#[non_exhaustive] -pub enum Error { - #[non_exhaustive] - #[snafu(display(""))] - Dummy {}, -} - -// region: IMPORTS - -use snafu::Snafu; - -// endregion: IMPORTS diff --git a/paxy/src/app/mod.rs b/paxy/src/app.rs similarity index 93% rename from paxy/src/app/mod.rs rename to paxy/src/app.rs index ab1280b..51b6530 100644 --- a/paxy/src/app/mod.rs +++ b/paxy/src/app.rs @@ -2,13 +2,6 @@ lazy_static! { pub static ref APP_NAME: &'static str = "paxy"; } -// region: IMPORTS - -use lazy_static::lazy_static; -use snafu::Snafu; - -// endregion: IMPORTS - // region: ERRORS #[derive(Debug, Snafu)] @@ -22,7 +15,7 @@ pub enum Error { }, #[non_exhaustive] - #[snafu(display("in configuration: {source}"), visibility(pub))] + #[snafu(display("in the configuration: {source}"), visibility(pub))] Config { #[snafu(backtrace)] source: config::Error, @@ -45,6 +38,13 @@ pub enum Error { // endregion: ERRORS +// region: IMPORTS + +use lazy_static::lazy_static; +use snafu::Snafu; + +// endregion: IMPORTS + // region: EXTERNAL-SUBMODULES pub mod config; diff --git a/paxy/src/app/ui.rs b/paxy/src/app/ui.rs index 10491eb..c428850 100644 --- a/paxy/src/app/ui.rs +++ b/paxy/src/app/ui.rs @@ -346,131 +346,21 @@ pub enum Error { use core::fmt; use std::path::PathBuf; -use owo_colors::OwoColorize; -use serde::{Deserialize, Serialize}; -use snafu::{ResultExt, Snafu}; -use tracing_appender::non_blocking::WorkerGuard; - -use crate::app::{self, config, logging}; - // endregion: IMPORTS // region: MODULES -/// Common commandline interface template for global arguments, intended to be -/// shared between the GUI and CLI programs. -pub mod cli_template { - #[derive(Clone, Debug, Args)] - #[command(next_display_order = usize::MAX - 100)] - pub struct GlobalArgs - where - L: clap_verbosity_flag::LogLevel, - { - #[arg( - long = "config", - short = 'c', - help = "Path to the configuration file to use.", - global = true, - display_order = usize::MAX - 6 - )] - pub config_file: Option, - - #[arg( - long = "json", - help = "Output in the JSON format for machine readability and scripting purposes.", - global = true, - display_order = usize::MAX - 5 - )] - pub json_flag: bool, - - #[arg( - long = "plain", - help = "Output as plain text without extra information, for machine readability and scripting purposes.", - global = true, - display_order = usize::MAX - 4 - )] - pub plain_flag: bool, - - #[arg( - long = "debug", - help = "Output debug messages.", - global = true, - display_order = usize::MAX - 3 - )] - pub debug_flag: bool, - - #[arg( - long = "no-color", - help = "Disable output coloring.", - global = true, - display_order = usize::MAX - 2 - )] - pub no_color_flag: bool, - - #[arg( - long = "test", - help = "Avoid destructive modifications and show all output subject to the commandline filters. Useful for dry-runs and for developers.", - global = true, - display_order = usize::MAX - 1 - )] - pub test_flag: bool, - - #[command(flatten)] - pub verbosity: clap_verbosity_flag::Verbosity, - } - - impl GlobalArguments for GlobalArgs - where - L: clap_verbosity_flag::LogLevel, - { - fn config_filepath(&self) -> &Option { - &self.config_file - } - - fn is_json(&self) -> bool { - self.json_flag - } - - fn is_plain(&self) -> bool { - self.plain_flag - } - - fn is_debug(&self) -> bool { - self.debug_flag - } - - fn is_test(&self) -> bool { - self.test_flag - } - - fn is_no_color(&self) -> bool { - self.no_color_flag - } - - fn verbosity_filter(&self) -> log::LevelFilter { - self.verbosity - .log_level_filter() - } - } - - // region: IMPORTS - - use std::path::PathBuf; - - use clap::Args; - - use super::GlobalArguments; - - // endregion: IMPORTS -} +pub mod console_template; // endregion: MODULES -// region: RE-EXPORTS - #[allow(unused_imports)] pub use cli_template::*; +use owo_colors::OwoColorize; +use serde::{Deserialize, Serialize}; +use snafu::{ResultExt, Snafu}; +use tracing_appender::non_blocking::WorkerGuard; -use super::config::ConfigTemplate; // Flatten the module heirarchy for easier access +use super::config::ConfigTemplate; +use crate::app::{self, config, logging}; // Flatten the module heirarchy for easier access -// endregion: RE-EXPORTS diff --git a/paxy/src/app/ui/console_template.rs b/paxy/src/app/ui/console_template.rs new file mode 100644 index 0000000..6c377c9 --- /dev/null +++ b/paxy/src/app/ui/console_template.rs @@ -0,0 +1,125 @@ +//! Common commandline interface template for global arguments, intended to be +//! shared between the GUI and CLI programs. +#[derive(Clone, Debug, Args)] +#[command(next_display_order = usize::MAX - 100)] +pub struct GlobalArgs +where + L: clap_verbosity_flag::LogLevel, +{ + #[arg( + long = "config", + short = 'c', + help = "Path to the configuration file to use.", + global = true, + display_order = usize::MAX - 6 + )] + pub config_file: Option, + + #[arg( + long = "json", + help = "Output in the JSON format for machine readability and scripting purposes.", + global = true, + display_order = usize::MAX - 5 + )] + pub json_flag: bool, + + #[arg( + long = "plain", + help = "Output as plain text without extra information, for machine readability and scripting purposes.", + global = true, + display_order = usize::MAX - 4 + )] + pub plain_flag: bool, + + #[arg( + long = "debug", + help = "Output debug messages.", + global = true, + display_order = usize::MAX - 3 + )] + pub debug_flag: bool, + + #[arg( + long = "no-color", + help = "Disable output coloring.", + global = true, + display_order = usize::MAX - 2 + )] + pub no_color_flag: bool, + + #[arg( + long = "test", + help = "Avoid destructive modifications and show all output subject to the commandline filters. Useful for dry-runs and for developers.", + global = true, + display_order = usize::MAX - 1 + )] + pub test_flag: bool, + + #[command(flatten)] + pub verbosity: clap_verbosity_flag::Verbosity, +} + +impl GlobalArguments for GlobalArgs +where + L: clap_verbosity_flag::LogLevel, +{ + fn config_filepath(&self) -> &Option { + &self.config_file + } + + fn is_json(&self) -> bool { + self.json_flag + } + + fn is_plain(&self) -> bool { + self.plain_flag + } + + fn is_debug(&self) -> bool { + self.debug_flag + } + + fn is_test(&self) -> bool { + self.test_flag + } + + fn is_no_color(&self) -> bool { + self.no_color_flag + } + + fn verbosity_filter(&self) -> log::LevelFilter { + self.verbosity + .log_level_filter() + } +} + +#[derive(Debug, Snafu)] +#[non_exhaustive] +pub enum Error { + #[non_exhaustive] + #[snafu(display(""), visibility(pub))] + GuiDummy {}, // No errors implemented yet +} + +// region: IMPORTS + +// endregion: IMPORTS + +// region: MODULES + +pub mod cli; +pub mod gui; + +// endregion: MODULES + +// region: IMPORTS +use std::path::PathBuf; + +use clap::Args; +use owo_colors::OwoColorize; +use paxy::app::ui; +use snafu::Snafu; + +use super::GlobalArguments; + +// endregion: IMPORTS diff --git a/paxy/src/app/ui/console_template/cli.rs b/paxy/src/app/ui/console_template/cli.rs new file mode 100644 index 0000000..182067c --- /dev/null +++ b/paxy/src/app/ui/console_template/cli.rs @@ -0,0 +1,370 @@ +//! This module is a [*derive* interface template](https://docs.rs/clap/latest/clap/_derive/_tutorial/chapter_0/index.html) specifically for +//! use with the `clap` library. Any other commandline-related code that is +//! not part of the `clap` derive template will not be in this module. +//! The CLI is designed to (as much as possible,) follow the guidelines in +//! https://clig.dev/ . As a consequence, the command structure follows the +//! 'application_name noun verb' order of subcommands. For example: +//! `paxy package list [args]`, `paxy repo add [args]` + +/// The base commandline template consists of global arguments, a +/// subcommand that denotes the entity that is being operated +/// upon (like a package or repository), and optionally, +/// arguments for the default subcommand (in this case, the +/// 'package' entity is assumed chosen to act on, by default). +#[derive(Debug, Parser)] +#[command( + version, + author, + about, + args_conflicts_with_subcommands = true, + propagate_version = true +)] +pub struct CliTemplate { + #[command(flatten)] + pub global_args: ui::cli_template::GlobalArgs, + + #[command(subcommand)] + pub entity: Option, +} + +/// Implement a trait that can extract standard global arguments from +/// our own CLI template +impl ui::GlobalArguments for CliTemplate { + fn config_filepath(&self) -> &Option { + self.global_args + .config_filepath() + } + + fn is_json(&self) -> bool { + self.global_args + .is_json() + } + + fn is_plain(&self) -> bool { + self.global_args + .is_plain() + } + + fn is_debug(&self) -> bool { + self.global_args + .is_debug() + } + + fn is_test(&self) -> bool { + self.global_args + .is_test() + } + + fn is_no_color(&self) -> bool { + self.global_args + .is_no_color() + } + + fn verbosity_filter(&self) -> log::LevelFilter { + self.global_args + .verbosity_filter() + } +} + +#[derive(Debug, Subcommand)] +#[command(args_conflicts_with_subcommands = true)] +pub enum EntitySubcommand { + #[command( + name = "package", + about = "Perform actions on package(s).", + subcommand, + display_order = 1 + )] + Package(PackageSubcommand), + + #[command( + subcommand, + name = "repository", + alias = "repo", + about = "Perform actions on repository(-ies).", + display_order = 2 + )] + Repository(RepositorySubcommand), +} + +#[derive(Debug, Subcommand)] +#[command(args_conflicts_with_subcommands = true)] +pub enum PackageSubcommand { + #[command(name = "list", about = "List installed packages.", display_order = 1)] + List(PackageListArguments), + + #[command( + name = "search", + alias = "find", + about = "Search for available packages.", + display_order = 2 + )] + Search(PackageSearchArguments), + + #[command( + name = "install", + alias = "add", + about = "Install packages.", + display_order = 3 + )] + Install(PackageInstallArguments), + + #[command( + name = "update", + alias = "upgrade", + about = "Update packages.", + display_order = 4 + )] + Update(PackageUpdateArguments), + + #[command( + name = "uninstall", + alias = "remove", + about = "Uninstall packages.", + display_order = 5 + )] + Uninstall(PackageUninstallArguments), + + #[command(name = "downgrade", about = "Downgrade a package.", display_order = 5)] + Downgrade(PackageDowngradeArguments), +} + +#[derive(Debug, Subcommand)] +#[command(args_conflicts_with_subcommands = true)] +pub enum RepositorySubcommand { + #[command( + name = "list", + about = "List installed repositories.", + display_order = 1 + )] + List(RepositoryListArguments), + + #[command( + name = "search", + alias = "find", + about = "Search for available repositories.", + display_order = 2 + )] + Search(RepositorySearchArguments), + + #[command( + name = "install", + alias = "add", + about = "Install repositories.", + display_order = 3 + )] + Install(RepositoryInstallArguments), + + #[command( + name = "update", + alias = "upgrade", + about = "Update repositories.", + display_order = 4 + )] + Update(RepositoryUpdateArguments), + + #[command( + name = "uninstall", + alias = "remove", + about = "Uninstall repositories.", + display_order = 5 + )] + Uninstall(RepositoryUninstallArguments), + + #[command( + name = "downgrade", + about = "Downgrade a repositories.", + display_order = 5 + )] + Downgrade(RepositoryDowngradeArguments), +} + +#[derive(Debug, Args)] +pub struct PackageListArguments { + #[arg( + long = "exclude", + alias = "ignore", + short = 'e', + help = "Partial or full name(s) of packages to exclude from the search among the installed packages.", + display_order = 1 + )] + pub excluded_partial_package_names: Vec, + + #[arg( + help = "Partial or full name(s) of the packages to search among the installed packages. Not specifying this argument will list all packages.", + display_order = usize::MAX - 1, + )] + pub partial_package_name: Vec, +} + +#[derive(Debug, Args)] +pub struct PackageSearchArguments { + #[arg( + long = "exclude", + alias = "ignore", + short = 'e', + help = "Partial or full name(s) of packages to exclude from the search among available packages.", + display_order = 1 + )] + pub excluded_partial_package_names: Vec, + + #[arg( + help = "Partial or full name(s) of the packages to search among available packages.", + last = true, + display_order = usize::MAX - 1 + )] + pub partial_package_name: Vec, +} + +#[derive(Debug, Args)] +pub struct PackageInstallArguments { + #[arg(help = "Full name(s) of the packages to install.", display_order = usize::MAX - 1)] + pub package_names: Vec, +} + +#[derive(Debug, Args)] +pub struct PackageUpdateArguments { + #[arg( + long = "exclude", + alias = "ignore", + short = 'e', + help = "Full name(s) of packages to exclude from updating.", + display_order = 1 + )] + pub excluded_package_names: Vec, + + #[arg( + help = "Full name(s) of the packages to update. Not specifying this argument will update all packages", + last = true, + display_order = usize::MAX - 1 + )] + pub package_names: Vec, +} + +#[derive(Debug, Args)] +pub struct PackageUninstallArguments { + #[arg( + help = "Full name(s) of the packages to uninstall.", + last = true, + display_order = usize::MAX - 1 + )] + pub package_names: Vec, +} + +#[derive(Debug, Args)] +pub struct PackageDowngradeArguments { + #[arg( + long = "version", + alias = "ver", + help = "The version to downgrade to.", + display_order = 1 + )] + pub version: Option, + + #[arg( + help = "Full name of the package to downgrade.", + last = true, + display_order = usize::MAX - 1 + )] + pub package_name: String, +} + +#[derive(Debug, Args)] +pub struct RepositoryListArguments { + #[arg( + long = "exclude", + alias = "ignore", + short = 'e', + help = "Partial or full name(s) of repositories to exclude from the search among the installed repositories.", + display_order = 1 + )] + pub excluded_partial_repository_names: Vec, + + #[arg( + help = "Partial or full name(s) of the repositories to search among the installed repositories. Not specifying this argument will list all repositories.", + last = true, + display_order = usize::MAX - 1, + )] + pub partial_repository_name: Vec, +} + +#[derive(Debug, Args)] +pub struct RepositorySearchArguments { + #[arg( + long = "exclude", + alias = "ignore", + short = 'e', + help = "Partial or full name(s) of repositories to exclude from the search among available repositories.", + display_order = 1 + )] + pub excluded_partial_repository_names: Vec, + + #[arg( + help = "Partial or full name(s) of the repositories to search among available repositories.", + last = true, + display_order = usize::MAX - 1 + )] + pub partial_repository_name: String, +} + +#[derive(Debug, Args)] +pub struct RepositoryInstallArguments { + #[arg(help = "Full name(s) of the repositories to install.", display_order = usize::MAX - 1)] + pub repository_names: Vec, +} + +#[derive(Debug, Args)] +pub struct RepositoryUpdateArguments { + #[arg( + long = "exclude", + alias = "ignore", + short = 'e', + help = "Full name(s) of repositories to exclude from updating.", + display_order = 1 + )] + pub excluded_repository_names: Vec, + + #[arg( + help = "Full name(s) of the repositories to update. Not specifying this argument will update all repositories", + last = true, + display_order = usize::MAX - 1 + )] + pub repository_names: Vec, +} + +#[derive(Debug, Args)] +pub struct RepositoryUninstallArguments { + #[arg( + help = "Full name(s) of the repositories to uninstall.", + last = true, + display_order = usize::MAX - 1 + )] + pub repository_names: Vec, +} + +#[derive(Debug, Args)] +pub struct RepositoryDowngradeArguments { + #[arg( + long = "version", + alias = "ver", + help = "The version to downgrade to.", + display_order = 1 + )] + pub version: Option, + + #[arg( + help = "Full name of the repository to downgrade.", + last = true, + display_order = usize::MAX - 1 + )] + pub repository_name: String, +} + +// region: IMPORTS + +use std::path::PathBuf; + +use clap::{Args, Parser, Subcommand}; +use paxy::app::ui::{self, cli_template::*}; + +// endregion: IMPORTS diff --git a/paxy/src/app/ui/console_template/gui.rs b/paxy/src/app/ui/console_template/gui.rs new file mode 100644 index 0000000..4f118bc --- /dev/null +++ b/paxy/src/app/ui/console_template/gui.rs @@ -0,0 +1,58 @@ +//! The commandline interface for the GUI program. Allows one to specify +//! flags that control output on a console. + +/// The base commandline template consists of global arguments +#[derive(Parser, Debug)] +#[command(version, author, about, args_conflicts_with_subcommands = true)] +pub struct CliTemplate { + #[clap(flatten)] + pub global_args: ui::cli_template::GlobalArgs, +} + +/// Implement a trait that can extract standard global arguments from +/// our own CLI template +impl ui::GlobalArguments for CliTemplate { + fn config_filepath(&self) -> &Option { + self.global_args + .config_filepath() + } + + fn is_json(&self) -> bool { + self.global_args + .is_json() + } + + fn is_plain(&self) -> bool { + self.global_args + .is_plain() + } + + fn is_debug(&self) -> bool { + self.global_args + .is_debug() + } + + fn is_test(&self) -> bool { + self.global_args + .is_test() + } + + fn is_no_color(&self) -> bool { + self.global_args + .is_no_color() + } + + fn verbosity_filter(&self) -> log::LevelFilter { + self.global_args + .verbosity_filter() + } +} + +// region: IMPORTS + +use std::path::PathBuf; + +use clap::Parser; +use paxy::app::ui; + +// endregion: IMPORTS diff --git a/paxy/src/data/mod.rs b/paxy/src/data.rs similarity index 80% rename from paxy/src/data/mod.rs rename to paxy/src/data.rs index 68a6538..f769933 100644 --- a/paxy/src/data/mod.rs +++ b/paxy/src/data.rs @@ -1,3 +1,7 @@ +// TODO: Write code here + +// region: ERRORS + #[derive(Debug, Snafu)] #[non_exhaustive] pub enum Error { @@ -12,27 +16,23 @@ pub enum Error { }, } +// region: ERRORS + // region: IMPORTS // use std::{fmt, str::FromStr}; // use serde::{Deserialize, Serialize}; // use serde_aux::prelude::*; -use snafu::Snafu; // use speedy::{Readable, Writable}; +use snafu::Snafu; // endregion: IMPORTS -// region: MODULES +// region: EXTERNAL-SUBMODULES // pub mod some_module; +mod config; -// endregion: MODULES - -// region: RE-EXPORTS - -// #[allow(unused_imports)] -// pub use some_module::*; +// endregion: EXTERNAL-SUBMODULES -// endregion: RE-EXPORTS -mod config; diff --git a/paxy/src/lib.rs b/paxy/src/lib.rs index 0790bf0..6401181 100644 --- a/paxy/src/lib.rs +++ b/paxy/src/lib.rs @@ -1,22 +1,17 @@ +// Returns a string representation of the type of the given object, which can +// be displayed or further processed. pub fn type_of(_: &T) -> &str { any::type_name::() } -// region: IMPORTS - -use std::any; - -use snafu::Snafu; - -// endregion: IMPORTS - // region: ERRORS #[derive(Debug, Snafu)] +#[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] - #[snafu(display("in the application: {source}"), visibility(pub))] + #[snafu(display("in the app: {source}"), visibility(pub))] App { #[snafu(backtrace)] source: app::Error, @@ -24,17 +19,25 @@ pub enum Error { #[non_exhaustive] #[snafu(display("in an action:{source}"), visibility(pub))] - Actions { + Action { #[snafu(backtrace)] - source: actions::Error, + source: action::Error, }, } // endregion: ERRORS +// region: IMPORTS + +use std::any; + +use snafu::Snafu; + +// endregion: IMPORTS + // region: EXTERNAL-SUBMODULES -pub mod actions; +pub mod action; pub mod app; pub mod data;