Class: GitTree::ExecCommand

Inherits:
AbstractCommand show all
Defined in:
lib/commands/git_exec.rb

Constant Summary

Constants included from Logging

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractCommand

#setup

Methods included from Logging

#log, #log_stdout, verbosity, verbosity=

Constructor Details

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

Returns a new instance of ExecCommand.



11
12
13
14
15
16
17
# File 'lib/commands/git_exec.rb', line 11

def initialize(args = ARGV, options: {})
  $PROGRAM_NAME = 'git-exec'
  super
  # Allow walker and runner to be injected for testing
  @runner = @options.delete(:runner)
  @walker = @options.delete(:walker)
end

Instance Attribute Details

#runner=(value) ⇒ Object (writeonly)

Sets the attribute runner

Parameters:

  • value —

    the value to set the attribute runner to.



9
10
11
# File 'lib/commands/git_exec.rb', line 9

def runner=(value)
  @runner = value
end

#walker=(value) ⇒ Object (writeonly)

Sets the attribute walker

Parameters:

  • value —

    the value to set the attribute walker to.



9
10
11
# File 'lib/commands/git_exec.rb', line 9

def walker=(value)
  @walker = value
end

Instance Method Details

#run ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/commands/git_exec.rb', line 19

def run
  setup
  return help('At least one root and a command must be specified.') if @args.length < 2

  @runner ||= CommandRunner.new
  # The last argument is the command to execute, the rest are roots for the walker.
  @walker ||= GitTreeWalker.new(@args[0..-2], options: @options)

  command = @args.last
  @walker.process do |dir, _thread_id, _walker|
    execute_and_log(dir, command)
  end
end