Class: GitTree::AbstractCommand

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/commands/abstract_command.rb

Overview

Abstract base class for all git-tree commands. It handles common option parsing for verbosity and help.

Constant Summary

Constants included from Logging

Logging::DEBUG, Logging::NORMAL, Logging::QUIET, Logging::VERBOSE

Class Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log, #log_stdout, verbosity, verbosity=

Constructor Details

#initialize(args = ARGV, options: {}) ⇒ AbstractCommand

Returns a new instance of AbstractCommand.



15
16
17
18
19
20
21
22
# File 'lib/commands/abstract_command.rb', line 15

def initialize(args = ARGV, options: {})
  @args = args
  @options = options
  @config = GitTree::Config.new
  # Set initial verbosity from config before anything else happens.
  # log Logging::VERBOSE, "AbstractCommand#initialize: Setting initial verbosity from config to: #{@config.verbosity}"
  Logging.verbosity = @config.verbosity
end

Class Attribute Details

.allow_empty_argsObject

Returns the value of attribute allow_empty_args.



12
13
14
# File 'lib/commands/abstract_command.rb', line 12

def allow_empty_args
  @allow_empty_args
end

Instance Method Details

#setupObject

Common setup for all commands. Parses options and sets initial verbosity.



26
27
28
29
30
# File 'lib/commands/abstract_command.rb', line 26

def setup
  # CLI options can override the config verbosity.
  log Logging::VERBOSE, "AbstractCommand#setup: verbosity before parsing options: #{Logging.verbosity}"
  parse_options(@args)
end