Class Limelight::Commands::Command
In: lib/limelight/commands/command.rb
Parent: Object

The base class for all limelight commands. The following is a list of them all.

 Usage: limelight <command> [options] [params]
   commands:
   create         Creates the directories and files for a production and/or scene.
   freeze         freeze a gem into a production.
   open           Open a limelight production.
   pack           Pack a limelight production into a .llp file.

Methods

Attributes

alias  [RW] 
print_backtrace  [RW]  Flag. The backtrace on parse errors will be printed if true.

Public Class methods

Abstract class level methof that returns a string description of the command. Derivatives should override this class level method.

[Source]

    # File lib/limelight/commands/command.rb, line 67
67:         def description
68:           return "Default Command description"
69:         end

Sets the alias for the derivative command and installs it in the command listing. All derivative much call this method exactly once.

[Source]

    # File lib/limelight/commands/command.rb, line 58
58:         def install_as(name)
59:           raise "Command already installed: #{name}." if LISTING[name]
60:           self.alias = name
61:           LISTING[name] = self
62:         end

Public Instance methods

Parse the arguments. All options will be parsed first, then parse_remainder will be called on remaining args. Derivative should not override this method.

[Source]

     # File lib/limelight/commands/command.rb, line 93
 93:       def parse(args)         
 94:         begin
 95:           remainder = options_spec.parse(args)
 96:           parse_remainder(remainder)
 97:         rescue SystemExit => e
 98:           raise e
 99:         rescue Exception => e
100:           @has_parse_error = true
101:           parse_error e
102:         end
103:       end

Runs the command. This is TemplateMethod. It will first parse the arguments, then require files, and finally process the command. Derivative should not override this method.

[Source]

    # File lib/limelight/commands/command.rb, line 80
80:       def run(args)
81:         parse(args)
82:         do_requires
83:         begin
84:           process if !@has_parse_error
85:         rescue SystemExit
86:           #okay
87:         end
88:       end

Protected Instance methods

Abstract method to define the command line options in the OptionParser. Derivative should override this method if they offer command line options

[Source]

     # File lib/limelight/commands/command.rb, line 154
154:       def build_options(spec)
155:         #override me
156:       end

Abstract method to require any files needed for processing the command. Derivative should override this method if they need to require any files.

[Source]

     # File lib/limelight/commands/command.rb, line 147
147:       def do_requires
148:         #override me
149:       end

Retreives the OptionParser instance for this command. It will create it if it doesn‘t exist.

[Source]

     # File lib/limelight/commands/command.rb, line 135
135:       def options_spec
136:         if @options_spec.nil?
137:           @options_spec = OptionParser.new
138:           @options_spec.on("-h", "--help", "Prints this usage summary.") { usage; exit 0 }
139:           build_options(@options_spec)
140:         end
141:         return @options_spec
142:       end

Prints an exception that occurs while parsing the arguments. The usages summary will follow.

[Source]

     # File lib/limelight/commands/command.rb, line 113
113:       def parse_error(exception = nil)
114:         if exception
115:           puts ""
116:           puts "!!! #{exception}"
117:           puts exception.backtrace if @print_backtrace
118:         end
119:         usage
120:         exit -1
121:       end

Abstract method to parse command line paramters. Parameter are those command line arguments listed after the options. Derivatives should override this method they take command line paramters.

[Source]

     # File lib/limelight/commands/command.rb, line 161
161:       def parse_remainder(args)
162:         #override me
163:       end

Prints the usage summary for a command.

[Source]

     # File lib/limelight/commands/command.rb, line 125
125:       def usage
126:         puts ""
127:         puts "Usage: limelight #{self.class.alias} #{parameter_description}"
128:         puts "    #{self.class.description}"
129:         puts "    options:"
130:         puts options_spec.summarize
131:       end

[Validate]