Class: RubyYacht::Runner::Help

Inherits:
Command
  • Object
show all
Defined in:
lib/ruby_yacht/runner/help.rb

Overview

This command provides help information about other commands.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

#backtick, #default_project, #docker, #get_machine_info, #log, #project_named, #projects, short_script_name, #system

Instance Attribute Details

#commandObject

The command that we are getting help in.


13
14
15
# File 'lib/ruby_yacht/runner/help.rb', line 13

def command
  @command
end

Class Method Details

.commandObject

The name of the command.


5
# File 'lib/ruby_yacht/runner/help.rb', line 5

def self.command; 'help'; end

.descriptionObject

The short description of the command.


8
9
10
# File 'lib/ruby_yacht/runner/help.rb', line 8

def self.description
  "Get information on available commands"
end

Instance Method Details

#option_parserObject

This method gets the command-line options for the command.


16
17
18
19
20
# File 'lib/ruby_yacht/runner/help.rb', line 16

def option_parser
  OptionParser.new do |options|
    options.banner = "Usage: #{Command.short_script_name} help [command]\n\n#{self.class.description}"
  end
end

#parse_positional_arguments(arguments) ⇒ Object

This method extracts arguments from the command line.

Parameters

  • arguments: Array The command line arguments.

27
28
29
# File 'lib/ruby_yacht/runner/help.rb', line 27

def parse_positional_arguments(arguments)
  self.command = arguments.shift
end

#runObject

This method runs the logic for the command.


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruby_yacht/runner/help.rb', line 32

def run
  if self.command
    RubyYacht::Runner.commands.each do |command|
      if command.command == self.command
        log command.new.option_parser.to_s
        return true
      end
    end

    log "Command not available: #{self.command}"
    log "Run #{Command.short_script_name} help for more options"
    return false
  end

  log "Available commands: \n\n"
  RubyYacht::Runner.commands.each do |command|
    log "#{command.name}: #{command.description}"
  end

  log "\nRun #{Command.short_script_name} help [command] for more information on a command"
  true
end