Class: Gb::Forall

Inherits:
SubCommand show all
Defined in:
lib/commands/forall.rb

Instance Attribute Summary

Attributes inherited from SubCommand

#gb_config

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SubCommand

#check_uncommit, #run, #save_workspace_config, #workspace_config

Methods inherited from Command

#error, handle_exception, #info, report_error, run

Constructor Details

#initialize(argv) ⇒ Forall

Returns a new instance of Forall.



20
21
22
23
# File 'lib/commands/forall.rb', line 20

def initialize(argv)
  @command = argv.option('c')
  super
end

Class Method Details

.optionsObject



14
15
16
17
18
# File 'lib/commands/forall.rb', line 14

def self.options
  [
      ["--c", "执行命令"],
  ].concat(super)
end

Instance Method Details

#run_in_configObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/commands/forall.rb', line 32

def run_in_config

  self.gb_config.projects.each do |project|
    project_path = File.expand_path(project.name, './')

    if File.exist?(project_path)
      info "'#{@command}' For project '#{project.name}'..."
      g = Git.open(project_path)
      Dir.chdir(project_path) do
        result = `#{@command}`
        puts result
      end
      puts
    else
      error "please run 'gb init first."
      break
    end
  end
end

#validate!Object



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

def validate!
  super
  if @command.nil?
    help! 'command is required.'
  end
end