From 975559e7202821ff7357e94c132f4315a5ddf8a2 Mon Sep 17 00:00:00 2001 From: pvshvp-oss Date: Sun, 12 May 2024 13:21:21 -0500 Subject: [PATCH 1/3] 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; From da5c61d874d19a3709712d275fdb6c5081a104a6 Mon Sep 17 00:00:00 2001 From: pvshvp-oss Date: Mon, 13 May 2024 16:47:32 -0500 Subject: [PATCH 2/3] feat: Connect CLI to actions and reorg --- paxy-cli/src/lib.rs | 104 +++--------------------- paxy-cli/src/main.rs | 4 +- paxy-gui/src/lib.rs | 20 ++++- paxy-gui/src/main.rs | 4 +- paxy/src/action.rs | 32 +++++++- paxy/src/action/package.rs | 71 ++++++++++------ paxy/src/action/package/downgrade.rs | 20 +++-- paxy/src/action/package/install.rs | 29 +++++-- paxy/src/action/package/list.rs | 20 +++-- paxy/src/action/package/search.rs | 20 +++-- paxy/src/action/package/uninstall.rs | 20 +++-- paxy/src/action/package/update.rs | 20 +++-- paxy/src/action/repository.rs | 72 +++++++++++----- paxy/src/action/repository/downgrade.rs | 20 +++-- paxy/src/action/repository/install.rs | 28 +++++-- paxy/src/action/repository/list.rs | 20 +++-- paxy/src/action/repository/search.rs | 20 +++-- paxy/src/action/repository/uninstall.rs | 20 +++-- paxy/src/action/repository/update.rs | 20 +++-- paxy/src/app.rs | 48 +++++++++-- paxy/src/app/config.rs | 5 ++ paxy/src/app/i18n.rs | 14 ++-- paxy/src/app/logging.rs | 7 ++ paxy/src/app/ui.rs | 73 ++++++----------- paxy/src/app/ui/console_template.rs | 20 ++--- paxy/src/app/ui/console_template/cli.rs | 5 +- paxy/src/app/ui/console_template/gui.rs | 5 +- paxy/src/data/config.rs | 2 +- paxy/src/{data.rs => data/mod.rs} | 1 - paxy/src/lib.rs | 8 ++ 30 files changed, 453 insertions(+), 299 deletions(-) rename paxy/src/{data.rs => data/mod.rs} (99%) diff --git a/paxy-cli/src/lib.rs b/paxy-cli/src/lib.rs index c11e701..42464c1 100644 --- a/paxy-cli/src/lib.rs +++ b/paxy-cli/src/lib.rs @@ -5,113 +5,31 @@ /// 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::()?; + // Initialize the app to setup basic functions like config and logging + let (console_input, _logging_worker_guards) = + app::run_common::().context(AppSnafu {})?; + // Notify that the app is running in CLI mode tracing::debug!( "Running in {} mode... {}", "CLI".blue(), 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)?; - } - }, - } - } + // Delegate handling actions + action::handle_action(console_input).context(ActionSnafu {})?; Ok(()) } - -#[derive(Debug, Snafu)] -#[non_exhaustive] -pub enum Error { - #[non_exhaustive] - #[snafu(display(""), visibility(pub))] - CliDummy {}, -} - // region: IMPORTS use owo_colors::OwoColorize; use paxy::{ - action::{package, repository}, - app::ui, + action, + app::{self, ui::console_template::cli::CliTemplate}, + ActionSnafu, + AppSnafu, }; -use snafu::{ResultExt, Snafu}; +use snafu::ResultExt; // endregion: IMPORTS diff --git a/paxy-cli/src/main.rs b/paxy-cli/src/main.rs index f4b8c66..73509b7 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 [`crate::run_cli`] function and captures the returned +/// Calls the [`paxy_cli::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 = crate::run_cli(); + let return_value = paxy_cli::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 eb00aae..71cade9 100644 --- a/paxy-gui/src/lib.rs +++ b/paxy-gui/src/lib.rs @@ -5,13 +5,29 @@ /// 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) = paxy::ui::run_common::()?; + // Initialize the app to setup basic functions like config and logging + let (_cli_input, _logging_worker_guards) = + app::run_common::().context(AppSnafu {})?; + // Notify that the app is running in GUI mode tracing::debug!( "Running in {} mode... {}", "GUI".blue(), console::Emoji("📊", "") ); - Ok(()) + todo!("GUI is not yet implemented"); + + // Ok(()) } + +// region: IMPORTS + +use owo_colors::OwoColorize; +use paxy::{ + app::{self, ui::console_template::gui::CliTemplate}, + AppSnafu, +}; +use snafu::ResultExt; + +// endregion: IMPORTS diff --git a/paxy-gui/src/main.rs b/paxy-gui/src/main.rs index ab0a734..f96597b 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 [`crate::run_gui`] function and captures the returned +/// Calls the [`paxy_gui::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 = crate::run_gui(); + let return_value = paxy_gui::run_gui(); match return_value { Ok(_) => process::ExitCode::from(0), Err(err_value) => { diff --git a/paxy/src/action.rs b/paxy/src/action.rs index 3336f0c..6d42b20 100644 --- a/paxy/src/action.rs +++ b/paxy/src/action.rs @@ -1,3 +1,26 @@ +//! Handles various package or repository actions that form the core +//! functionality of paxy, not the application related functionality - UI, +//! logging, config, OS, etc. + +/// Receives console input and delegates actions +pub fn handle_action(console_input: CliTemplate) -> Result<(), Error> { + use crate::app::ui::console_template::cli::*; + + if let Some(entity) = console_input.entity { + match entity { + EntitySubcommand::Package(package_subcommand) => { + package::handle_package_action(package_subcommand).context(PackageSnafu)?; + } + EntitySubcommand::Repository(repository_subcommand) => { + repository::handle_repository_action(repository_subcommand) + .context(RepositorySnafu)?; + } + } + } + + Ok(()) +} + // region: ERRORS #[derive(Debug, Snafu)] @@ -6,18 +29,20 @@ pub enum Error { #[non_exhaustive] #[snafu(display("Could not complete package action:\n {source}"))] - PackageError { source: package::Error }, + Package { source: package::Error }, #[non_exhaustive] #[snafu(display("Could not complete repository action:\n {source}"))] - RepositoryError { source: repository::Error }, + Repository { source: repository::Error }, } // endregion: ERRORS // region: IMPORTS -use snafu::Snafu; +use snafu::{ResultExt, Snafu}; + +use crate::app::ui::console_template::cli::CliTemplate; // endregion: IMPORTS @@ -27,4 +52,3 @@ pub mod package; pub mod repository; // region: EXTERNAL-SUBMODULES - diff --git a/paxy/src/action/package.rs b/paxy/src/action/package.rs index a283272..2b6a47a 100644 --- a/paxy/src/action/package.rs +++ b/paxy/src/action/package.rs @@ -1,35 +1,75 @@ +//! Handles package related actions. + +pub fn handle_package_action(package_subcommand: PackageSubcommand) -> Result<(), Error> { + use crate::app::ui::console_template::cli::*; + + match package_subcommand { + PackageSubcommand::List(package_list_arguments) => { + list::handle_package_list_action(package_list_arguments).context(PackageListSnafu {})? + } + PackageSubcommand::Search(package_search_arguments) => { + search::handle_package_search_action(package_search_arguments) + .context(PackageSearchSnafu {})? + } + PackageSubcommand::Install(package_install_arguments) => { + install::handle_package_install_action(package_install_arguments) + .context(PackageInstallSnafu {})? + } + PackageSubcommand::Update(package_update_arguments) => { + update::handle_package_update_action(package_update_arguments) + .context(PackageUpdateSnafu {})? + } + PackageSubcommand::Uninstall(package_uninstall_arguments) => { + uninstall::handle_package_uninstall_action(package_uninstall_arguments) + .context(PackageUninstallSnafu {})? + } + PackageSubcommand::Downgrade(package_downgrade_arguments) => { + downgrade::handle_package_downgrade_action(package_downgrade_arguments) + .context(PackageDowngradeSnafu {})? + } + } + + Ok(()) +} + +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] #[snafu(display("Could not list:\n {source}"))] - CouldNotList { source: list::Error }, + PackageList { source: list::Error }, #[non_exhaustive] #[snafu(display("Could not search:\n {source}"))] - CouldNotSearch { source: search::Error }, + PackageSearch { source: search::Error }, #[non_exhaustive] #[snafu(display("Could not install:\n {source}"))] - CouldNotInstall { source: install::Error }, + PackageInstall { source: install::Error }, #[non_exhaustive] #[snafu(display("Could not update:\n {source}"))] - CouldNotUpdate { source: update::Error }, + PackageUpdate { source: update::Error }, #[non_exhaustive] #[snafu(display("Could not uninstall:\n {source}"))] - CouldNotUninstall { source: uninstall::Error }, + PackageUninstall { source: uninstall::Error }, #[non_exhaustive] #[snafu(display("Could not downgrade:\n {source}"))] - CouldNotDowngrade { source: downgrade::Error }, + PackageDowngrade { source: downgrade::Error }, } +// endregion: ERRORS + // region: IMPORTS -use snafu::Snafu; +use snafu::{ResultExt, Snafu}; + +use crate::app::ui::console_template::cli::PackageSubcommand; // endregion: IMPORTS @@ -43,20 +83,3 @@ pub mod uninstall; pub mod update; // endregion: MODULES - -// region: RE-EXPORTS - -#[allow(unused_imports)] -pub use downgrade::*; -#[allow(unused_imports)] -pub use install::*; -#[allow(unused_imports)] -pub use list::*; -#[allow(unused_imports)] -pub use search::*; -#[allow(unused_imports)] -pub use uninstall::*; -#[allow(unused_imports)] -pub use update::*; - -// endregion: RE-EXPORTS diff --git a/paxy/src/action/package/downgrade.rs b/paxy/src/action/package/downgrade.rs index b8bb501..0af5b38 100644 --- a/paxy/src/action/package/downgrade.rs +++ b/paxy/src/action/package/downgrade.rs @@ -1,9 +1,16 @@ -pub fn run_downgrade( - package_downgrade_arguments: ui::cli_template::PackageDowngradeArguments, +#[allow(unused)] +pub fn handle_package_downgrade_action( + package_downgrade_arguments: PackageDowngradeArguments, ) -> Result<(), Error> { - todo!() + use crate::app::ui::console_template::cli::*; + + todo!(); + + // Ok(()) } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -13,10 +20,13 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::app::ui; +use crate::app::ui::console_template::cli::PackageDowngradeArguments; // endregion: IMPORTS diff --git a/paxy/src/action/package/install.rs b/paxy/src/action/package/install.rs index e0ca03c..94dca98 100644 --- a/paxy/src/action/package/install.rs +++ b/paxy/src/action/package/install.rs @@ -1,9 +1,22 @@ -pub fn run_install( - package_install_arguments: ui::cli_template::PackageInstallArguments, +#[allow(unused)] +pub fn handle_package_install_action( + package_install_arguments: PackageInstallArguments, ) -> Result<(), Error> { + use crate::app::ui::console_template::cli::*; + + todo!(); + + // Ok(()) +} + +#[allow(dead_code)] +#[allow(unused_variables)] +fn plugin(manifest: PathBuf) -> PathBuf { todo!() } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -13,17 +26,15 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS use std::path::PathBuf; -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::app::ui; +use crate::app::ui::console_template::cli::PackageInstallArguments; // endregion: IMPORTS -#[allow(dead_code)] -#[allow(unused_variables)] -fn plugin(manifest: PathBuf) -> PathBuf { - todo!() -} diff --git a/paxy/src/action/package/list.rs b/paxy/src/action/package/list.rs index f3b5c0c..cb72b63 100644 --- a/paxy/src/action/package/list.rs +++ b/paxy/src/action/package/list.rs @@ -1,9 +1,16 @@ -pub fn run_list( - package_list_arguments: ui::cli_template::PackageListArguments, +#[allow(unused)] +pub fn handle_package_list_action( + package_list_arguments: PackageListArguments, ) -> Result<(), Error> { - todo!() + use crate::app::ui::console_template::cli::*; + + todo!(); + + // Ok(()) } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -13,10 +20,13 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::app::ui; +use crate::app::ui::console_template::cli::PackageListArguments; // endregion: IMPORTS diff --git a/paxy/src/action/package/search.rs b/paxy/src/action/package/search.rs index 3636629..7602b74 100644 --- a/paxy/src/action/package/search.rs +++ b/paxy/src/action/package/search.rs @@ -1,9 +1,16 @@ -pub fn run_search( - package_search_arguments: ui::cli_template::PackageSearchArguments, +#[allow(unused)] +pub fn handle_package_search_action( + package_search_arguments: PackageSearchArguments, ) -> Result<(), Error> { - todo!() + use crate::app::ui::console_template::cli::*; + + todo!(); + + // Ok(()) } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -13,10 +20,13 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::app::ui; +use crate::app::ui::console_template::cli::PackageSearchArguments; // endregion: IMPORTS diff --git a/paxy/src/action/package/uninstall.rs b/paxy/src/action/package/uninstall.rs index 4da4f47..e4ba100 100644 --- a/paxy/src/action/package/uninstall.rs +++ b/paxy/src/action/package/uninstall.rs @@ -1,9 +1,16 @@ -pub fn run_uninstall( - package_uninstall_arguments: ui::cli_template::PackageUninstallArguments, +#[allow(unused)] +pub fn handle_package_uninstall_action( + package_uninstall_arguments: PackageUninstallArguments, ) -> Result<(), Error> { - todo!() + use crate::app::ui::console_template::cli::*; + + todo!(); + + // Ok(()) } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -13,10 +20,13 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::app::ui; +use crate::app::ui::console_template::cli::PackageUninstallArguments; // endregion: IMPORTS diff --git a/paxy/src/action/package/update.rs b/paxy/src/action/package/update.rs index 80d1244..f52e1ca 100644 --- a/paxy/src/action/package/update.rs +++ b/paxy/src/action/package/update.rs @@ -1,9 +1,16 @@ -pub fn run_update( - package_update_arguments: ui::cli_template::PackageUpdateArguments, +#[allow(unused)] +pub fn handle_package_update_action( + package_update_arguments: PackageUpdateArguments, ) -> Result<(), Error> { - todo!() + use crate::app::ui::console_template::cli::*; + + todo!(); + + // Ok(()) } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -13,10 +20,13 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::app::ui; +use crate::app::ui::console_template::cli::PackageUpdateArguments; // endregion: IMPORTS diff --git a/paxy/src/action/repository.rs b/paxy/src/action/repository.rs index ad618d4..c3d5c3f 100644 --- a/paxy/src/action/repository.rs +++ b/paxy/src/action/repository.rs @@ -1,4 +1,38 @@ -#[macro_export] +//! Handles repository-related actions. + +pub fn handle_repository_action(repository_subcommand: RepositorySubcommand) -> Result<(), Error> { + use crate::app::ui::console_template::cli::*; + + match repository_subcommand { + RepositorySubcommand::List(repository_list_arguments) => { + list::handle_repository_list_action(repository_list_arguments) + .context(RepositoryListSnafu {})? + } + RepositorySubcommand::Search(repository_search_arguments) => { + search::handle_repository_search_action(repository_search_arguments) + .context(RepositorySearchSnafu {})? + } + RepositorySubcommand::Install(repository_install_arguments) => { + install::handle_repository_install_action(repository_install_arguments) + .context(RepositoryInstallSnafu {})? + } + RepositorySubcommand::Update(repository_update_arguments) => { + update::handle_repository_update_action(repository_update_arguments) + .context(RepositoryUpdateSnafu {})? + } + RepositorySubcommand::Uninstall(repository_uninstall_arguments) => { + uninstall::handle_repository_uninstall_action(repository_uninstall_arguments) + .context(RepositoryUninstallSnafu {})? + } + RepositorySubcommand::Downgrade(repository_downgrade_arguments) => { + downgrade::handle_repository_downgrade_action(repository_downgrade_arguments) + .context(RepositoryDowngradeSnafu {})? + } + } + + Ok(()) +} + macro_rules! home { () => { match home::home_dir() { @@ -23,44 +57,50 @@ pub fn ensure_path(path: Option<&PathBuf>) { } } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { #[non_exhaustive] #[snafu(display("Could not list:\n {source}"))] - CouldNotList { source: list::Error }, + RepositoryList { source: list::Error }, #[non_exhaustive] #[snafu(display("Could not search:\n {source}"))] - CouldNotSearch { source: search::Error }, + RepositorySearch { source: search::Error }, #[non_exhaustive] #[snafu(display("Could not install:\n {source}"))] - CouldNotInstall { source: install::Error }, + RepositoryInstall { source: install::Error }, #[non_exhaustive] #[snafu(display("Could not update:\n {source}"))] - CouldNotUpdate { source: update::Error }, + RepositoryUpdate { source: update::Error }, #[non_exhaustive] #[snafu(display("Could not uninstall:\n {source}"))] - CouldNotUninstall { source: uninstall::Error }, + RepositoryUninstall { source: uninstall::Error }, #[non_exhaustive] #[snafu(display("Could not downgrade:\n {source}"))] - CouldNotDowngrade { source: downgrade::Error }, + RepositoryDowngrade { source: downgrade::Error }, } +// endregion: ERRORS + // region: IMPORTS use std::path::PathBuf; -use snafu::Snafu; +use snafu::{ResultExt, Snafu}; + +use crate::app::ui::console_template::cli::RepositorySubcommand; // endregion: IMPORTS -// region: MODULES +// region: EXTERNAL-SUBMODULES pub mod downgrade; pub mod install; @@ -69,22 +109,10 @@ pub mod search; pub mod uninstall; pub mod update; -// endregion: MODULES +// endregion: EXTERNAL-SUBMODULES // region: RE-EXPORTS -#[allow(unused_imports)] -pub use downgrade::*; pub(crate) use home; -#[allow(unused_imports)] -pub use install::*; -#[allow(unused_imports)] -pub use list::*; -#[allow(unused_imports)] -pub use search::*; -#[allow(unused_imports)] -pub use uninstall::*; -#[allow(unused_imports)] -pub use update::*; // endregion: RE-EXPORTS diff --git a/paxy/src/action/repository/downgrade.rs b/paxy/src/action/repository/downgrade.rs index 75aaab3..aa004a9 100644 --- a/paxy/src/action/repository/downgrade.rs +++ b/paxy/src/action/repository/downgrade.rs @@ -1,9 +1,16 @@ -pub fn run_downgrade( - repository_downgrade_arguments: ui::cli_template::RepositoryDowngradeArguments, +#[allow(unused)] +pub fn handle_repository_downgrade_action( + repository_downgrade_arguments: RepositoryDowngradeArguments, ) -> Result<(), Error> { - todo!() + use crate::app::ui::console_template::cli::*; + + todo!(); + + // Ok(()) } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -13,10 +20,13 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::app::ui; +use crate::app::ui::console_template::cli::RepositoryDowngradeArguments; // endregion: IMPORTS diff --git a/paxy/src/action/repository/install.rs b/paxy/src/action/repository/install.rs index a06eaba..ccc9d09 100644 --- a/paxy/src/action/repository/install.rs +++ b/paxy/src/action/repository/install.rs @@ -1,14 +1,19 @@ -pub fn run_install( - repository_install_arguments: ui::cli_template::RepositoryInstallArguments, +#[allow(unused)] +pub fn handle_repository_install_action( + repository_install_arguments: RepositoryInstallArguments, ) -> Result<(), Error> { - todo!() + use crate::app::ui::console_template::cli::*; + + todo!(); + + Ok(()) } #[allow(unused)] fn add_repo(repo: &str, name: &str) { - let mut file = super::home!(); + let mut file = repository::home!(); file.push(".paxy"); - ensure_path(None); + repository::ensure_path(None); file.push("repos.bson"); let mut doc = if !file.is_file() { warn!("file not found. Creating"); @@ -30,7 +35,7 @@ fn add_repo(repo: &str, name: &str) { file.pop(); file.push("repos"); file.push(name); - ensure_path(Some(&file)); + repository::ensure_path(Some(&file)); Repository::clone(repo, file).unwrap(); } @@ -40,6 +45,8 @@ fn plugin(manifest: PathBuf) -> PathBuf { todo!() } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -49,6 +56,8 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS use std::{ @@ -59,10 +68,11 @@ use std::{ use bson::{doc, Document}; use git2::Repository; use log::{info, warn}; -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::action::repository::ensure_path; -use crate::app::ui; +use crate::action::repository; +use crate::app::ui::console_template::cli::RepositoryInstallArguments; // endregion: IMPORTS diff --git a/paxy/src/action/repository/list.rs b/paxy/src/action/repository/list.rs index 2fdf8ed..526b8df 100644 --- a/paxy/src/action/repository/list.rs +++ b/paxy/src/action/repository/list.rs @@ -1,9 +1,16 @@ -pub fn run_list( - repository_list_arguments: ui::cli_template::RepositoryListArguments, +#[allow(unused)] +pub fn handle_repository_list_action( + repository_list_arguments: RepositoryListArguments, ) -> Result<(), Error> { - todo!() + use crate::app::ui::console_template::cli::*; + + todo!(); + + // Ok(()) } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -13,10 +20,13 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::app::ui; +use crate::app::ui::console_template::cli::RepositoryListArguments; // endregion: IMPORTS diff --git a/paxy/src/action/repository/search.rs b/paxy/src/action/repository/search.rs index 6d05a00..a548fca 100644 --- a/paxy/src/action/repository/search.rs +++ b/paxy/src/action/repository/search.rs @@ -1,9 +1,16 @@ -pub fn run_search( - repository_search_arguments: ui::cli_template::RepositorySearchArguments, +#[allow(unused)] +pub fn handle_repository_search_action( + repository_search_arguments: RepositorySearchArguments, ) -> Result<(), Error> { - todo!() + use crate::app::ui::console_template::cli::*; + + todo!(); + + // Ok(()) } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -13,10 +20,13 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::app::ui; +use crate::app::ui::console_template::cli::RepositorySearchArguments; // endregion: IMPORTS diff --git a/paxy/src/action/repository/uninstall.rs b/paxy/src/action/repository/uninstall.rs index 6fa0065..37eec1e 100644 --- a/paxy/src/action/repository/uninstall.rs +++ b/paxy/src/action/repository/uninstall.rs @@ -1,9 +1,16 @@ -pub fn run_uninstall( - repository_uninstall_arguments: ui::cli_template::RepositoryUninstallArguments, +#[allow(unused)] +pub fn handle_repository_uninstall_action( + repository_uninstall_arguments: RepositoryUninstallArguments, ) -> Result<(), Error> { - todo!() + use crate::app::ui::console_template::cli::*; + + todo!(); + + // Ok(()) } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -13,10 +20,13 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::app::ui; +use crate::app::ui::console_template::cli::RepositoryUninstallArguments; // endregion: IMPORTS diff --git a/paxy/src/action/repository/update.rs b/paxy/src/action/repository/update.rs index 971f9dc..204b7ab 100644 --- a/paxy/src/action/repository/update.rs +++ b/paxy/src/action/repository/update.rs @@ -1,9 +1,16 @@ -pub fn run_update( - repository_update_arguments: ui::cli_template::RepositoryUpdateArguments, +#[allow(unused)] +pub fn handle_repository_update_action( + repository_update_arguments: RepositoryUpdateArguments, ) -> Result<(), Error> { - todo!() + use crate::app::ui::console_template::cli::*; + + todo!(); + + // Ok(()) } +// region: ERRORS + #[derive(Debug, Snafu)] #[snafu(visibility(pub(crate)))] #[non_exhaustive] @@ -13,10 +20,13 @@ pub enum Error { Dummy {}, } +// endregion: ERRORS + // region: IMPORTS -use snafu::Snafu; +#[allow(unused)] +use snafu::{ResultExt, Snafu}; -use crate::app::ui; +use crate::app::ui::console_template::cli::RepositoryUpdateArguments; // endregion: IMPORTS diff --git a/paxy/src/app.rs b/paxy/src/app.rs index 51b6530..dd20419 100644 --- a/paxy/src/app.rs +++ b/paxy/src/app.rs @@ -1,7 +1,38 @@ +//! Handles application related functionality - UI, logging, config, OS, etc. +//! , not the various package or repository actions that form the core +//! functionality of paxy. + lazy_static! { + /// A global variable that represents the application name. pub static ref APP_NAME: &'static str = "paxy"; } +/// Run common tasks pertaining to both CLI and GUI. This includes parsing +/// console arguments, obtaining user configuration +#[tracing::instrument(level = "trace")] +pub fn run_common() -> Result<(C, Vec), Error> +where + // [`clap::Parser`] binding to parse console input, [`GlobalArguments`] + // binding to extract global arguments, and [`fmt::Debug`] binding to + // display commandline arguments + C: clap::Parser + GlobalArguments + fmt::Debug, +{ + // Obtain CLI arguments. Also provides info for setting up configuration and + // logging + let console_input = C::parse(); + + // Obtain user configuration + let config = config::init_config(&console_input).context(ConfigSnafu {})?; + + // Begin logging and outputting to console + let logging_handle = logging::init_log(&config).context(LoggingSnafu {})?; + + // Display initializing messages + ui::emit_init_messages(&config, &console_input); + + Ok((console_input, logging_handle.worker_guards)) +} + // region: ERRORS #[derive(Debug, Snafu)] @@ -22,14 +53,10 @@ pub enum Error { }, #[non_exhaustive] - #[snafu(display("in the UI: {source}"), visibility(pub))] - Ui { - #[snafu(backtrace)] - source: ui::Error, - }, - - #[non_exhaustive] - #[snafu(display("in internationalization: {source}"), visibility(pub))] + #[snafu( + display("in internationalization/regionalization/translation: {source}"), + visibility(pub) + )] Internationalization { #[snafu(backtrace)] source: i18n::Error, @@ -40,8 +67,11 @@ pub enum Error { // region: IMPORTS +use std::fmt; + use lazy_static::lazy_static; -use snafu::Snafu; +use snafu::{ResultExt, Snafu}; +use ui::GlobalArguments; // endregion: IMPORTS diff --git a/paxy/src/app/config.rs b/paxy/src/app/config.rs index 66870bf..99e40b6 100644 --- a/paxy/src/app/config.rs +++ b/paxy/src/app/config.rs @@ -1,4 +1,9 @@ +//! Handles configuration of the app through global and local settings files, +//! through global and app-specific environment variables, and through console +//! input. + lazy_static! { + /// Global variable representing supported configuration file extensions pub static ref CONFIG_FILE_EXTENSIONS: &'static [&'static str] = &["toml", "json", "yaml", "yml"]; } diff --git a/paxy/src/app/i18n.rs b/paxy/src/app/i18n.rs index ef0eadc..6206803 100644 --- a/paxy/src/app/i18n.rs +++ b/paxy/src/app/i18n.rs @@ -1,10 +1,4 @@ -// TODO: The module code goes here - -// region: IMPORTS - -use snafu::Snafu; - -// endregion: IMPORTS +// TODO: Add code here // region: ERRORS @@ -17,3 +11,9 @@ pub enum Error { } // endregion: ERRORS + +// region: IMPORTS + +use snafu::Snafu; + +// endregion: IMPORTS diff --git a/paxy/src/app/logging.rs b/paxy/src/app/logging.rs index 62229ec..2aec28f 100644 --- a/paxy/src/app/logging.rs +++ b/paxy/src/app/logging.rs @@ -1,3 +1,10 @@ +//! Handles both logging to file(s) and all messages displayed to the console. +//! Even messages intended for the user are supplied via logging macros. The +//! console output mode and the output verbosity level limit what goes to the +//! console. The logging target sent to the macros for each logging message +//! decides which output mode the message is intended to target. + +/// Begins logging with the provided settings. pub fn init_log(config: &config::ConfigTemplate) -> Result { let log_filename = format!("{}.log", *app::APP_NAME); let log_file_appender = diff --git a/paxy/src/app/ui.rs b/paxy/src/app/ui.rs index c428850..867599b 100644 --- a/paxy/src/app/ui.rs +++ b/paxy/src/app/ui.rs @@ -1,28 +1,12 @@ -#[tracing::instrument(level = "trace")] -pub fn run_common() -> Result<(C, Vec), crate::Error> +//! Objects pertaining to the UI. + +pub fn emit_init_messages(config: &ConfigTemplate, console_input: &C) where - C: clap::Parser + GlobalArguments + fmt::Debug, + C: clap::Parser + fmt::Debug, { - // Obtain CLI arguments - let console_input = C::parse(); - - // Obtain user configuration - let config = config::init_config(&console_input) - .context(app::ConfigSnafu {}) - .context(crate::AppSnafu)?; - - // Begin logging and outputting - let logging_handle = logging::init_log(&config) - .context(app::LoggingSnafu {}) - .context(crate::AppSnafu {})?; - emit_welcome_messages(); - - emit_diagnostic_messages(&config); - - emit_test_messages(&config, &console_input); - - Ok((console_input, logging_handle.worker_guards)) + emit_diagnostic_messages(config); + emit_test_messages(config, console_input); } fn emit_welcome_messages() { @@ -43,7 +27,7 @@ fn emit_welcome_messages() { ); acc.push_str(" "); acc.push_str(author); - acc.push_str("\n"); + acc.push('\n'); acc }); @@ -193,6 +177,7 @@ where ); } +/// Configurable settings that handle how the console output is displayed. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct ConsoleOutputFormat { pub mode: ConsoleOutputMode, @@ -256,6 +241,13 @@ impl ConsoleOutputFormat { } } +/// Represents the output mode of the app. The `Regular` for displaying all +/// logging messages (up to the maximum verbosity set by the user) to the +/// console. The `Plain` mode is for displaying just the main output of the app +/// without any human-facing messages. The `Json` mode also displays the main +/// output of the app, but in the `JSON` format. Both `Plain` and `JSON` modes +/// are to be used to obtain pure scriptable and program-ready outputs without +/// any polluting human messages. #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] pub enum ConsoleOutputMode { #[default] @@ -265,6 +257,8 @@ pub enum ConsoleOutputMode { Test, } +/// A common interface for CLI templates to convey information about standard +/// global arguments pub trait GlobalArguments { fn config_filepath(&self) -> &Option; @@ -303,6 +297,8 @@ pub trait GlobalArguments { } } +/// Blanket implementation of [`GlobalArguments`] interface for *references* +/// of all objects that already implement `GlobalArguments`. impl GlobalArguments for &T { fn config_filepath(&self) -> &Option { (**self).config_filepath() @@ -333,34 +329,19 @@ impl GlobalArguments for &T { } } -#[derive(Debug, Snafu)] -#[non_exhaustive] -pub enum Error { - #[non_exhaustive] - #[snafu(display(""))] - Dummy {}, -} - // region: IMPORTS -use core::fmt; -use std::path::PathBuf; +use std::{fmt, path::PathBuf}; -// endregion: IMPORTS - -// region: MODULES +use owo_colors::OwoColorize; +use serde::{Deserialize, Serialize}; -pub mod console_template; +use crate::app::config::ConfigTemplate; -// endregion: MODULES +// endregion: IMPORTS -#[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; +// region: EXTERNAL-SUBMODULES -use super::config::ConfigTemplate; -use crate::app::{self, config, logging}; // Flatten the module heirarchy for easier access +pub mod console_template; +// endregion: EXTERNAL-SUBMODULES diff --git a/paxy/src/app/ui/console_template.rs b/paxy/src/app/ui/console_template.rs index 6c377c9..4412ee6 100644 --- a/paxy/src/app/ui/console_template.rs +++ b/paxy/src/app/ui/console_template.rs @@ -1,5 +1,7 @@ -//! Common commandline interface template for global arguments, intended to be -//! shared between the GUI and CLI programs. +//! Templates to be used for commandline interface for both GUI and CLI modes. + +/// 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 @@ -93,14 +95,6 @@ where } } -#[derive(Debug, Snafu)] -#[non_exhaustive] -pub enum Error { - #[non_exhaustive] - #[snafu(display(""), visibility(pub))] - GuiDummy {}, // No errors implemented yet -} - // region: IMPORTS // endregion: IMPORTS @@ -113,13 +107,11 @@ 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; +use crate::app::ui::GlobalArguments; // endregion: IMPORTS diff --git a/paxy/src/app/ui/console_template/cli.rs b/paxy/src/app/ui/console_template/cli.rs index 182067c..8cb64d4 100644 --- a/paxy/src/app/ui/console_template/cli.rs +++ b/paxy/src/app/ui/console_template/cli.rs @@ -21,7 +21,7 @@ )] pub struct CliTemplate { #[command(flatten)] - pub global_args: ui::cli_template::GlobalArgs, + pub global_args: GlobalArgs, #[command(subcommand)] pub entity: Option, @@ -365,6 +365,7 @@ pub struct RepositoryDowngradeArguments { use std::path::PathBuf; use clap::{Args, Parser, Subcommand}; -use paxy::app::ui::{self, cli_template::*}; + +use crate::app::ui::{self, console_template::GlobalArgs}; // endregion: IMPORTS diff --git a/paxy/src/app/ui/console_template/gui.rs b/paxy/src/app/ui/console_template/gui.rs index 4f118bc..54e9844 100644 --- a/paxy/src/app/ui/console_template/gui.rs +++ b/paxy/src/app/ui/console_template/gui.rs @@ -6,7 +6,7 @@ #[command(version, author, about, args_conflicts_with_subcommands = true)] pub struct CliTemplate { #[clap(flatten)] - pub global_args: ui::cli_template::GlobalArgs, + pub global_args: GlobalArgs, } /// Implement a trait that can extract standard global arguments from @@ -53,6 +53,7 @@ impl ui::GlobalArguments for CliTemplate { use std::path::PathBuf; use clap::Parser; -use paxy::app::ui; + +use crate::app::ui::{self, console_template::GlobalArgs}; // endregion: IMPORTS diff --git a/paxy/src/data/config.rs b/paxy/src/data/config.rs index 6fa649a..7fb377a 100644 --- a/paxy/src/data/config.rs +++ b/paxy/src/data/config.rs @@ -23,7 +23,7 @@ impl Default for Config { }; user.push(".paxy"); user.push("pkgs"); - let system = if cfg!(linux) { + let system = if cfg!(unix) { PathBuf::from("/") } else { PathBuf::from("") diff --git a/paxy/src/data.rs b/paxy/src/data/mod.rs similarity index 99% rename from paxy/src/data.rs rename to paxy/src/data/mod.rs index f769933..87db370 100644 --- a/paxy/src/data.rs +++ b/paxy/src/data/mod.rs @@ -35,4 +35,3 @@ use snafu::Snafu; mod config; // endregion: EXTERNAL-SUBMODULES - diff --git a/paxy/src/lib.rs b/paxy/src/lib.rs index 6401181..7433ad7 100644 --- a/paxy/src/lib.rs +++ b/paxy/src/lib.rs @@ -1,3 +1,5 @@ +//! The core library of paxy + // Returns a string representation of the type of the given object, which can // be displayed or further processed. pub fn type_of(_: &T) -> &str { @@ -10,6 +12,9 @@ pub fn type_of(_: &T) -> &str { #[snafu(visibility(pub(crate)))] #[non_exhaustive] pub enum Error { + /// Indicates that the error is in the application which deals with UI, + /// logging, config, OS, etc., not in the various package or repository + /// actions that form the core functionality of paxy. #[non_exhaustive] #[snafu(display("in the app: {source}"), visibility(pub))] App { @@ -17,6 +22,9 @@ pub enum Error { source: app::Error, }, + /// Indicates that the error is in the package or repository actions that + /// form the core functionality of paxy, not in the application that + /// deals with UI, logging, config, OS, etc. #[non_exhaustive] #[snafu(display("in an action:{source}"), visibility(pub))] Action { From e3bb659e06b1e61111f9189b9beb765d90f0a287 Mon Sep 17 00:00:00 2001 From: pvshvp-oss Date: Mon, 13 May 2024 16:57:12 -0500 Subject: [PATCH 3/3] Do not run CI by default on other branches --- .github/workflows/code_validation.yml | 1 + .github/workflows/security_audit.yml | 1 + paxy/src/action/repository/install.rs | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/code_validation.yml b/.github/workflows/code_validation.yml index c10dab5..7ec20a5 100644 --- a/.github/workflows/code_validation.yml +++ b/.github/workflows/code_validation.yml @@ -5,6 +5,7 @@ on: - '**/Cargo.toml' # Run when dependencies change - '**/Cargo.lock' # Run when dependencies change - '**/src/**' + branches: [main] pull_request: paths: - '.github/workflows/code_validation.yml' # Run when this workflow changes diff --git a/.github/workflows/security_audit.yml b/.github/workflows/security_audit.yml index 4ba48a3..41cf1cc 100644 --- a/.github/workflows/security_audit.yml +++ b/.github/workflows/security_audit.yml @@ -6,6 +6,7 @@ on: - '.github/workflows/security_audit.yml' # Run when this workflow changes - '**/Cargo.toml' # Run when dependencies change - '**/Cargo.lock' # Run when dependencies change + branches: [main] pull_request: paths: - '.github/workflows/security_audit.yml' # Run when this workflow changes diff --git a/paxy/src/action/repository/install.rs b/paxy/src/action/repository/install.rs index ccc9d09..1944c50 100644 --- a/paxy/src/action/repository/install.rs +++ b/paxy/src/action/repository/install.rs @@ -6,7 +6,7 @@ pub fn handle_repository_install_action( todo!(); - Ok(()) + // Ok(()) } #[allow(unused)]