Skip to content

Commit

Permalink
cli: rename --verbose to --debug to better fit what it does
Browse files Browse the repository at this point in the history
  • Loading branch information
poliorcetics committed Feb 18, 2024
1 parent 06d67f0 commit c66ac29
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

* `--verbose/-v` is now `--debug` (no short option since it's not intended to be used often)

### Fixed bugs

* On Windows, symlinks in the repo are now materialized as regular files in the
Expand Down
18 changes: 9 additions & 9 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
.modify(|filter| {
*filter = tracing_subscriber::EnvFilter::builder()
.with_default_directive(tracing::metadata::LevelFilter::DEBUG.into())
.from_env_lossy()
})
.map_err(|err| internal_error_with_message("failed to enable verbose logging", err))?;
tracing::info!("verbose logging enabled");
.map_err(|err| internal_error_with_message("failed to enable debug logging", err))?;
tracing::info!("debug logging enabled");
Ok(())
}
}
Expand Down Expand Up @@ -2497,9 +2497,9 @@ pub struct GlobalArgs {
/// do that, but it is possible.
#[arg(long, visible_alias = "at-op", global = true, default_value = "@")]
pub at_operation: String,
/// Enable verbose logging
#[arg(long, short = 'v', global = true)]
pub verbose: bool,
/// Enable debug logging
#[arg(long, global = true)]
pub debug: bool,

#[command(flatten)]
pub early_args: EarlyArgs,
Expand Down Expand Up @@ -2743,9 +2743,9 @@ pub fn parse_args(
.try_get_matches_from(string_args)?;

let args: Args = Args::from_arg_matches(&matches).unwrap();
if args.global_args.verbose {
// TODO: set up verbose logging as early as possible
tracing_subscription.enable_verbose_logging()?;
if args.global_args.debug {
// TODO: set up debug logging as early as possible
tracing_subscription.enable_debug_logging()?;
}

Ok((matches, args))
Expand Down
8 changes: 4 additions & 4 deletions cli/src/merge_tools/external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ pub enum ExternalToolError {
MergeArgsNotConfigured { tool_name: String },
#[error("Error setting up temporary directory")]
SetUpDir(#[source] std::io::Error),
// TODO: Remove the "(run with --verbose to see the exact invocation)"
// from this and other errors. Print it as a hint but only if --verbose is *not* set.
#[error("Error executing '{tool_binary}' (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 --debug is *not* set.
#[error("Error executing '{tool_binary}' (run with --debug to see the exact invocation)")]
FailedToExecute {
tool_binary: String,
#[source]
Expand Down Expand Up @@ -575,7 +575,7 @@ fn format_tool_aborted(exit_status: &ExitStatus) -> String {
.map(|c| c.to_string())
.unwrap_or_else(|| "<unknown>".to_string());
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}."
)
}
Expand Down
2 changes: 1 addition & 1 deletion cli/src/merge_tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub enum ConflictResolveError {
#[error("The conflict at {path:?} has {sides} sides. At most 2 sides are supported.")]
ConflictTooComplicated { path: RepoPathBuf, sides: usize },
#[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 see the exact invocation)."
)]
EmptyOrUnchanged,
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ repository.
* `--at-operation <AT_OPERATION>` — Operation to load the repo at
Default value: `@`
* `-v`, `--verbose` — Enable verbose logging
* `--debug` — Enable debug logging
Possible values: `true`, `false`
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_diff_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ fn test_diff_external_tool() {
diff
"###);
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.
"###);
}

Expand Down
4 changes: 2 additions & 2 deletions cli/tests/test_diffedit_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn test_diffedit() {
std::fs::write(&edit_script, "rm file2\0fail").unwrap();
insta::assert_snapshot!(&test_env.jj_cmd_failure(&repo_path, &["diffedit"]), @r###"
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"]);
insta::assert_snapshot!(stdout, @r###"
Expand Down Expand Up @@ -395,7 +395,7 @@ fn test_diffedit_old_restore_interactive_tests() {
std::fs::write(&edit_script, "rm file2\0fail").unwrap();
insta::assert_snapshot!(&test_env.jj_cmd_failure(&repo_path, &["diffedit", "--from", "@-"]), @r###"
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"]);
insta::assert_snapshot!(stdout, @r###"
Expand Down
12 changes: 6 additions & 6 deletions cli/tests/test_global_opts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,30 +446,30 @@ fn test_help() {
-R, --repository <REPOSITORY> Path to repository to operate on
--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]
-v, --verbose Enable verbose logging
--debug Enable debug logging
--color <WHEN> When to colorize output (always, never, auto)
--no-pager Disable the pager
--config-toml <TOML> Additional configuration options (can be repeated)
"###);
}

#[test]
fn test_verbose_logging_enabled() {
// Test that the verbose flag enabled verbose logging
fn test_debug_logging_enabled() {
// Test that the debug flag enabled debug logging
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.
// The timestamp is constant sized so this is a robust operation.
// Example timestamp: 2022-11-20T06:24:05.477703Z
let (_timestamp, log_line) = stderr
.lines()
.next()
.expect("verbose logging on first line")
.expect("debug logging on first line")
.split_at(36);
// The log format is currently Pretty so we include the terminal markup.
// Luckily, insta will print this in colour when reviewing.
insta::assert_snapshot!(log_line, @"[32m INFO[0m [2mjj_cli::cli_util[0m[2m:[0m verbose logging enabled");
insta::assert_snapshot!(log_line, @"[32m INFO[0m [2mjj_cli::cli_util[0m[2m:[0m debug logging enabled");
}

fn strip_last_line(s: &str) -> &str {
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/test_resolve_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ fn check_resolve_produces_input_file(
assert_eq!(
&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 \
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"
);
}
Expand Down

0 comments on commit c66ac29

Please sign in to comment.