Make --debug output a bit quieter by default

The `Formulary` and `system_command` debug output is incredibly verbose
by default and this is pretty annoying when all you want is to get
better backtraces when there's an error.

Instead, let's require `--verbose` and `--debug` for the noisiest output
message types.
This commit is contained in:
Mike McQuaid 2025-07-25 17:14:46 +01:00
parent 00afc6b433
commit 312f046302
No known key found for this signature in database
4 changed files with 9 additions and 7 deletions

View File

@ -622,7 +622,7 @@ module Cask
NullLoader, NullLoader,
].each do |loader_class| ].each do |loader_class|
if (loader = loader_class.try_new(ref, warn:)) if (loader = loader_class.try_new(ref, warn:))
$stderr.puts "#{$PROGRAM_NAME} (#{loader.class}): loading #{ref}" if debug? $stderr.puts "#{$PROGRAM_NAME} (#{loader.class}): loading #{ref}" if verbose? && debug?
return loader return loader
end end
end end

View File

@ -1159,7 +1159,7 @@ module Formulary
NullLoader, NullLoader,
].each do |loader_class| ].each do |loader_class|
if (loader = loader_class.try_new(ref, from:, warn:)) if (loader = loader_class.try_new(ref, from:, warn:))
$stderr.puts "#{$PROGRAM_NAME} (#{loader_class}): loading #{ref}" if debug? $stderr.puts "#{$PROGRAM_NAME} (#{loader_class}): loading #{ref}" if verbose? && debug?
return loader return loader
end end
end end

View File

@ -44,7 +44,7 @@ class SystemCommand
sig { returns(SystemCommand::Result) } sig { returns(SystemCommand::Result) }
def run! def run!
$stderr.puts redact_secrets(command.shelljoin.gsub('\=', "="), @secrets) if verbose? || debug? $stderr.puts redact_secrets(command.shelljoin.gsub('\=', "="), @secrets) if verbose? && debug?
@output = [] @output = []
@ -104,7 +104,7 @@ class SystemCommand
print_stdout: false, print_stdout: false,
print_stderr: true, print_stderr: true,
debug: nil, debug: nil,
verbose: false, verbose: T.unsafe(nil),
secrets: [], secrets: [],
chdir: T.unsafe(nil), chdir: T.unsafe(nil),
reset_uid: false, reset_uid: false,

View File

@ -193,7 +193,7 @@ RSpec.describe SystemCommand do
.and not_to_output.to_stdout .and not_to_output.to_stdout
end end
context "when `debug?` is true" do context "when `verbose?` and `debug?` are true" do
include Context include Context
let(:options) do let(:options) do
@ -203,8 +203,8 @@ RSpec.describe SystemCommand do
] } ] }
end end
it "echoes the command and all output to STDERR when `debug?` is true" do it "echoes the command and all output to STDERR" do
with_context debug: true do with_context(verbose: true, debug: true) do
expect { described_class.run(command, **options) } expect { described_class.run(command, **options) }
.to output(/\A.*#{Regexp.escape(command)}.*\n1\n2\n3\n4\n5\n6\n\Z/).to_stderr .to output(/\A.*#{Regexp.escape(command)}.*\n1\n2\n3\n4\n5\n6\n\Z/).to_stderr
.and not_to_output.to_stdout .and not_to_output.to_stdout
@ -323,6 +323,7 @@ RSpec.describe SystemCommand do
described_class.run! "curl", described_class.run! "curl",
args: %w[--user username:hunter2], args: %w[--user username:hunter2],
verbose: true, verbose: true,
debug: true,
secrets: %w[hunter2] secrets: %w[hunter2]
end.to raise_error(ErrorDuringExecution, redacted_msg).and output(redacted_msg).to_stderr end.to raise_error(ErrorDuringExecution, redacted_msg).and output(redacted_msg).to_stderr
end end
@ -333,6 +334,7 @@ RSpec.describe SystemCommand do
ENV["PASSWORD"] = "hunter2" ENV["PASSWORD"] = "hunter2"
described_class.run! "curl", described_class.run! "curl",
args: %w[--user username:hunter2], args: %w[--user username:hunter2],
debug: true,
verbose: true verbose: true
end.to raise_error(ErrorDuringExecution, redacted_msg).and output(redacted_msg).to_stderr end.to raise_error(ErrorDuringExecution, redacted_msg).and output(redacted_msg).to_stderr
end end