Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Config overhaul #17

Merged
merged 19 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ paxy = { path = "paxy" }
tracing = "0.1"
tracing-appender = "0.2"
tracing-subscriber = "0.3"
log = "0.4"

# Configuration
figment = "0.10"
Expand All @@ -57,7 +58,7 @@ serde-aux = "4.5"
serde_yaml = "0.9"
tracing-serde = "0.1"
speedy = "0.8"
log = "0.4"
itertools = "0.12"

# Internationalization
fluent = "0.16"
Expand Down
1 change: 1 addition & 0 deletions paxy-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ paxy = { workspace = true }

# Logging
tracing = { workspace = true }
log = { workspace = true, features = ["serde"] }

# Error handling
snafu = {workspace = true}
Expand Down
58 changes: 31 additions & 27 deletions paxy-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
//! Has the [`run_cli`] function and the commandline interface template
//! [`cli_template::CliTemplate`]

/// Calls the [`ui::run_common::<C>`] 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, _worker_guards) = ui::run_common::<CliTemplate>()?;
let (_cli_input, _logging_worker_guards) = ui::run_common::<CliTemplate>()?;

tracing::debug!(
"Running in {} mode... {}",
Expand All @@ -19,8 +26,9 @@ pub enum Error {
}

// region: IMPORTS

use owo_colors::OwoColorize;
use paxy::ui;
use paxy::app::ui;
use snafu::Snafu;

// endregion: IMPORTS
Expand Down Expand Up @@ -51,7 +59,7 @@ mod cli_template {
)]
pub struct CliTemplate {
#[command(flatten)]
pub global_arguments: ui::cli_template::GlobalArgs<clap_verbosity_flag::InfoLevel>,
pub global_args: ui::cli_template::GlobalArgs<clap_verbosity_flag::InfoLevel>,

#[command(subcommand)]
pub entity: Option<EntitySubcommand>,
Expand All @@ -60,43 +68,39 @@ mod cli_template {
/// Implement a trait that can extract standard global arguments from our
/// own CLI template
impl ui::GlobalArguments for CliTemplate {
type L = clap_verbosity_flag::InfoLevel;

fn config_file(&self) -> &Option<PathBuf> {
&self
.global_arguments
.config_file
fn config_filepath(&self) -> &Option<PathBuf> {
self.global_args
.config_filepath()
}

fn is_json(&self) -> bool {
self.global_arguments
.json_flag
self.global_args
.is_json()
}

fn is_plain(&self) -> bool {
self.global_arguments
.plain_flag
self.global_args
.is_plain()
}

fn is_debug(&self) -> bool {
self.global_arguments
.debug_flag
self.global_args
.is_debug()
}

fn is_no_color(&self) -> bool {
self.global_arguments
.no_color_flag
fn is_test(&self) -> bool {
self.global_args
.is_test()
}

fn is_test(&self) -> bool {
self.global_arguments
.test_flag
fn is_no_color(&self) -> bool {
self.global_args
.is_no_color()
}

fn verbosity(&self) -> &clap_verbosity_flag::Verbosity<Self::L> {
&self
.global_arguments
.verbose
fn verbosity_filter(&self) -> log::LevelFilter {
self.global_args
.verbosity_filter()
}
}

Expand Down Expand Up @@ -399,7 +403,7 @@ mod cli_template {
use std::path::PathBuf;

use clap::{Args, Parser, Subcommand};
use paxy::ui;
use paxy::app::ui;

// endregion: IMPORTS
}
Expand All @@ -408,6 +412,6 @@ mod cli_template {

// region: RE-EXPORTS

pub use cli_template::*;
pub use cli_template::*; // Flatten the module heirarchy for easier access

// endregion: RE-EXPORTS
7 changes: 7 additions & 0 deletions paxy-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//! 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
/// [`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();
match return_value {
Expand Down
1 change: 1 addition & 0 deletions paxy-gui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ paxy = { workspace = true }

# Logging
tracing = { workspace = true }
log = { workspace = true, features = ["serde"] }

# Error handling
snafu = {workspace = true}
Expand Down
53 changes: 31 additions & 22 deletions paxy-gui/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
//! Has the [`run_gui`] function and the commandline interface template
//! [`gui_cli_template::CliTemplate`]

/// Calls the [`ui::run_common::<C>`] 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, _worker_guards) = ui::run_common::<CliTemplate>()?;
let (_cli_input, _logging_worker_guards) = ui::run_common::<CliTemplate>()?;

tracing::debug!(
"Running in {} mode... {}",
Expand All @@ -15,65 +22,67 @@ pub fn run_gui() -> Result<(), paxy::Error> {
pub enum Error {
#[non_exhaustive]
#[snafu(display(""), visibility(pub))]
GuiDummy {},
GuiDummy {}, // No errors implemented yet
}

// region: IMPORTS

use owo_colors::OwoColorize;
use paxy::ui;
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<clap_verbosity_flag::InfoLevel>,
}

/// Implement a trait that can extract standard global arguments from our
/// own CLI template
impl ui::GlobalArguments for CliTemplate {
type L = clap_verbosity_flag::InfoLevel;

fn config_file(&self) -> &Option<PathBuf> {
&self
.global_args
.config_file
fn config_filepath(&self) -> &Option<PathBuf> {
self.global_args
.config_filepath()
}

fn is_json(&self) -> bool {
self.global_args
.json_flag
.is_json()
}

fn is_plain(&self) -> bool {
self.global_args
.plain_flag
.is_plain()
}

fn is_debug(&self) -> bool {
self.global_args
.debug_flag
.is_debug()
}

fn is_no_color(&self) -> bool {
fn is_test(&self) -> bool {
self.global_args
.no_color_flag
.is_test()
}

fn is_test(&self) -> bool {
fn is_no_color(&self) -> bool {
self.global_args
.test_flag
.is_no_color()
}

fn verbosity(&self) -> &clap_verbosity_flag::Verbosity<Self::L> {
&self
.global_args
.verbose
fn verbosity_filter(&self) -> log::LevelFilter {
self.global_args
.verbosity_filter()
}
}

Expand All @@ -82,7 +91,7 @@ mod gui_cli_template {
use std::path::PathBuf;

use clap::Parser;
use paxy::ui;
use paxy::app::ui;

// endregion: IMPORTS
}
Expand All @@ -91,6 +100,6 @@ mod gui_cli_template {

// region: RE-EXPORTS

pub use gui_cli_template::*;
pub use gui_cli_template::*; // Flatten the module heirarchy for easier access

// endregion: RE-EXPORTS
7 changes: 7 additions & 0 deletions paxy-gui/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
//! 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
/// [`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();
match return_value {
Expand Down
5 changes: 3 additions & 2 deletions paxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ edition.workspace = true
tracing = { workspace = true }
tracing-appender = { workspace = true }
tracing-subscriber = { workspace = true }
log = { workspace = true, features = ["serde"] }

# Configuration
figment = { workspace = true, features = ["toml", "json", "yaml", "env"] }
Expand All @@ -37,7 +38,7 @@ serde-aux = { workspace = true }
serde_yaml = { workspace = true }
tracing-serde = { workspace = true }
speedy = { workspace = true }
log = { workspace = true, features = ["serde"] }
itertools = { workspace = true }

# Internationalization
fluent = { workspace = true }
Expand All @@ -53,7 +54,7 @@ console = { workspace = true }
home = "0.5.9"
toml = "0.8.10"
pollster = "0.3"
reqwest = "0.11"
reqwest = "0.12"
url = { version = "2.3", features = ["serde"] }
extism = "1.2.0"
bson = "2.9.0"
Expand Down
Loading
Loading