turbot 0.1.36 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +44 -25
- data/Rakefile +16 -0
- data/appveyor.yml +35 -0
- data/bin/turbot +2 -16
- data/data/schema.json +134 -0
- data/{templates → data/templates}/LICENSE.txt +0 -0
- data/{templates → data/templates}/manifest.json +0 -0
- data/{templates → data/templates}/python/scraper.py +0 -0
- data/{templates → data/templates}/ruby/scraper.rb +0 -0
- data/dist/deb.rake +32 -0
- data/dist/gem.rake +16 -0
- data/dist/manifest.rake +9 -0
- data/dist/pkg.rake +60 -0
- data/dist/resources/deb/control +10 -0
- data/dist/resources/deb/postinst +45 -0
- data/dist/resources/deb/turbot +25 -0
- data/dist/resources/deb/turbot-release-key.txt +30 -0
- data/dist/resources/pkg/Distribution.erb +15 -0
- data/dist/resources/pkg/PackageInfo.erb +6 -0
- data/dist/resources/pkg/postinstall +45 -0
- data/dist/resources/pkg/turbot +24 -0
- data/dist/resources/tgz/turbot +24 -0
- data/dist/rpm.rake +35 -0
- data/dist/tgz.rake +26 -0
- data/dist/zip.rake +40 -0
- data/lib/turbot/cli.rb +10 -27
- data/lib/turbot/command/auth.rb +72 -34
- data/lib/turbot/command/base.rb +21 -60
- data/lib/turbot/command/bots.rb +245 -300
- data/lib/turbot/command/help.rb +57 -110
- data/lib/turbot/command/version.rb +6 -10
- data/lib/turbot/command.rb +53 -196
- data/lib/turbot/handlers/base_handler.rb +21 -0
- data/lib/turbot/handlers/dump_handler.rb +10 -0
- data/lib/turbot/handlers/preview_handler.rb +30 -0
- data/lib/turbot/handlers/validation_handler.rb +17 -0
- data/lib/turbot/helpers/api_helper.rb +41 -0
- data/lib/turbot/helpers/netrc_helper.rb +66 -0
- data/lib/turbot/helpers/shell_helper.rb +36 -0
- data/lib/turbot/helpers.rb +14 -482
- data/lib/turbot/version.rb +1 -1
- data/lib/turbot.rb +17 -15
- data/spec/fixtures/bad_permissions +0 -0
- data/spec/fixtures/empty +0 -0
- data/spec/fixtures/netrc +6 -0
- data/spec/spec_helper.rb +17 -219
- data/spec/support/bot_helper.rb +100 -0
- data/spec/support/command_helper.rb +20 -0
- data/spec/support/custom_matchers.rb +5 -0
- data/spec/support/fixture_helper.rb +9 -0
- data/spec/support/netrc_helper.rb +21 -0
- data/spec/turbot/command/auth_spec.rb +202 -20
- data/spec/turbot/command/base_spec.rb +22 -58
- data/spec/turbot/command/bots_spec.rb +558 -89
- data/spec/turbot/command/help_spec.rb +32 -75
- data/spec/turbot/command/version_spec.rb +11 -10
- data/spec/turbot/command_spec.rb +60 -85
- data/turbot.gemspec +31 -0
- metadata +86 -178
- data/data/cacert.pem +0 -3988
- data/lib/turbot/auth.rb +0 -315
- data/lib/turbot/client/cisaurus.rb +0 -25
- data/lib/turbot/client/pgbackups.rb +0 -113
- data/lib/turbot/client/rendezvous.rb +0 -111
- data/lib/turbot/client/ssl_endpoint.rb +0 -25
- data/lib/turbot/client/turbot_postgresql.rb +0 -148
- data/lib/turbot/client.rb +0 -757
- data/lib/turbot/command/ssl.rb +0 -43
- data/lib/turbot/deprecated/help.rb +0 -38
- data/lib/turbot/deprecated.rb +0 -5
- data/lib/turbot/distribution.rb +0 -9
- data/lib/turbot/errors.rb +0 -28
- data/lib/turbot/excon.rb +0 -11
- data/lib/turbot/helpers/log_displayer.rb +0 -70
- data/lib/turbot/helpers/pg_dump_restore.rb +0 -115
- data/lib/turbot/helpers/turbot_postgresql.rb +0 -213
- data/lib/turbot/plugin.rb +0 -165
- data/lib/turbot/updater.rb +0 -171
- data/lib/vendor/turbot/okjson.rb +0 -598
- data/spec/helper/legacy_help.rb +0 -16
- data/spec/helper/pg_dump_restore_spec.rb +0 -67
- data/spec/spec.opts +0 -1
- data/spec/support/display_message_matcher.rb +0 -49
- data/spec/support/dummy_api.rb +0 -120
- data/spec/support/openssl_mock_helper.rb +0 -8
- data/spec/support/organizations_mock_helper.rb +0 -11
- data/spec/turbot/auth_spec.rb +0 -214
- data/spec/turbot/client/pgbackups_spec.rb +0 -43
- data/spec/turbot/client/rendezvous_spec.rb +0 -62
- data/spec/turbot/client/ssl_endpoint_spec.rb +0 -48
- data/spec/turbot/client/turbot_postgresql_spec.rb +0 -71
- data/spec/turbot/client_spec.rb +0 -548
- data/spec/turbot/helpers/turbot_postgresql_spec.rb +0 -181
- data/spec/turbot/helpers_spec.rb +0 -48
- data/spec/turbot/plugin_spec.rb +0 -172
- data/spec/turbot/updater_spec.rb +0 -44
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
|
3
|
+
usershell=$(dscl localhost -read /Local/Default/Users/$USER shell | sed -e 's/[^ ]* //')
|
4
|
+
|
5
|
+
startup_files() {
|
6
|
+
case $(basename $usershell) in
|
7
|
+
zsh)
|
8
|
+
echo ".zlogin .zshrc .zprofile .zshenv"
|
9
|
+
;;
|
10
|
+
bash)
|
11
|
+
echo ".bashrc .bash_profile .bash_login .profile"
|
12
|
+
;;
|
13
|
+
*)
|
14
|
+
echo ".bash_profile .zshrc .profile"
|
15
|
+
;;
|
16
|
+
esac
|
17
|
+
}
|
18
|
+
|
19
|
+
install_path() {
|
20
|
+
for file in $(startup_files); do
|
21
|
+
[ -f $HOME/$file ] || continue
|
22
|
+
(grep "Added by the Turbot" $HOME/$file >/dev/null) && break
|
23
|
+
|
24
|
+
cat <<MESSAGE >>$HOME/$file
|
25
|
+
|
26
|
+
### Added by the Turbot Toolbelt
|
27
|
+
export PATH="/usr/local/turbot/bin:\$PATH"
|
28
|
+
MESSAGE
|
29
|
+
|
30
|
+
# done after we add to one file
|
31
|
+
break
|
32
|
+
done
|
33
|
+
}
|
34
|
+
|
35
|
+
# if the toolbelt is not returned by `which`, let's add to the PATH
|
36
|
+
case $(which turbot) in
|
37
|
+
/usr/bin/turbot|/usr/local/turbot/bin/turbot)
|
38
|
+
;;
|
39
|
+
*)
|
40
|
+
install_path
|
41
|
+
;;
|
42
|
+
esac
|
43
|
+
|
44
|
+
# symlink binary to /usr/bin/turbot
|
45
|
+
ln -sf /usr/local/turbot/bin/turbot /usr/bin/turbot
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/local/turbot/ruby/bin/ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# resolve bin path, ignoring symlinks
|
5
|
+
require "pathname"
|
6
|
+
bin_file = Pathname.new(__FILE__).realpath
|
7
|
+
|
8
|
+
# add locally vendored gems to libpath
|
9
|
+
gem_dir = File.expand_path("../../vendor/gems", bin_file)
|
10
|
+
Dir["#{gem_dir}/**/lib"].each do |libdir|
|
11
|
+
$:.unshift libdir
|
12
|
+
end
|
13
|
+
|
14
|
+
# add self to libpath
|
15
|
+
$:.unshift File.expand_path("../../lib", bin_file)
|
16
|
+
|
17
|
+
# inject any code in ~/.turbot/client over top
|
18
|
+
require "turbot/updater"
|
19
|
+
Turbot::Updater.inject_libpath
|
20
|
+
|
21
|
+
# start up the CLI
|
22
|
+
require "turbot/cli"
|
23
|
+
Turbot.user_agent = "turbot-toolbelt/#{Turbot::VERSION} (#{RUBY_PLATFORM}) ruby/#{RUBY_VERSION}"
|
24
|
+
Turbot::CLI.start(*ARGV)
|
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# resolve bin path, ignoring symlinks
|
5
|
+
require "pathname"
|
6
|
+
bin_file = Pathname.new(__FILE__).realpath
|
7
|
+
|
8
|
+
# add locally vendored gems to libpath
|
9
|
+
gem_dir = File.expand_path("../../vendor/gems", bin_file)
|
10
|
+
Dir["#{gem_dir}/**/lib"].each do |libdir|
|
11
|
+
$:.unshift libdir
|
12
|
+
end
|
13
|
+
|
14
|
+
# add self to libpath
|
15
|
+
$:.unshift File.expand_path("../../lib", bin_file)
|
16
|
+
|
17
|
+
# inject any code in ~/.turbot/client over top
|
18
|
+
require "turbot/updater"
|
19
|
+
Turbot::Updater.inject_libpath
|
20
|
+
|
21
|
+
# start up the CLI
|
22
|
+
require "turbot/cli"
|
23
|
+
Turbot.user_agent = "turbot-toolbelt/#{Turbot::VERSION} (#{RUBY_PLATFORM}) ruby/#{RUBY_VERSION}"
|
24
|
+
Turbot::CLI.start(*ARGV)
|
data/dist/rpm.rake
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# TODO
|
2
|
+
# * signing
|
3
|
+
# * yum repository for updates
|
4
|
+
# * foreman
|
5
|
+
|
6
|
+
file pkg("/yum-#{version}/turbot-#{version}.rpm") => "deb:build" do |t|
|
7
|
+
mkchdir(File.dirname(t.name)) do
|
8
|
+
deb = pkg("/apt-#{version}/turbot-#{version}.deb")
|
9
|
+
sh "alien --keep-version --scripts --generate --to-rpm #{deb}"
|
10
|
+
|
11
|
+
spec = "turbot-#{version}/turbot-#{version}-1.spec"
|
12
|
+
spec_contents = File.read(spec)
|
13
|
+
File.open(spec, "w") do |f|
|
14
|
+
# Add ruby requirement, remove benchmark file with ugly filename
|
15
|
+
f.puts spec_contents.sub(/\n\n/m, "\nRequires: ruby\nBuildArch: noarch\n\n").
|
16
|
+
sub(/^.+has_key-vs-hash\[key\].+$/, "").
|
17
|
+
sub(/^License: .*/, "License: MIT\nURL: http://turbot.com\n").
|
18
|
+
sub(/^%description/, "%description\nClient library and CLI to deploy bots on Turbot.")
|
19
|
+
end
|
20
|
+
sh "sed -i s/ruby1.9.1/ruby/ turbot-#{version}/usr/local/turbot/bin/turbot"
|
21
|
+
|
22
|
+
chdir("turbot-#{version}") do
|
23
|
+
sh "rpmbuild --buildroot $PWD -bb turbot-#{version}-1.spec"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
desc "Build an .rpm package"
|
29
|
+
task "rpm:build" => pkg("/yum-#{version}/turbot-#{version}.rpm")
|
30
|
+
|
31
|
+
desc "Remove build artifacts for .rpm"
|
32
|
+
task "rpm:clean" do
|
33
|
+
clean pkg("turbot-#{version}.rpm")
|
34
|
+
FileUtils.rm_rf("pkg/yum-#{version}") if Dir.exists?("pkg/yum-#{version}")
|
35
|
+
end
|
data/dist/tgz.rake
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
file pkg("turbot-#{version}.tgz") => distribution_files("tgz") do |t|
|
2
|
+
tempdir do |dir|
|
3
|
+
mkchdir("turbot-client") do
|
4
|
+
assemble_distribution
|
5
|
+
assemble_gems
|
6
|
+
assemble resource("tgz/turbot"), "bin/turbot", 0755
|
7
|
+
end
|
8
|
+
|
9
|
+
sh "chmod -R go+r turbot-client"
|
10
|
+
sh "sudo chown -R 0:0 turbot-client"
|
11
|
+
sh "tar czf #{t.name} turbot-client"
|
12
|
+
sh "sudo chown -R $(whoami) turbot-client"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
task "tgz:build" => pkg("turbot-#{version}.tgz")
|
17
|
+
|
18
|
+
task "tgz:clean" do
|
19
|
+
clean pkg("turbot-#{version}.tgz")
|
20
|
+
end
|
21
|
+
|
22
|
+
task "tgz:release" => "tgz:build" do |t|
|
23
|
+
store pkg("turbot-#{version}.tgz"), "turbot-client/turbot-client-#{version}.tgz"
|
24
|
+
store pkg("turbot-#{version}.tgz"), "turbot-client/turbot-client-beta.tgz" if beta?
|
25
|
+
store pkg("turbot-#{version}.tgz"), "turbot-client/turbot-client.tgz" unless beta?
|
26
|
+
end
|
data/dist/zip.rake
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "zip"
|
2
|
+
|
3
|
+
file pkg("turbot-#{version}.zip") => distribution_files("zip") do |t|
|
4
|
+
tempdir do |dir|
|
5
|
+
mkchdir("turbot-client") do
|
6
|
+
assemble_distribution
|
7
|
+
assemble_gems
|
8
|
+
Zip::ZipFile.open(t.name, Zip::ZipFile::CREATE) do |zip|
|
9
|
+
Dir["**/*"].each do |file|
|
10
|
+
zip.add(file, file) { true }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
file pkg("turbot-#{version}.zip.sha256") => pkg("turbot-#{version}.zip") do |t|
|
18
|
+
File.open(t.name, "w") do |file|
|
19
|
+
file.puts Digest::SHA256.file(t.prerequisites.first).hexdigest
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
task "zip:build" => pkg("turbot-#{version}.zip")
|
24
|
+
task "zip:sign" => pkg("turbot-#{version}.zip.sha256")
|
25
|
+
|
26
|
+
def zip_signature
|
27
|
+
File.read(pkg("turbot-#{version}.zip.sha256")).chomp
|
28
|
+
end
|
29
|
+
|
30
|
+
task "zip:clean" do
|
31
|
+
clean pkg("turbot-#{version}.zip")
|
32
|
+
end
|
33
|
+
|
34
|
+
task "zip:release" => %w( zip:build zip:sign ) do |t|
|
35
|
+
store pkg("turbot-#{version}.zip"), "turbot-client/turbot-client-#{version}.zip"
|
36
|
+
store pkg("turbot-#{version}.zip"), "turbot-client/turbot-client-beta.zip" if beta?
|
37
|
+
store pkg("turbot-#{version}.zip"), "turbot-client/turbot-client.zip" unless beta?
|
38
|
+
|
39
|
+
sh "turbot config:add UPDATE_HASH=#{zip_signature} -a toolbelt"
|
40
|
+
end
|
data/lib/turbot/cli.rb
CHANGED
@@ -1,42 +1,25 @@
|
|
1
|
-
load('turbot/helpers.rb') # reload helpers after possible inject_loadpath
|
2
|
-
load('turbot/updater.rb') # reload updater after possible inject_loadpath
|
3
|
-
|
4
|
-
require "turbot"
|
5
|
-
require "turbot/command"
|
6
|
-
require "turbot/helpers"
|
7
|
-
|
8
|
-
# workaround for rescue/reraise to define errors in command.rb failing in 1.8.6
|
9
|
-
if RUBY_VERSION =~ /^1.8.6/
|
10
|
-
require('turbot-api')
|
11
|
-
require('rest_client')
|
12
|
-
end
|
13
|
-
|
14
1
|
class Turbot::CLI
|
15
|
-
|
16
2
|
extend Turbot::Helpers
|
17
3
|
|
18
4
|
def self.start(*args)
|
19
5
|
begin
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
$stdout.sync = true
|
25
|
-
end
|
26
|
-
command = args.shift.strip rescue "help"
|
27
|
-
Turbot::Command.load
|
28
|
-
trap "SIGINT" do
|
6
|
+
$stdout.sync = true
|
7
|
+
$stderr.sync = true
|
8
|
+
|
9
|
+
trap 'SIGINT' do
|
29
10
|
# Script terminated by Control-C.
|
30
11
|
exit 130
|
31
12
|
end
|
13
|
+
|
14
|
+
Turbot::Command.load
|
15
|
+
command = args.shift.strip rescue 'help'
|
32
16
|
Turbot::Command.run(command, args)
|
33
17
|
rescue Interrupt
|
34
18
|
`stty icanon echo`
|
35
|
-
error
|
36
|
-
rescue =>
|
37
|
-
styled_error(
|
19
|
+
error 'Command cancelled.'
|
20
|
+
rescue => e
|
21
|
+
styled_error(e)
|
38
22
|
exit(1)
|
39
23
|
end
|
40
24
|
end
|
41
|
-
|
42
25
|
end
|
data/lib/turbot/command/auth.rb
CHANGED
@@ -1,85 +1,123 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# authentication (login, logout)
|
1
|
+
#Login or logout from Turbot
|
4
2
|
#
|
5
3
|
class Turbot::Command::Auth < Turbot::Command::Base
|
6
|
-
|
7
4
|
# auth
|
8
5
|
#
|
9
|
-
#
|
6
|
+
#Login or logout. Display your Turbot API token or email address.
|
10
7
|
def index
|
11
8
|
validate_arguments!
|
12
|
-
|
13
9
|
Turbot::Command::Help.new.send(:help_for_command, current_command)
|
14
10
|
end
|
15
11
|
|
16
12
|
# auth:login
|
17
13
|
#
|
18
|
-
#
|
14
|
+
#Login to Turbot and save your Turbot credentials.
|
19
15
|
#
|
20
16
|
#Example:
|
21
17
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
25
|
-
#
|
26
|
-
#
|
18
|
+
# $ turbot auth:login
|
19
|
+
# Enter your Turbot email and password:
|
20
|
+
# Email: email@example.com
|
21
|
+
# Password (typing will be hidden):
|
22
|
+
# Logged in. Saved Turbot API key.
|
27
23
|
#
|
28
24
|
def login
|
29
25
|
validate_arguments!
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
email_address, api_key = ask_for_email_address_and_password
|
27
|
+
if api_key.empty?
|
28
|
+
error 'Authentication failed.'
|
29
|
+
end
|
30
|
+
save_netrc_entry(email_address, api_key)
|
31
|
+
puts 'Authentication successful.'
|
33
32
|
end
|
34
|
-
|
35
|
-
alias_command "login", "auth:login"
|
33
|
+
alias_command 'login', 'auth:login'
|
36
34
|
|
37
35
|
# auth:logout
|
38
36
|
#
|
39
|
-
#
|
37
|
+
#Delete your Turbot credentials.
|
40
38
|
#
|
41
39
|
#Example:
|
42
40
|
#
|
43
|
-
#
|
44
|
-
#
|
41
|
+
# $ turbot auth:logout
|
42
|
+
# Deleted Turbot credentials.
|
45
43
|
#
|
46
44
|
def logout
|
47
45
|
validate_arguments!
|
48
|
-
|
49
|
-
Turbot
|
50
|
-
display "Local credentials cleared."
|
46
|
+
delete_netrc_entry
|
47
|
+
puts 'Deleted Turbot credentials.'
|
51
48
|
end
|
52
|
-
|
53
|
-
alias_command "logout", "auth:logout"
|
49
|
+
alias_command 'logout', 'auth:logout'
|
54
50
|
|
55
51
|
# auth:token
|
56
52
|
#
|
57
|
-
#
|
53
|
+
#Display your Turbot API token.
|
58
54
|
#
|
59
55
|
#Example:
|
60
56
|
#
|
61
|
-
#
|
62
|
-
#
|
57
|
+
# $ turbot auth:token
|
58
|
+
# 93a5c45595ed37dc9d040116
|
63
59
|
#
|
64
60
|
def token
|
65
61
|
validate_arguments!
|
66
|
-
|
67
|
-
|
62
|
+
result = email_address_and_api_key[1]
|
63
|
+
if result
|
64
|
+
puts result
|
65
|
+
else
|
66
|
+
error 'not logged in'
|
67
|
+
end
|
68
68
|
end
|
69
69
|
|
70
70
|
# auth:whoami
|
71
71
|
#
|
72
|
-
#
|
72
|
+
#Display your Turbot email address.
|
73
73
|
#
|
74
74
|
#Example:
|
75
75
|
#
|
76
|
-
#
|
77
|
-
#
|
76
|
+
# $ turbot auth:whoami
|
77
|
+
# email@example.com
|
78
78
|
#
|
79
79
|
def whoami
|
80
80
|
validate_arguments!
|
81
|
+
result = email_address_and_api_key[0]
|
82
|
+
if result
|
83
|
+
puts result
|
84
|
+
else
|
85
|
+
error 'not logged in'
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
### Shell-related
|
81
92
|
|
82
|
-
|
93
|
+
# Prompts the user for an email address and password, and returns the email
|
94
|
+
# address and the user's API key.
|
95
|
+
#
|
96
|
+
# @return [Array<String>] the user's email address and API key
|
97
|
+
def ask_for_email_address_and_password
|
98
|
+
puts 'Enter your Turbot email and password.'
|
99
|
+
|
100
|
+
print 'Email: '
|
101
|
+
email_address = ask
|
102
|
+
|
103
|
+
print 'Password (typing will be hidden): '
|
104
|
+
password = running_on_windows? ? ask_for_password_on_windows : ask_for_password
|
105
|
+
|
106
|
+
puts
|
107
|
+
|
108
|
+
[email_address, get_api_key(email_address, password)]
|
83
109
|
end
|
84
110
|
|
111
|
+
def running_on_windows?
|
112
|
+
RUBY_PLATFORM =~ /mswin32|mingw32/
|
113
|
+
end
|
114
|
+
|
115
|
+
### API-related
|
116
|
+
|
117
|
+
# Gets the user's API key.
|
118
|
+
#
|
119
|
+
# @return [String] the API key, or the empty string if authentication fails
|
120
|
+
def get_api_key(email_address, password)
|
121
|
+
api.get_api_key_for_credentials(email_address, password)['api_key']
|
122
|
+
end
|
85
123
|
end
|
data/lib/turbot/command/base.rb
CHANGED
@@ -1,19 +1,14 @@
|
|
1
|
-
require "fileutils"
|
2
|
-
require "turbot/auth"
|
3
|
-
require "turbot/client/rendezvous"
|
4
|
-
require "turbot/command"
|
5
|
-
|
6
1
|
class Turbot::Command::Base
|
7
2
|
include Turbot::Helpers
|
8
3
|
|
9
4
|
def self.namespace
|
10
|
-
self.to_s.split(
|
5
|
+
self.to_s.split('::').last.downcase
|
11
6
|
end
|
12
7
|
|
13
8
|
attr_reader :args
|
14
9
|
attr_reader :options
|
15
10
|
|
16
|
-
def initialize(args=[], options={})
|
11
|
+
def initialize(args = [], options = {})
|
17
12
|
@args = args
|
18
13
|
@options = options
|
19
14
|
end
|
@@ -21,24 +16,13 @@ class Turbot::Command::Base
|
|
21
16
|
def bot
|
22
17
|
@bot ||= if options[:bot].is_a?(String)
|
23
18
|
options[:bot]
|
24
|
-
elsif ENV
|
19
|
+
elsif ENV['TURBOT_BOT']
|
25
20
|
ENV['TURBOT_BOT']
|
26
|
-
elsif
|
27
|
-
|
28
|
-
else
|
29
|
-
# raise instead of using error command to enable rescuing when bot is optional
|
30
|
-
raise Turbot::Command::CommandFailed.new("No bot specified.\nRun this command from a bot folder containing a `manifest.json`, or specify which bot to use with --bot BOT_ID.") unless options[:ignore_no_bot]
|
21
|
+
elsif manifest = parse_manifest
|
22
|
+
manifest['bot_id']
|
31
23
|
end
|
32
24
|
end
|
33
25
|
|
34
|
-
def api
|
35
|
-
Turbot::Auth.api
|
36
|
-
end
|
37
|
-
|
38
|
-
def turbot
|
39
|
-
Turbot::Auth.client
|
40
|
-
end
|
41
|
-
|
42
26
|
protected
|
43
27
|
|
44
28
|
def self.inherited(klass)
|
@@ -53,9 +37,9 @@ protected
|
|
53
37
|
end
|
54
38
|
|
55
39
|
def self.method_added(method)
|
56
|
-
|
57
|
-
|
58
|
-
|
40
|
+
if self == Turbot::Command::Base || private_method_defined?(method) || protected_method_defined?(method)
|
41
|
+
return
|
42
|
+
end
|
59
43
|
|
60
44
|
help = extract_help_from_caller(caller.first)
|
61
45
|
resolved_method = (method.to_s == "index") ? nil : method.to_s
|
@@ -73,18 +57,10 @@ protected
|
|
73
57
|
:description => extract_description(help),
|
74
58
|
:options => extract_options(help)
|
75
59
|
)
|
76
|
-
|
77
|
-
alias_command command.gsub(/_/, '-'), command if command =~ /_/
|
78
|
-
end
|
79
|
-
|
80
|
-
def self.alias_command(new, old)
|
81
|
-
raise "no such command: #{old}" unless Turbot::Command.commands[old]
|
82
|
-
Turbot::Command.command_aliases[new] = old
|
83
60
|
end
|
84
61
|
|
85
|
-
def
|
86
|
-
|
87
|
-
bot
|
62
|
+
def self.alias_command(command_alias, command)
|
63
|
+
Turbot::Command.command_aliases[command_alias] = command
|
88
64
|
end
|
89
65
|
|
90
66
|
#
|
@@ -113,7 +89,7 @@ protected
|
|
113
89
|
buffer = []
|
114
90
|
lines = Turbot::Command.files[file]
|
115
91
|
|
116
|
-
(line_number.to_i-2).downto(0) do |i|
|
92
|
+
(line_number.to_i - 2).downto(0) do |i|
|
117
93
|
line = lines[i]
|
118
94
|
case line[0..0]
|
119
95
|
when ""
|
@@ -156,37 +132,22 @@ protected
|
|
156
132
|
Turbot::Command.current_command
|
157
133
|
end
|
158
134
|
|
159
|
-
def extract_option(key)
|
160
|
-
options[key.dup.gsub('-','_').to_sym]
|
161
|
-
end
|
162
|
-
|
163
|
-
def invalid_arguments
|
164
|
-
Turbot::Command.invalid_arguments
|
165
|
-
end
|
166
|
-
|
167
|
-
def shift_argument
|
168
|
-
Turbot::Command.shift_argument
|
169
|
-
end
|
170
|
-
|
171
135
|
def validate_arguments!
|
172
136
|
Turbot::Command.validate_arguments!
|
173
137
|
end
|
174
138
|
|
175
|
-
def
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
139
|
+
def parse_manifest
|
140
|
+
path = File.join(working_directory, 'manifest.json')
|
141
|
+
if File.exists?(path)
|
142
|
+
begin
|
143
|
+
JSON.load(File.read(path))
|
144
|
+
rescue JSON::ParserError => e
|
145
|
+
error "`manifest.json` is invalid JSON. Consider validating it at http://pro.jsonlint.com/"
|
146
|
+
end
|
180
147
|
end
|
181
148
|
end
|
182
149
|
|
183
|
-
def
|
184
|
-
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
module Turbot::Command
|
189
|
-
unless const_defined?(:BaseWithApp)
|
190
|
-
BaseWithApp = Base
|
150
|
+
def working_directory
|
151
|
+
Dir.pwd
|
191
152
|
end
|
192
153
|
end
|