Add quiet mode

Only log errors
This commit is contained in:
David Heinemeier Hansson
2023-02-01 14:10:51 +01:00
parent cdd77445d0
commit f06d639583
3 changed files with 14 additions and 9 deletions

View File

@@ -8,6 +8,7 @@ module Mrsk::Cli
def self.exit_on_failure?() true end
class_option :verbose, type: :boolean, aliases: "-v", desc: "Detailed logging"
class_option :quiet, type: :boolean, aliases: "-q", desc: "Minimal logging"
class_option :version, desc: "Run commands against a specific app version"
@@ -35,8 +36,12 @@ module Mrsk::Cli
commander.specific_primary! if options[:primary]
if options[:verbose]
commander.verbose = true
ENV["VERBOSE"] = "1" # For backtraces via cli/start
ENV["VERBOSE"] = "1" # For backtraces via cli/start
commander.verbosity = :debug
end
if options[:quiet]
commander.verbosity = :error
end
end
end

View File

@@ -13,13 +13,13 @@ class Mrsk::Cli::Build < Mrsk::Cli::Base
run_locally do
begin
MRSK.verbosity(:debug) { execute *MRSK.builder.push }
MRSK.with_verbosity(:debug) { execute *MRSK.builder.push }
rescue SSHKit::Command::Failed => e
if e.message =~ /(no builder)|(no such file or directory)/
error "Missing compatible builder, so creating a new one first"
if cli.create
MRSK.verbosity(:debug) { execute *MRSK.builder.push }
MRSK.with_verbosity(:debug) { execute *MRSK.builder.push }
end
else
raise

View File

@@ -9,10 +9,10 @@ require "mrsk/commands/traefik"
require "mrsk/commands/registry"
class Mrsk::Commander
attr_accessor :config_file, :destination, :verbose, :version
attr_accessor :config_file, :destination, :verbosity, :version
def initialize(config_file: nil, destination: nil, verbose: false)
@config_file, @destination, @verbose = config_file, destination, verbose
def initialize(config_file: nil, destination: nil, verbosity: :info)
@config_file, @destination, @verbosity = config_file, destination, verbosity
end
def config
@@ -78,7 +78,7 @@ class Mrsk::Commander
end
def verbosity(level)
def with_verbosity(level)
old_level = SSHKit.config.output_verbosity
SSHKit.config.output_verbosity = level
yield
@@ -95,6 +95,6 @@ class Mrsk::Commander
def configure_sshkit_with(config)
SSHKit::Backend::Netssh.configure { |ssh| ssh.ssh_options = config.ssh_options }
SSHKit.config.command_map[:docker] = "docker" # No need to use /usr/bin/env, just clogs up the logs
SSHKit.config.output_verbosity = :debug if verbose
SSHKit.config.output_verbosity = verbosity
end
end