Skip to content

Commit

Permalink
Enable overriding the comments option; #20
Browse files Browse the repository at this point in the history
  • Loading branch information
msuchane committed Feb 27, 2024
1 parent 0eac23d commit 738033b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
28 changes: 16 additions & 12 deletions src/cmd_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,10 @@ pub struct CommonOptions {
#[bpaf(short('A'), long)]
pub anchor_prefixes: bool,

/// Generate the file without any comments.
/// This option is now the default.
/// The option is hidden, has no effect, and exists only for compatibility
/// with previous releases.
#[bpaf(short('C'), long, hide)]
pub no_comments: bool,

/// Generate the file without any example, placeholder content
#[bpaf(short('E'), long, long("expert-mode"))]
pub no_examples: bool,

/// Generate the file with explanatory comments
#[bpaf(short('M'), long)]
pub comments: bool,

/// Do not use module type prefixes (such as `proc_`) in file names
#[bpaf(short('P'), long, long("no-prefixes"))]
pub no_file_prefixes: bool,
Expand All @@ -73,8 +62,11 @@ pub struct CommonOptions {
#[bpaf(short('T'), long, argument("DIRECTORY"), fallback(".".into()))]
pub target_dir: PathBuf,

#[bpaf(external, fallback(Verbosity::Default))]
#[bpaf(external, fallback(Verbosity::default()))]
pub verbosity: Verbosity,

#[bpaf(external, fallback(Comments::default()))]
pub comments: Comments,
}

#[derive(Clone, Debug, Bpaf)]
Expand Down Expand Up @@ -125,6 +117,18 @@ pub enum Verbosity {
Default,
}

#[derive(Clone, Copy, Debug, Bpaf, Serialize, Deserialize, Default, PartialEq)]
pub enum Comments {
/// Generate the file without any comments.
/// This option is now the default.
#[default]
#[bpaf(short('C'), long)]
NoComments,
/// Generate the file with explanatory comments
#[bpaf(short('M'), long)]
Comments,
}

/// Check that the current command generates or validates at least one file.
fn at_least_one_file(action: &Action) -> bool {
!action.assembly.is_empty()
Expand Down
7 changes: 5 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use directories::ProjectDirs;
use figment::{Figment, providers::{Format, Toml, Serialized}};
use serde::{Serialize, Deserialize};

use crate::cmd_line::{Cli, Verbosity};
use crate::cmd_line::{Cli, Comments, Verbosity};

const PKG_NAME: &str = env!("CARGO_PKG_NAME");

Expand All @@ -29,7 +29,10 @@ impl Options {
// Comments and prefixes are enabled (true) by default unless you disable them
// on the command line. If the no-comments or no-prefixes option is passed,
// the feature is disabled, so the option is set to false.
comments: cli.common_options.comments,
comments: match cli.common_options.comments {
Comments::Comments => true,
Comments::NoComments => false,
},
file_prefixes: !cli.common_options.no_file_prefixes,
anchor_prefixes: cli.common_options.anchor_prefixes,
examples: !cli.common_options.no_examples,
Expand Down
7 changes: 0 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,6 @@ pub fn run(options: &Options, cli: &Cli) -> Result<()> {
log::warn!("The validation feature has been removed. \
Please switch to the Enki validation tool: <https://github.com/Levi-Leah/enki/>.");
}
if cli.common_options.no_comments {
log::warn!(
"The --no-comments (-C) option is deprecated and has no effect anymore.\n\
By default, generated modules do not contain any comments.\n\
If you want to include comments, use the --comments (-M) option."
);
}

// Attach titles from the CLI to content types.
let content_types = [
Expand Down

0 comments on commit 738033b

Please sign in to comment.