Skip to content

Commit

Permalink
merged config
Browse files Browse the repository at this point in the history
  • Loading branch information
FerrisWasTaken committed May 9, 2024
2 parents ca62b9d + 298cba2 commit 137dd60
Show file tree
Hide file tree
Showing 14 changed files with 761 additions and 461 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ paxy = { path = "paxy" }
tracing = "0.1"
tracing-appender = "0.2"
tracing-subscriber = "0.3"
log = "0.4"

# Configuration
figment = "0.10"
Expand All @@ -59,7 +60,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
53 changes: 28 additions & 25 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 Down Expand Up @@ -51,7 +58,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 +67,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 @@ -408,6 +411,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
49 changes: 29 additions & 20 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,7 +22,7 @@ pub fn run_gui() -> Result<(), paxy::Error> {
pub enum Error {
#[non_exhaustive]
#[snafu(display(""), visibility(pub))]
GuiDummy {},
GuiDummy {}, // No errors implemented yet
}

// region: IMPORTS
Expand All @@ -28,52 +35,54 @@ use snafu::Snafu;

// 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 @@ -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

0 comments on commit 137dd60

Please sign in to comment.