cli: rename --verbose to --debug to better fit what it does

This commit is contained in:
Alexis (Poliorcetics) Bourget 2024-02-18 17:47:12 +01:00 committed by Poliorcetics
parent 06d67f02d8
commit 0fc5005b8a
9 changed files with 28 additions and 26 deletions

View file

@ -53,6 +53,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `jj git fetch` now automatically prints new remote branches and tags by default. * `jj git fetch` now automatically prints new remote branches and tags by default.
* `--verbose/-v` is now `--debug` (no short option since it's not intended to be used often)
### Fixed bugs ### Fixed bugs
* On Windows, symlinks in the repo are now materialized as regular files in the * On Windows, symlinks in the repo are now materialized as regular files in the

View file

@ -555,15 +555,15 @@ impl TracingSubscription {
} }
} }
pub fn enable_verbose_logging(&self) -> Result<(), CommandError> { pub fn enable_debug_logging(&self) -> Result<(), CommandError> {
self.reload_log_filter self.reload_log_filter
.modify(|filter| { .modify(|filter| {
*filter = tracing_subscriber::EnvFilter::builder() *filter = tracing_subscriber::EnvFilter::builder()
.with_default_directive(tracing::metadata::LevelFilter::DEBUG.into()) .with_default_directive(tracing::metadata::LevelFilter::DEBUG.into())
.from_env_lossy() .from_env_lossy()
}) })
.map_err(|err| internal_error_with_message("failed to enable verbose logging", err))?; .map_err(|err| internal_error_with_message("failed to enable debug logging", err))?;
tracing::info!("verbose logging enabled"); tracing::info!("debug logging enabled");
Ok(()) Ok(())
} }
} }
@ -2497,9 +2497,9 @@ pub struct GlobalArgs {
/// do that, but it is possible. /// do that, but it is possible.
#[arg(long, visible_alias = "at-op", global = true, default_value = "@")] #[arg(long, visible_alias = "at-op", global = true, default_value = "@")]
pub at_operation: String, pub at_operation: String,
/// Enable verbose logging /// Enable debug logging
#[arg(long, short = 'v', global = true)] #[arg(long, global = true)]
pub verbose: bool, pub debug: bool,
#[command(flatten)] #[command(flatten)]
pub early_args: EarlyArgs, pub early_args: EarlyArgs,
@ -2743,9 +2743,9 @@ pub fn parse_args(
.try_get_matches_from(string_args)?; .try_get_matches_from(string_args)?;
let args: Args = Args::from_arg_matches(&matches).unwrap(); let args: Args = Args::from_arg_matches(&matches).unwrap();
if args.global_args.verbose { if args.global_args.debug {
// TODO: set up verbose logging as early as possible // TODO: set up debug logging as early as possible
tracing_subscription.enable_verbose_logging()?; tracing_subscription.enable_debug_logging()?;
} }
Ok((matches, args)) Ok((matches, args))

View file

@ -116,9 +116,9 @@ pub enum ExternalToolError {
MergeArgsNotConfigured { tool_name: String }, MergeArgsNotConfigured { tool_name: String },
#[error("Error setting up temporary directory")] #[error("Error setting up temporary directory")]
SetUpDir(#[source] std::io::Error), SetUpDir(#[source] std::io::Error),
// TODO: Remove the "(run with --verbose to see the exact invocation)" // TODO: Remove the "(run with --debug to see the exact invocation)"
// from this and other errors. Print it as a hint but only if --verbose is *not* set. // from this and other errors. Print it as a hint but only if --debug is *not* set.
#[error("Error executing '{tool_binary}' (run with --verbose to see the exact invocation)")] #[error("Error executing '{tool_binary}' (run with --debug to see the exact invocation)")]
FailedToExecute { FailedToExecute {
tool_binary: String, tool_binary: String,
#[source] #[source]
@ -575,7 +575,7 @@ fn format_tool_aborted(exit_status: &ExitStatus) -> String {
.map(|c| c.to_string()) .map(|c| c.to_string())
.unwrap_or_else(|| "<unknown>".to_string()); .unwrap_or_else(|| "<unknown>".to_string());
format!( format!(
"Tool exited with a non-zero code (run with --verbose to see the exact invocation). Exit \ "Tool exited with a non-zero code (run with --debug to see the exact invocation). Exit \
code: {code}." code: {code}."
) )
} }

View file

@ -77,8 +77,8 @@ pub enum ConflictResolveError {
#[error("The conflict at {path:?} has {sides} sides. At most 2 sides are supported.")] #[error("The conflict at {path:?} has {sides} sides. At most 2 sides are supported.")]
ConflictTooComplicated { path: RepoPathBuf, sides: usize }, ConflictTooComplicated { path: RepoPathBuf, sides: usize },
#[error( #[error(
"The output file is either unchanged or empty after the editor quit (run with --verbose \ "The output file is either unchanged or empty after the editor quit (run with --debug to \
to see the exact invocation)." see the exact invocation)."
)] )]
EmptyOrUnchanged, EmptyOrUnchanged,
#[error("Backend error")] #[error("Backend error")]

View file

@ -154,7 +154,7 @@ repository.
* `--at-operation <AT_OPERATION>` — Operation to load the repo at * `--at-operation <AT_OPERATION>` — Operation to load the repo at
Default value: `@` Default value: `@`
* `-v`, `--verbose` — Enable verbose logging * `--debug` — Enable debug logging
Possible values: `true`, `false` Possible values: `true`, `false`

View file

@ -751,7 +751,7 @@ fn test_diff_external_tool() {
diff diff
"###); "###);
insta::assert_snapshot!(stderr, @r###" insta::assert_snapshot!(stderr, @r###"
Tool exited with a non-zero code (run with --verbose to see the exact invocation). Exit code: 1. Tool exited with a non-zero code (run with --debug to see the exact invocation). Exit code: 1.
"###); "###);
} }

View file

@ -51,7 +51,7 @@ fn test_diffedit() {
std::fs::write(&edit_script, "rm file2\0fail").unwrap(); std::fs::write(&edit_script, "rm file2\0fail").unwrap();
insta::assert_snapshot!(&test_env.jj_cmd_failure(&repo_path, &["diffedit"]), @r###" insta::assert_snapshot!(&test_env.jj_cmd_failure(&repo_path, &["diffedit"]), @r###"
Error: Failed to edit diff Error: Failed to edit diff
Caused by: Tool exited with a non-zero code (run with --verbose to see the exact invocation). Exit code: 1. Caused by: Tool exited with a non-zero code (run with --debug to see the exact invocation). Exit code: 1.
"###); "###);
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]); let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"
@ -395,7 +395,7 @@ fn test_diffedit_old_restore_interactive_tests() {
std::fs::write(&edit_script, "rm file2\0fail").unwrap(); std::fs::write(&edit_script, "rm file2\0fail").unwrap();
insta::assert_snapshot!(&test_env.jj_cmd_failure(&repo_path, &["diffedit", "--from", "@-"]), @r###" insta::assert_snapshot!(&test_env.jj_cmd_failure(&repo_path, &["diffedit", "--from", "@-"]), @r###"
Error: Failed to edit diff Error: Failed to edit diff
Caused by: Tool exited with a non-zero code (run with --verbose to see the exact invocation). Exit code: 1. Caused by: Tool exited with a non-zero code (run with --debug to see the exact invocation). Exit code: 1.
"###); "###);
let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]); let stdout = test_env.jj_cmd_success(&repo_path, &["diff", "-s"]);
insta::assert_snapshot!(stdout, @r###" insta::assert_snapshot!(stdout, @r###"

View file

@ -446,7 +446,7 @@ fn test_help() {
-R, --repository <REPOSITORY> Path to repository to operate on -R, --repository <REPOSITORY> Path to repository to operate on
--ignore-working-copy Don't snapshot the working copy, and don't update it --ignore-working-copy Don't snapshot the working copy, and don't update it
--at-operation <AT_OPERATION> Operation to load the repo at [default: @] [aliases: at-op] --at-operation <AT_OPERATION> Operation to load the repo at [default: @] [aliases: at-op]
-v, --verbose Enable verbose logging --debug Enable debug logging
--color <WHEN> When to colorize output (always, never, auto) --color <WHEN> When to colorize output (always, never, auto)
--no-pager Disable the pager --no-pager Disable the pager
--config-toml <TOML> Additional configuration options (can be repeated) --config-toml <TOML> Additional configuration options (can be repeated)
@ -454,22 +454,22 @@ fn test_help() {
} }
#[test] #[test]
fn test_verbose_logging_enabled() { fn test_debug_logging_enabled() {
// Test that the verbose flag enabled verbose logging // Test that the debug flag enabled debug logging
let test_env = TestEnvironment::default(); let test_env = TestEnvironment::default();
let (_stdout, stderr) = test_env.jj_cmd_ok(test_env.env_root(), &["version", "-v"]); let (_stdout, stderr) = test_env.jj_cmd_ok(test_env.env_root(), &["version", "--debug"]);
// Split the first log line into a timestamp and the rest. // Split the first log line into a timestamp and the rest.
// The timestamp is constant sized so this is a robust operation. // The timestamp is constant sized so this is a robust operation.
// Example timestamp: 2022-11-20T06:24:05.477703Z // Example timestamp: 2022-11-20T06:24:05.477703Z
let (_timestamp, log_line) = stderr let (_timestamp, log_line) = stderr
.lines() .lines()
.next() .next()
.expect("verbose logging on first line") .expect("debug logging on first line")
.split_at(36); .split_at(36);
// The log format is currently Pretty so we include the terminal markup. // The log format is currently Pretty so we include the terminal markup.
// Luckily, insta will print this in colour when reviewing. // Luckily, insta will print this in colour when reviewing.
insta::assert_snapshot!(log_line, @" INFO jj_cli::cli_util: verbose logging enabled"); insta::assert_snapshot!(log_line, @" INFO jj_cli::cli_util: debug logging enabled");
} }
fn strip_last_line(s: &str) -> &str { fn strip_last_line(s: &str) -> &str {

View file

@ -299,7 +299,7 @@ fn check_resolve_produces_input_file(
assert_eq!( assert_eq!(
&test_env.jj_cmd_failure(repo_path, &["resolve", "--config-toml", &merge_arg_config]), &test_env.jj_cmd_failure(repo_path, &["resolve", "--config-toml", &merge_arg_config]),
"Resolving conflicts in: file\nError: Failed to resolve conflicts\nCaused by: The output \ "Resolving conflicts in: file\nError: Failed to resolve conflicts\nCaused by: The output \
file is either unchanged or empty after the editor quit (run with --verbose to see the \ file is either unchanged or empty after the editor quit (run with --debug to see the \
exact invocation).\n" exact invocation).\n"
); );
} }