Class: Spade::CLI::Base
- Inherits:
-
Thor
- Object
- Thor
- Spade::CLI::Base
show all
- Includes:
- Thor::Actions
- Defined in:
- lib/spade/cli/base.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth) ⇒ Object
344
345
346
347
348
349
350
351
|
# File 'lib/spade/cli/base.rb', line 344
def method_missing(meth, *)
if File.exist?(meth.to_s)
ARGV.unshift("exec")
invoke :exec
else
super
end
end
|
Instance Method Details
#build ⇒ Object
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
# File 'lib/spade/cli/base.rb', line 241
def build
local = Spade::Local.new
if local.logged_in?
package = local.pack("package.json")
if package.errors.empty?
puts "Successfully built package: #{package.to_ext}"
else
failure_message = "Spade encountered the following problems building your package:"
package.errors.each do |error|
failure_message << "\n* #{error}"
end
abort failure_message
end
else
abort LOGIN_MESSAGE
end
end
|
#console ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/spade/cli/base.rb', line 25
def console
require 'readline'
shell = Spade::Shell.new
context(:with => shell) do |ctx|
shell.ctx = ctx
puts "help() for help. quit() to quit."
puts "Spade #{Spade::VERSION} (V8 #{V8::VERSION})"
puts "WORKING=#{options[:working]}" if options[:verbose]
trap("SIGINT") { puts "^C" }
repl ctx
end
end
|
#exec ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/spade/cli/base.rb', line 42
def exec(*)
exec_args = ARGV.dup
arg = exec_args.shift while arg != "exec" && !exec_args.empty?
filename = exec_args.shift
puts "Filename: #{filename}" if options[:verbose]
if filename
puts "Working: #{options[:working]}" if options[:verbose]
filename = File.expand_path filename, Dir.pwd
throw "#{filename} not found" unless File.exists?(filename)
fp = File.open filename
source = File.basename filename
rootdir = Spade.discover_root filename
caller_id = nil
if rootdir
json_path = File.join(rootdir, 'package.json')
if File.exist?(json_path)
package_json = JSON.parse(File.read(json_path))
caller_id = "#{package_json['name']}/main"
end
end
unless fp.readline =~ /^\#\!/
fp.rewind
end
if options[:verbose]
pos = fp.pos
puts fp.read
fp.pos = pos
end
else
fp = $stdin
source = '<stdin>'
rootdir = options[:working]
caller_id = nil
end
if options[:verbose]
puts "source: #{source}"
puts "rootdir: #{rootdir}"
puts "caller_id: #{caller_id}"
end
begin
context(:argv => exec_args, :rootdir => rootdir, :caller_id => caller_id) do |ctx|
ctx.eval(fp, source) end
rescue Interrupt => e
puts; exit
end
end
|
#install(*packages) ⇒ Object
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
|
# File 'lib/spade/cli/base.rb', line 126
def install(*packages)
report_arity_error("install") and return if packages.size.zero?
begin
packages.each do |package|
installed = Spade::Remote.new.install(package, options[:version], options[:prerelease])
installed.each do |spec|
say "Successfully installed #{spec.full_name}"
end
end
rescue Gem::InstallError => e
abort "Install error: #{e}"
rescue Gem::GemNotFoundException => e
abort "Can't find package #{e.name} #{e.version} available for install"
rescue Errno::EACCES, Gem::FilePermissionError => e
abort e.message
end
end
|
#installed(*packages) ⇒ Object
146
147
148
149
150
|
# File 'lib/spade/cli/base.rb', line 146
def installed(*packages)
local = Spade::Local.new
index = local.installed(packages)
print_specs(packages, index)
end
|
#list(*packages) ⇒ Object
228
229
230
231
232
|
# File 'lib/spade/cli/base.rb', line 228
def list(*packages)
remote = Spade::Remote.new
index = remote.list_packages(packages, options[:all], options[:prerelease])
print_specs(packages, index)
end
|
#login ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/spade/cli/base.rb', line 167
def login
highline = HighLine.new
say "Enter your Spade credentials."
begin
email = highline.ask "\nEmail:" do |q|
next unless STDIN.tty?
q.readline = true
end
password = highline.ask "\nPassword:" do |q|
next unless STDIN.tty?
q.echo = "*"
end
rescue Interrupt => ex
abort "Cancelled login."
end
say "\nLogging in as #{email}..."
if Spade::Remote.new.login(email, password)
say "Logged in!"
else
say "Incorrect email or password."
login
end
end
|
#new(name) ⇒ Object
235
236
237
238
|
# File 'lib/spade/cli/base.rb', line 235
def new(name)
ProjectGenerator.new(self,
name, File.expand_path(name)).run
end
|
#preview ⇒ Object
112
113
114
115
116
|
# File 'lib/spade/cli/base.rb', line 112
def preview
require 'spade/server'
trap("SIGINT") { Spade::Server.shutdown }
Spade::Server.run(options[:working], options[:port]);
end
|
#push(package) ⇒ Object
196
197
198
199
200
201
202
203
|
# File 'lib/spade/cli/base.rb', line 196
def push(package)
remote = Spade::Remote.new
if remote.logged_in?
say remote.push(package)
else
say LOGIN_MESSAGE
end
end
|
#uninstall(*packages) ⇒ Object
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/spade/cli/base.rb', line 153
def uninstall(*packages)
local = Spade::Local.new
if packages.size > 0
packages.each do |package|
if !local.uninstall(package)
abort %{No packages installed named "#{package}"}
end
end
else
report_arity_error('uninstall')
end
end
|
#unpack(*paths) ⇒ Object
261
262
263
264
265
266
267
268
269
270
271
272
273
|
# File 'lib/spade/cli/base.rb', line 261
def unpack(*paths)
local = Spade::Local.new
paths.each do |path|
begin
package = local.unpack(path, options[:target])
unpack_path = File.expand_path(File.join(Dir.pwd, options[:target], package.to_full_name))
puts "Unpacked spade into: #{unpack_path}"
rescue Errno::EACCES, Gem::FilePermissionError => ex
abort "There was a problem unpacking #{path}:\n#{ex.message}"
end
end
end
|
#update ⇒ Object
119
120
121
|
# File 'lib/spade/cli/base.rb', line 119
def update
Spade::Bundle.update(options[:working], :verbose => options[:verbose])
end
|
#yank(package) ⇒ Object
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
|
# File 'lib/spade/cli/base.rb', line 208
def yank(package)
if options[:version]
remote = Spade::Remote.new
if remote.logged_in?
if options[:undo]
say remote.unyank(package, options[:version])
else
say remote.yank(package, options[:version])
end
else
say LOGIN_MESSAGE
end
else
say "Version required"
end
end
|