Class: Commands::Extension

Inherits:
Object show all
Defined in:
lib/commands/extension.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExtension

Returns a new instance of Extension.



122
123
124
125
126
127
# File 'lib/commands/extension.rb', line 122

def initialize
  @environment = SpreeEnvironment.default
  @spree_root = SpreeEnvironment.default.root
  @script_name = File.basename($0) 
  @sources = []
end

Instance Attribute Details

#environmentObject

, :sources



121
122
123
# File 'lib/commands/extension.rb', line 121

def environment
  @environment
end

#script_nameObject (readonly)

, :sources



121
122
123
# File 'lib/commands/extension.rb', line 121

def script_name
  @script_name
end

Class Method Details

.parse!(args = ARGV) ⇒ Object



183
184
185
# File 'lib/commands/extension.rb', line 183

def self.parse!(args=ARGV)
  Extension.new.parse!(args)
end

Instance Method Details

#optionsObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/commands/extension.rb', line 134

def options
  OptionParser.new do |o|
    o.set_summary_indent('  ')
    o.banner =    "Usage: #{@script_name} [OPTIONS] command"
    o.define_head "Spree extension manager."
    
    o.separator ""        
    o.separator "GENERAL OPTIONS"
    
    o.on("-r", "--root=DIR", String,
         "Set an explicit Spree vendor/extensions directory.",
         "Default: #{@spree_root}") { |@spree_root| self.environment = SpreeEnvironment.new(@spree_root) }
    o.on("-v", "--verbose", "Turn on verbose output.") { |$verbose| }
    o.on("-h", "--help", "Show this help message.") { puts o; exit }
    
    o.separator ""
    o.separator "COMMANDS"
    
    o.separator "  install    Install extension(s) from known URLs."
    o.separator "  remove     Uninstall extensions."        
    o.separator ""
    o.separator "EXAMPLES"
    o.separator "  Install an extension from a git URL:"
    o.separator "    #{@script_name} install git://github.com/SomeGuy/my_awesome_extension.git\n"
  end
end

#parse!(args = ARGV) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/commands/extension.rb', line 161

def parse!(args=ARGV)
  general, sub = split_args(args)
  options.parse!(general)
  
  command = general.shift
  if command =~ /^(install|remove|update)$/
    command = Commands.const_get(command.capitalize).new(self)
    command.parse!(sub)
  else
    puts "Unknown command: #{command}"
    puts options
    exit 1
  end
end

#split_args(args) ⇒ Object



176
177
178
179
180
181
# File 'lib/commands/extension.rb', line 176

def split_args(args)
  left = []
  left << args.shift while args[0] and args[0] =~ /^-/
  left << args.shift if args[0]
  return [left, args]
end