heroku-shortcuts 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (6) hide show
  1. checksums.yaml +15 -0
  2. data/MIT-LICENSE.txt +21 -0
  3. data/README.md +30 -0
  4. data/bin/h +122 -0
  5. data/heroku-shortcuts.gemspec +17 -0
  6. metadata +51 -0
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZTQzODU1ZjczYTMyZTJkOWU1OGRiODlhNzBhYjRhNzgxYzg4YzMxZQ==
5
+ data.tar.gz: !binary |-
6
+ NmRlNmE3OTQ1M2YyYjJhOGM0NWMwNjQ2N2VlNzRjYmIwODlmMjZhYQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ ZDk5Y2FhNDIwNmIyMGQwMjM5NDFjMzFmMThkMWE2NTYwYTFkOTg0ZmE1Y2Mw
10
+ OTRlZWMyMjJjZGQ5ZTUzZGJlNmUwOTAwOGRkNjk2MGFhYTg4ZDZhMWZmZWEy
11
+ ZTNkNzI0ZjQ3NWNlMDgxZjg1NTA4NDg2YzM3NTk4YmU1N2M3NWE=
12
+ data.tar.gz: !binary |-
13
+ YTI3YmExM2M3OTRiMThmMDkzOWFhYTAxOTkwOTFhM2E3ZWIzOTE5YjJmYjhh
14
+ YTYxYzg4Y2ViMTgzMmY5MzhkMjM2M2U4NTZlNzhmNjAyMzJmZDI5ZTE5YTZj
15
+ NTgxM2Q3OThhNTRlNzg3MjY5NGY5Njk2OTUwOTM5ZjI5MzRhZjU=
data/MIT-LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ Copyright 2013 Vertical Brands Media, ApartmentList
2
+ http://www.apartmentlist.com/
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ ## heroku-shortcuts
2
+
3
+ This gem is a collection of shortcuts and shorthands for Heroku commands and
4
+ applications. Once you've set up shortname aliases (see section below), you
5
+ can invoke commands as:
6
+
7
+ ```bash
8
+ $ h logs hp
9
+ Executing 'heroku logs -t --app heroku-production'...
10
+ ```
11
+
12
+ ### Installation
13
+ ##### Building Locally
14
+ ```bash
15
+ gem build heroku-shortcuts.gemspec
16
+ gem install heroku-shortcuts-0.0.1.gem
17
+ ```
18
+
19
+ ##### Configure Application Shortnames
20
+ Create `~/.heroku-apps.json` as a hash of short name => full name:
21
+ ```json
22
+ {
23
+ 'hp': 'heroku-production',
24
+ 'hs': 'heroku-staging'
25
+ }
26
+ ```
27
+
28
+ ### License
29
+ This gem was created by the ApartmentList engineering team and is released under
30
+ the MIT license.
data/bin/h ADDED
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env ruby
2
+ require 'json'
3
+
4
+ path = File.expand_path('~/.heroku-apps.json')
5
+ if File.exists?(path)
6
+ envs = File.open(path, 'r') { |f| JSON.load(f) }
7
+ else
8
+ puts '~/.heroku-apps.json must be configured for your environments before '\
9
+ 'using `h`'
10
+ exit -1
11
+ end
12
+
13
+ action_key = ARGV.shift
14
+ environment = ARGV.pop
15
+ real_environment = environment ? envs[environment] : nil
16
+ action_args = ARGV
17
+
18
+ actions = {
19
+ logs: 'logs -t',
20
+ console: 'run rails c',
21
+ bash: 'run bash',
22
+ hist: 'releases',
23
+ mon: 'maintenance:on',
24
+ moff: 'maintenance:off',
25
+ # Database
26
+ pg: 'pg:psql',
27
+ pginfo: 'pg:info',
28
+ migrate: 'run rake db:migrate',
29
+ pulltable: 'db:pull --tables',
30
+ # Processes / Workers
31
+ scale: 'ps:scale',
32
+ restart: 'ps:restart',
33
+ # Addons - Browser
34
+ add: 'addons:add',
35
+ remove: 'addons:remove',
36
+ relic: 'addons:open newrelic',
37
+ bigwig: 'addons:open rabbitmq-bigwig',
38
+ rmq: lambda{r = get_rmq_addon(real_environment); "addons:open #{r}"},
39
+ redis: lambda{r = get_redis_addon(real_environment); "addons:open #{r}"},
40
+ sched: 'addons:open scheduler',
41
+ postgres: 'addons:open heroku-postgresql',
42
+ graphite: 'addons:open hostedgraphite',
43
+ librato: 'addons:open librato',
44
+ # Backups
45
+ backups: 'pgbackups',
46
+ capture: 'pgbackups:capture',
47
+ grab: 'pgbackups:url',
48
+ # No mapping, but listed for completeness
49
+ ps: 'ps',
50
+ addons: 'addons',
51
+ config: 'config',
52
+ }
53
+
54
+ def multiple_addon_handle(type, regex, env)
55
+ addons = %x[heroku addons --app #{env}].split.grep(regex)
56
+ case addons.size
57
+ when 0
58
+ puts("No #{type} addons found for #{env}")
59
+ when 1
60
+ addons.first
61
+ else
62
+ addon = addons.first
63
+ puts("Multiple #{type} addons found:")
64
+ addons.each{ |a| puts("\t#{a}") }
65
+ puts("Using '#{addon}'")
66
+ addon
67
+ end
68
+ end
69
+
70
+ def get_redis_addon(env)
71
+ multiple_addon_handle('Redis', /redis/i, env)
72
+ end
73
+
74
+ def get_rmq_addon(env)
75
+ multiple_addon_handle('RMQ', /rabbitmq|amqp/i, env)
76
+ end
77
+
78
+ if not action_key or action_key =~ /help/i
79
+ puts "Usage: 'h <action> <environment>'"
80
+ puts "\nActions:"
81
+ actions.to_a.each{|pair| puts pair * " => "}
82
+ puts "\nEnvironments:"
83
+ envs.to_a.each{|pair| puts pair * " => "}
84
+ end
85
+
86
+ environmentless_actions = ['status', 'addons:list']
87
+
88
+ exit if !action_key || (!environment && !environmentless_actions.member?(action_key))
89
+
90
+ action = actions[action_key.to_sym]
91
+ real_action = case action
92
+ when String
93
+ action
94
+ when Proc
95
+ action.call
96
+ when nil
97
+ action_key
98
+ end
99
+
100
+ # DB-specific logic. If we get much more like this, we'll need to
101
+ # develop a much more scalable approach to this app.
102
+ if action_key == 'pg'
103
+ db = action_args[0] # Assume the first arg (if any) to pg is a DB color
104
+ if db and not db =~ /HEROKU/
105
+ action_args[0] = "HEROKU_POSTGRESQL_#{action_args[0].upcase}"
106
+ end
107
+ end
108
+
109
+ # Logs specific logic -- add the '-p' arg
110
+ if action_key == 'logs'
111
+ worker_spec = action_args[0]
112
+ action_args.unshift('-p') if worker_spec
113
+ end
114
+
115
+ action_args = action_args * ' '
116
+
117
+ app = real_environment ? "--app #{real_environment}" : nil
118
+ command_array = ["heroku", real_action, *action_args, app]
119
+
120
+ command = command_array * ' '
121
+ puts "Executing '#{command}'..."
122
+ output = system(command)
@@ -0,0 +1,17 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "heroku-shortcuts"
7
+ spec.version = "0.0.1"
8
+ spec.authors = ["Rick Dillon", "Adam Derewecki"]
9
+ spec.email = ["rpdillon@apartmentlist.com", "adam@apartmentlist.com"]
10
+ spec.description = %q{Shortcuts for the Heroku CLI}
11
+ spec.summary = %q{Shortcuts for the Heroku CLI}
12
+ spec.homepage = "https://github.com/apartmentlist/h"
13
+ spec.license = "MIT"
14
+ spec.has_rdoc = false
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: heroku-shortcuts
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Rick Dillon
8
+ - Adam Derewecki
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-09-13 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Shortcuts for the Heroku CLI
15
+ email:
16
+ - rpdillon@apartmentlist.com
17
+ - adam@apartmentlist.com
18
+ executables:
19
+ - h
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - MIT-LICENSE.txt
24
+ - README.md
25
+ - bin/h
26
+ - heroku-shortcuts.gemspec
27
+ homepage: https://github.com/apartmentlist/h
28
+ licenses:
29
+ - MIT
30
+ metadata: {}
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ! '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubyforge_project:
47
+ rubygems_version: 2.0.3
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Shortcuts for the Heroku CLI
51
+ test_files: []