class Flash::Command::Run
Public Class Methods
new(command, group)
click to toggle source
# File lib/flash/command/run.rb, line 6 def initialize(command, group) @command = command @group = group end
Public Instance Methods
execute()
click to toggle source
# File lib/flash/command/run.rb, line 11 def execute raise(ArgumentError, 'Missing required command and group parameters.') unless @command && @group unknown_group_and_exit(@group) unless valid_group?(@group) run_command_in_group(@command, @group) end
Private Instance Methods
aliases()
click to toggle source
# File lib/flash/command/run.rb, line 54 def aliases config['aliases'] || {} end
commands(alias_or_command)
click to toggle source
# File lib/flash/command/run.rb, line 49 def commands(alias_or_command) commands = aliases[alias_or_command] || alias_or_command commands.split(';').map(&:strip) end
new_color()
click to toggle source
# File lib/flash/command/run.rb, line 71 def new_color rand((1..22)) * 10 + 2 end
project_dir(project)
click to toggle source
# File lib/flash/command/run.rb, line 75 def project_dir(project) "#{ Dir.pwd }/#{ project }" end
projects(group)
click to toggle source
# File lib/flash/command/run.rb, line 36 def projects(group) config[group] end
prompt(message, options)
click to toggle source
# File lib/flash/command/run.rb, line 58 def prompt(message, options) color = options[:color] project = options[:project] say("#{ project }> #{ message }", color) end
run(command, options = {})
click to toggle source
# File lib/flash/command/run.rb, line 40 def run(command, options = {}) verbose = options[:verbose].nil? ? true : options[:verbose] color = options[:color] project = options[:project] prompt(command, color: color, project: project) if verbose system("cd #{ project_dir(project) } ; #{ command }") end
run_command_in_group(command, group)
click to toggle source
# File lib/flash/command/run.rb, line 25 def run_command_in_group(command, group) projects(group).each do |project| color = new_color system("cd #{ project_dir(project) }") commands(command).each { |cmd| run(cmd, color: color, project: project) } say('', color) end end
say(stuff, color)
click to toggle source
# File lib/flash/command/run.rb, line 65 def say(stuff, color) prefix = "\e[38;5;#{ color }m" suffix = "\e[0m" system "echo '#{ prefix }#{ stuff }#{ suffix }'" end
unknown_group_and_exit(group)
click to toggle source
# File lib/flash/command/run.rb, line 20 def unknown_group_and_exit(group) puts "Unknown group \"#{group}\" in .flash.yml config." exit 1 end