Class: Commands::Extension
Instance Attribute Summary collapse
-
#environment ⇒ Object
, :sources.
-
#script_name ⇒ Object
readonly
, :sources.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Extension
constructor
A new instance of Extension.
- #options ⇒ Object
- #parse!(args = ARGV) ⇒ Object
- #split_args(args) ⇒ Object
Constructor Details
#initialize ⇒ Extension
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
#environment ⇒ Object
, :sources
121 122 123 |
# File 'lib/commands/extension.rb', line 121 def environment @environment end |
#script_name ⇒ Object (readonly)
, :sources
121 122 123 |
# File 'lib/commands/extension.rb', line 121 def script_name @script_name end |
Class Method Details
Instance Method Details
#options ⇒ Object
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 OptionParser.new do |o| o.set_summary_indent(' ') o. = "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) .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 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 |