Class: Pebbles::Command::Apps

Inherits:
Base
  • Object
show all
Defined in:
lib/pebbles/command/apps.rb

Overview

manage apps (create, destroy)

Instance Attribute Summary

Attributes inherited from Base

#args, #options

Instance Method Summary collapse

Methods inherited from Base

#api, #app, #initialize, namespace

Methods included from Helpers

#action, #ask, #confirm_command, #create_git_remote, #debug, #debugging?, #display, #error, error_with_failure, error_with_failure=, #flatten_hash, #format_bytes, #format_error, #format_with_bang, #git, #has_git?, #has_git_remote?, #has_http_git_entry_in_netrc, #home_directory, #hputs, #json_decode, #launchy, #line_formatter, #longest, #output_with_bang, #running_on_a_mac?, #running_on_windows?, #styled_array, #styled_error, #styled_hash, #styled_header, #update_git_remote, #with_tty

Constructor Details

This class inherits a constructor from Pebbles::Command::Base

Instance Method Details

#createObject

apps:create [NAME]

create a new app

--addons ADDONS        # a comma-delimited list of addons to install

-b, –buildpack BUILDPACK # a buildpack url to use for this app -n, –no-remote # don’t create a git remote -r, –remote REMOTE # the git remote to create, default “pebbles”

--ssh-git              # Use SSH git protocol
--http-git             # HIDDEN: Use HTTP git protocol

Examples:

$ pebbles apps:create Creating floating-dragon-42… done, stack is cedar floating-dragon-42.pebblesinspace.com/ | git.pebblesinspace.com/floating-dragon-42.git

# specify a name $ pebbles apps:create example Creating example… done, stack is cedar example.pebblesinspace.com/ | git.pebblesinspace.com/example.git

# create a staging app $ pebbles apps:create example-staging –remote staging



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
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
160
161
# File 'lib/pebbles/command/apps.rb', line 119

def create
  name    = shift_argument || options[:app] || ENV['PEBBLES_APP']
  validate_arguments!

  params = {
    "name" => name,
  }

  info = api.post_app(params).body

  begin
    action("Creating #{info['name']}") do
      if info['create_status'] == 'creating'
        Timeout::timeout(options[:timeout].to_i) do
          loop do
            break if api.get_app(info['name']).body['create_status'] == 'complete'
            sleep 1
          end
        end
      end
    end

    # (options[:addons] || "").split(",").each do |addon|
    #   addon.strip!
    #   action("Adding #{addon} to #{info["name"]}") do
    #     api.post_addon(info["name"], addon)
    #   end
    # end

    if buildpack = options[:buildpack]
      api.put_config_vars(info["name"], "BUILDPACK_URL" => buildpack)
      display("BUILDPACK_URL=#{buildpack}")
    end

    hputs([ info["web_url"], git_url(info['name']) ].join(" | "))
  rescue Timeout::Error
    hputs("Timed Out! Run `pebbles status` to check for known platform issues.")
  end

  unless options[:no_remote].is_a? FalseClass
    create_git_remote(options[:remote] || "pebbles", git_url(info['name']))
  end
end

#destroyObject

apps:destroy –app APP

permanently destroy an app

Example:

$ pebbles apps:destroy -a example –confirm example Destroying example (including all add-ons)… done



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# File 'lib/pebbles/command/apps.rb', line 174

def destroy
  @app = shift_argument || options[:app] || options[:confirm]
  validate_arguments!

  unless @app
    error("Usage: pebbles apps:destroy --app APP\nMust specify APP to destroy.")
  end

  api.get_app(@app) # fail fast if no access or doesn't exist

  message = "WARNING: Potentially Destructive Action\nThis command will destroy #{@app} (including all add-ons)."
  if confirm_command(@app, message)
    action("Destroying #{@app} (including all add-ons)") do
      api.delete_app(@app)
      if remotes = git_remotes(Dir.pwd)
        remotes.each do |remote_name, remote_app|
          next if @app != remote_app
          git "remote rm #{remote_name}"
        end
      end
    end
  end
end

#indexObject

apps

list your apps

Example:

$ pebbles apps

My Apps

example example2



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pebbles/command/apps.rb', line 18

def index
  validate_arguments!

  apps = api.get_apps.body

  unless apps.empty?
    styled_header("My Apps")
    styled_array(apps.map { |app| app_name(app) })
  else
    display("You have no apps.")
  end
end

#infoObject

apps:info

show detailed app information

-s, –shell # output more shell friendly key/value pairs

Examples:

$ pebbles apps:info

example

Git URL: git.pebblescape.com/example.git Repo Size: 5M …

$ pebbles apps:info –shell git_url=git.pebblescape.com/example.git repo_size=5000000 …



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
# File 'lib/pebbles/command/apps.rb', line 52

def info
  validate_arguments!
  app_data = api.get_app(app).body

  unless options[:shell]
    styled_header(app_data["name"])
  end
  
  if options[:shell]
    app_data['git_url'] = git_url(app_data['name'])
    if app_data['domain_name']
      app_data['domain_name'] = app_data['domain_name']['domain']
    end
    app_data['owner'].delete('id')
    flatten_hash(app_data, 'owner')
    app_data.keys.sort_by { |a| a.to_s }.each do |key|
      hputs("#{key}=#{app_data[key]}")
    end
  else
    data = {}
    
    if app_data["create_status"] && app_data["create_status"] != "complete"
      data["Create Status"] = app_data["create_status"]
    end

    data["Git URL"] = git_url(app_data['name'])

    
    if app_data["owner"]
      data["Owner Email"] = app_data["owner"]["email"]
      data["Owner"] = app_data["owner"]["name"]
    end
    data["Repo Size"] = format_bytes(app_data["repo_size"]) if app_data["repo_size"]
    data["Build Size"] = format_bytes(app_data["build_size"]) if app_data["build_size"]
    data["Web URL"] = app_data["web_url"]

    styled_hash(data)
  end
end

#openObject

apps:open –app APP

open the app in a web browser

Example:

$ heroku apps:open Opening example… done



210
211
212
213
214
215
216
217
218
# File 'lib/pebbles/command/apps.rb', line 210

def open
  path = shift_argument
  validate_arguments!

  app_data = api.get_app(app).body

  url = [app_data['web_url'], path].join
  launchy("Opening #{app}", url)
end