Class: MGit::ForEachCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/mgit/commands/foreach.rb

Instance Method Summary collapse

Methods inherited from Command

#check_arity, execute, instance_each, list, load_commands, register_alias, register_command

Methods included from Output

#perror, #pinfo, #psystem, #ptable, #pwarn

Instance Method Details

#arityObject



17
18
19
# File 'lib/mgit/commands/foreach.rb', line 17

def arity
  [1, nil]
end

#descriptionObject



25
26
27
# File 'lib/mgit/commands/foreach.rb', line 25

def description
  'execute a command for each repository'
end

#execute(args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/mgit/commands/foreach.rb', line 3

def execute(args)
  command = args.join(' ')

  Registry.each do |repo|
    pinfo "Executing command in repository #{repo.name}..."

    sc = System::run(command, { :chdir => repo.path, :print_stdout => true, :print_stderr => true })

    if !sc.success? && !agree("Executing command '#{command}' in repository '#{repo.name}' failed. Would you like to continue anyway?".red)
      break
    end
  end
end

#usageObject



21
22
23
# File 'lib/mgit/commands/foreach.rb', line 21

def usage
  'foreach <command...>'
end