Skip to content

Commit

Permalink
sign: Add the global flags mentioned in configs
Browse files Browse the repository at this point in the history
  • Loading branch information
necauqua authored and julienvincent committed Feb 9, 2024
1 parent f8dc6a3 commit 58b4ed3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
30 changes: 28 additions & 2 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2093,7 +2093,7 @@ pub fn print_dropped_signatures(ui: &Ui, num_dropped: usize) -> Result<(), std::
}
Ok(())
}

pub fn parse_string_pattern(src: &str) -> Result<StringPattern, StringPatternParseError> {
if let Some((kind, pat)) = src.split_once(':') {
StringPattern::from_str_kind(pat, kind)
Expand Down Expand Up @@ -2615,10 +2615,29 @@ pub struct EarlyArgs {
#[arg(long, value_name = "WHEN", global = true)]
pub color: Option<ColorChoice>,
/// Disable the pager
#[arg(long, value_name = "WHEN", global = true, action = ArgAction::SetTrue)]
#[arg(long, global = true, action = ArgAction::SetTrue)]
// Parsing with ignore_errors will crash if this is bool, so use
// Option<bool>.
pub no_pager: Option<bool>,
/// Override the configured key to be used for the commit signing.
/// Is only used when a commit signing operation has to be performed by the
/// operation.
#[arg(
long,
value_name = "KEY",
global = true,
help_heading = "Global Options"
)]
pub sign_with: Option<String>,
/// Don't sign unsigned commits when configured to sign all, is ignored
/// otherwise.
#[arg(
long,
global = true,
help_heading = "Global Options",
action = ArgAction::SetTrue
)]
pub no_sign: Option<bool>,
/// Additional configuration options (can be repeated)
// TODO: Introduce a `--config` option with simpler syntax for simple
// cases, designed so that `--config ui.color=auto` works
Expand Down Expand Up @@ -2806,6 +2825,13 @@ fn handle_early_args(
if args.no_pager.unwrap_or_default() {
args.config_toml.push(r#"ui.paginate="never""#.to_owned());
}
if let Some(key) = args.sign_with {
args.config_toml.push(format!(r#"signing.key="{key}""#));
}
if args.no_sign.unwrap_or_default() {
args.config_toml
.push(r#"signing.sign-all=false"#.to_owned());
}
if !args.config_toml.is_empty() {
layered_configs.parse_config_args(&args.config_toml)?;
ui.reset(&layered_configs.merge())?;
Expand Down
5 changes: 5 additions & 0 deletions cli/tests/test_global_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,11 @@ fn test_help() {
-v, --verbose Enable verbose logging
--color <WHEN> When to colorize output (always, never, auto)
--no-pager Disable the pager
--sign-with <KEY> Override the configured key to be used for the commit signing.
Is only used when a commit signing operation has to be
performed by the operation
--no-sign Don't sign unsigned commits when configured to sign all, is
ignored otherwise
--config-toml <TOML> Additional configuration options (can be repeated)
"###);
}
Expand Down

0 comments on commit 58b4ed3

Please sign in to comment.