Class: Samus::Command
- Inherits:
-
Object
- Object
- Samus::Command
- Defined in:
- lib/samus/command.rb
Class Attribute Summary collapse
-
.command_paths ⇒ Object
readonly
Returns the value of attribute command_paths.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#stage ⇒ Object
readonly
Returns the value of attribute stage.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #help_text ⇒ Object
-
#initialize(stage, name) ⇒ Command
constructor
A new instance of Command.
- #log_command(env = {}, arguments = []) ⇒ Object
- #run(opts = {}) ⇒ Object
- #show_help ⇒ Object
Constructor Details
#initialize(stage, name) ⇒ Command
Returns a new instance of Command.
47 48 49 50 51 |
# File 'lib/samus/command.rb', line 47 def initialize(stage, name) @name = name @stage = stage load_full_path end |
Class Attribute Details
.command_paths ⇒ Object (readonly)
Returns the value of attribute command_paths.
4 5 6 |
# File 'lib/samus/command.rb', line 4 def command_paths @command_paths end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
45 46 47 |
# File 'lib/samus/command.rb', line 45 def name @name end |
#stage ⇒ Object (readonly)
Returns the value of attribute stage.
45 46 47 |
# File 'lib/samus/command.rb', line 45 def stage @stage end |
Class Method Details
.list_commands(stage = nil) ⇒ Object
6 7 8 |
# File 'lib/samus/command.rb', line 6 def list_commands(stage = nil) display_commands(collect_commands(stage)) end |
Instance Method Details
#<=>(other) ⇒ Object
85 86 87 |
# File 'lib/samus/command.rb', line 85 def <=>(other) name <=> other.name end |
#help_text ⇒ Object
59 60 61 |
# File 'lib/samus/command.rb', line 59 def help_text @help_text ||= File.exist?(help_path) ? File.read(help_path) : '' end |
#log_command(env = {}, arguments = []) ⇒ Object
63 64 65 66 67 |
# File 'lib/samus/command.rb', line 63 def log_command(env = {}, arguments = []) e = env.map { |k, v| k =~ /^(AWS|__)/ ? nil : "#{k}=#{v.inspect}" }.compact.join(' ') e += ' ' unless e.empty? puts('[C] ' + e + name + (arguments ? ' ' + arguments.join(' ') : '')) end |
#run(opts = {}) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/samus/command.rb', line 69 def run(opts = {}) env = (opts[:arguments] || {}).each_with_object({}) { |(k, v), h| h["_#{k.upcase}"] = v; } arguments = opts[:files] || [] dry_run = opts[:dry_run] || false allow_fail = opts[:allow_fail] || false pwd = opts[:pwd] log_command(env, arguments) return if dry_run exec_in_dir(pwd) do system(env, exe_type + @full_path + ' ' + (arguments ? arguments.join(' ') : '')) end report_error($?, allow_fail) end |
#show_help ⇒ Object
53 54 55 56 57 |
# File 'lib/samus/command.rb', line 53 def show_help puts "#{stage.capitalize} Command: #{name}" puts '' puts help_text end |