Class: Spade::Packager::CLI::Base

Inherits:
Thor
  • Object
show all
Defined in:
lib/spade/packager/cli/base.rb

Instance Method Summary collapse

Instance Method Details

#buildObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/spade/packager/cli/base.rb', line 136

def build
  local = Spade::Packager::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

#install(*packages) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/spade/packager/cli/base.rb', line 21

def install(*packages)
  report_arity_error("install") and return if packages.size.zero?

  begin
    packages.each do |package|
      installed = Spade::Packager::Remote.new.install(package, options[:version], options[:prerelease])
      installed.each do |spec|
        say "Successfully installed #{spec.full_name}"
      end
    end
  rescue LibGems::InstallError => e
    abort "Install error: #{e}"
  rescue LibGems::GemNotFoundException => e
    abort "Can't find package #{e.name} #{e.version} available for install"
  rescue Errno::EACCES, LibGems::FilePermissionError => e
    abort e.message
  end
end

#installed(*packages) ⇒ Object



41
42
43
44
45
# File 'lib/spade/packager/cli/base.rb', line 41

def installed(*packages)
  local = Spade::Packager::Local.new
  index = local.installed(packages)
  print_specs(packages, index)
end

#list(*packages) ⇒ Object



123
124
125
126
127
# File 'lib/spade/packager/cli/base.rb', line 123

def list(*packages)
  remote = Spade::Packager::Remote.new
  index  = remote.list_packages(packages, options[:all], options[:prerelease])
  print_specs(packages, index)
end

#loginObject



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
# File 'lib/spade/packager/cli/base.rb', line 62

def 
  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::Packager::Remote.new.(email, password)
    say "Logged in!"
  else
    say "Incorrect email or password."
    
  end
end

#new(name) ⇒ Object



130
131
132
133
# File 'lib/spade/packager/cli/base.rb', line 130

def new(name)
  ProjectGenerator.new(self,
    name, File.expand_path(name)).run
end

#push(package) ⇒ Object



91
92
93
94
95
96
97
98
# File 'lib/spade/packager/cli/base.rb', line 91

def push(package)
  remote = Spade::Packager::Remote.new
  if remote.logged_in?
    say remote.push(package)
  else
    say LOGIN_MESSAGE
  end
end

#uninstall(*packages) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/spade/packager/cli/base.rb', line 48

def uninstall(*packages)
  local = Spade::Packager::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



156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/spade/packager/cli/base.rb', line 156

def unpack(*paths)
  local = Spade::Packager::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, LibGems::FilePermissionError => ex
      abort "There was a problem unpacking #{path}:\n#{ex.message}"
    end
  end
end

#yank(package) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/spade/packager/cli/base.rb', line 103

def yank(package)
  if options[:version]
    remote = Spade::Packager::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