Skip to content

Commit

Permalink
fix: 🚚 Move global arguments to a common area
Browse files Browse the repository at this point in the history
  • Loading branch information
pvshvp-oss committed Apr 8, 2024
1 parent ac61853 commit 3c98621
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 61 deletions.
61 changes: 1 addition & 60 deletions paxy-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ mod cli_template {
)]
pub struct CliTemplate {
#[command(flatten)]
pub global_arguments: GlobalArguments<clap_verbosity_flag::InfoLevel>,
pub global_arguments: ui::cli_template::GlobalArguments<clap_verbosity_flag::InfoLevel>,

#[command(subcommand)]
pub entity: Option<EntitySubcommand>,
Expand Down Expand Up @@ -100,65 +100,6 @@ mod cli_template {
}
}

#[derive(Clone, Debug, Args)]
#[command(next_display_order = usize::MAX - 100)]
pub struct GlobalArguments<L>
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<PathBuf>,

#[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 verbose: clap_verbosity_flag::Verbosity<L>,
}

#[derive(Debug, Subcommand)]
#[command(args_conflicts_with_subcommands = true)]
pub enum EntitySubcommand {
Expand Down
2 changes: 1 addition & 1 deletion paxy-gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod gui_cli_template {
#[command(version, author, about, args_conflicts_with_subcommands = true)]
pub struct CliTemplate {
#[clap(flatten)]
pub global_args: ui::GlobalArgs<clap_verbosity_flag::InfoLevel>,
pub global_args: ui::cli_template::GlobalArguments<clap_verbosity_flag::InfoLevel>,
}

impl ui::GlobalArguments for CliTemplate {
Expand Down
72 changes: 72 additions & 0 deletions paxy/src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,80 @@ use crate::app::{self, config, logging};

// region: MODULES

pub mod cli_template {
#[derive(Clone, Debug, Args)]
#[command(next_display_order = usize::MAX - 100)]
pub struct GlobalArguments<L>
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<PathBuf>,

#[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 verbose: clap_verbosity_flag::Verbosity<L>,
}

// region: IMPORTS

use std::path::PathBuf;

use clap::Args;

// endregion: IMPORTS
}

// endregion: MODULES

// region: RE-EXPORTS

#[allow(unused_imports)]
pub use cli_template::*;

// endregion: RE-EXPORTS

0 comments on commit 3c98621

Please sign in to comment.