Skip to content

Commit

Permalink
feat(args): update clap to v4
Browse files Browse the repository at this point in the history
  • Loading branch information
lbowenwest committed Jan 15, 2023
1 parent 336b25f commit 8f4c25a
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 62 deletions.
92 changes: 66 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions git-cliff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ regex.workspace = true
pretty_env_logger = "0.4.0"
log = "0.4.17"
dirs-next = "2.0.0"
clap_complete = "3.2.5"
clap_mangen = "0.1.11"
clap_complete = "4.1.0"
clap_mangen = "0.2.7"

[dependencies.git-cliff-core]
version = "1.1.1" # managed by release.sh
path = "../git-cliff-core"

[dependencies.clap]
version = "3.2.22"
version = "4.1.1"
features = ["derive", "env", "wrap_help"]

[dependencies.update-informer]
Expand Down
61 changes: 30 additions & 31 deletions git-cliff/src/args.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
use clap::{
AppSettings,
ArgEnum,
ArgAction,
Parser,
ValueEnum,
};
use git_cliff_core::DEFAULT_CONFIG;
use glob::Pattern;
use std::path::PathBuf;

#[derive(Debug, Clone, Copy, ArgEnum)]
#[derive(Debug, Clone, Copy, ValueEnum)]
pub enum Strip {
Header,
Footer,
All,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, ArgEnum)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
pub enum Sort {
Oldest,
Newest,
}

/// Command-line arguments to parse.
#[derive(Debug, Parser)]
#[clap(
#[command(
version,
author,
about,
global_setting = AppSettings::DeriveDisplayOrder,
rename_all_env = "screaming-snake",
next_help_heading = Some("OPTIONS"),
override_usage = "git-cliff [FLAGS] [OPTIONS] [--] [RANGE]",
Expand All @@ -35,55 +34,55 @@ pub enum Sort {
)]
pub struct Opt {
/// Increases the logging verbosity.
#[clap(short, long, parse(from_occurrences), alias = "debug", help_heading = Some("FLAGS"))]
#[arg(short, long, action = ArgAction::Count, alias = "debug", help_heading = Some("FLAGS"))]
pub verbose: u8,
/// Sets the configuration file.
#[clap(short, long, env = "GIT_CLIFF_CONFIG", value_name = "PATH", default_value = DEFAULT_CONFIG)]
#[arg(short, long, env = "GIT_CLIFF_CONFIG", value_name = "PATH", default_value = DEFAULT_CONFIG)]
pub config: PathBuf,
/// Sets the working directory.
#[clap(short, long, env = "GIT_CLIFF_WORKDIR", value_name = "PATH")]
#[arg(short, long, env = "GIT_CLIFF_WORKDIR", value_name = "PATH")]
pub workdir: Option<PathBuf>,
/// Sets the git repository.
#[clap(
#[arg(
short,
long,
env = "GIT_CLIFF_REPOSITORY",
value_name = "PATH",
multiple_values = true
num_args(1..)
)]
pub repository: Option<Vec<PathBuf>>,
/// Sets the path to include related commits.
#[clap(
#[arg(
long,
env = "GIT_CLIFF_INCLUDE_PATH",
value_name = "PATTERN",
multiple_values = true
num_args(1..)
)]
pub include_path: Option<Vec<Pattern>>,
/// Sets the path to exclude related commits.
#[clap(
#[arg(
long,
env = "GIT_CLIFF_EXCLUDE_PATH",
value_name = "PATTERN",
multiple_values = true
num_args(1..)
)]
pub exclude_path: Option<Vec<Pattern>>,
/// Sets custom commit messages to include in the changelog.
#[clap(
#[arg(
long,
env = "GIT_CLIFF_WITH_COMMIT",
value_name = "MSG",
multiple_values = true
num_args(1..)
)]
pub with_commit: Option<Vec<String>>,
/// Prepends entries to the given changelog file.
#[clap(short, long, env = "GIT_CLIFF_PREPEND", value_name = "PATH")]
#[arg(short, long, env = "GIT_CLIFF_PREPEND", value_name = "PATH")]
pub prepend: Option<PathBuf>,
/// Writes output to the given file.
#[clap(short, long, env = "GIT_CLIFF_OUTPUT", value_name = "PATH")]
#[arg(short, long, env = "GIT_CLIFF_OUTPUT", value_name = "PATH")]
pub output: Option<PathBuf>,
/// Sets the tag for the latest version.
#[clap(
#[arg(
short,
long,
env = "GIT_CLIFF_TAG",
Expand All @@ -92,7 +91,7 @@ pub struct Opt {
)]
pub tag: Option<String>,
/// Sets the template for the changelog body.
#[clap(
#[arg(
short,
long,
env = "GIT_CLIFF_TEMPLATE",
Expand All @@ -101,34 +100,34 @@ pub struct Opt {
)]
pub body: Option<String>,
/// Writes the default configuration file to cliff.toml
#[clap(short, long, help_heading = Some("FLAGS"))]
#[arg(short, long, help_heading = Some("FLAGS"))]
pub init: bool,
/// Processes the commits starting from the latest tag.
#[clap(short, long, help_heading = Some("FLAGS"))]
#[arg(short, long, help_heading = Some("FLAGS"))]
pub latest: bool,
/// Processes the commits that belong to the current tag.
#[clap(long, help_heading = Some("FLAGS"))]
#[arg(long, help_heading = Some("FLAGS"))]
pub current: bool,
/// Processes the commits that do not belong to a tag.
#[clap(short, long, help_heading = Some("FLAGS"))]
#[arg(short, long, help_heading = Some("FLAGS"))]
pub unreleased: bool,
/// Sorts the tags topologically.
#[clap(long, help_heading = Some("FLAGS"))]
#[arg(long, help_heading = Some("FLAGS"))]
pub topo_order: bool,
/// Prints changelog context as JSON.
#[clap(long, help_heading = Some("FLAGS"))]
#[arg(long, help_heading = Some("FLAGS"))]
pub context: bool,
/// Strips the given parts from the changelog.
#[clap(short, long, value_name = "PART", arg_enum)]
#[arg(short, long, value_name = "PART", value_enum)]
pub strip: Option<Strip>,
/// Sets sorting of the commits inside sections.
#[clap(
#[arg(
long,
arg_enum,
value_enum,
default_value_t = Sort::Oldest
)]
pub sort: Sort,
/// Sets the commit range to process.
#[clap(value_name = "RANGE", help_heading = Some("ARGS"))]
#[arg(value_name = "RANGE", help_heading = Some("ARGS"))]
pub range: Option<String>,
}
2 changes: 1 addition & 1 deletion git-cliff/src/bin/completions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{
ArgEnum,
CommandFactory,
ValueEnum,
};
use clap_complete::Shell;
use git_cliff::args::Opt;
Expand Down
2 changes: 1 addition & 1 deletion git-cliff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use args::{
Strip,
};
use changelog::Changelog;
use clap::ArgEnum;
use clap::ValueEnum;
use git_cliff_core::commit::Commit;
use git_cliff_core::config::Config;
use git_cliff_core::embed::EmbeddedConfig;
Expand Down

0 comments on commit 8f4c25a

Please sign in to comment.