protobox 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +61 -0
- data/LICENSE +48 -0
- data/README.md +21 -0
- data/Rakefile +1 -0
- data/bin/protobox +6 -0
- data/lib/protobox.rb +5 -0
- data/lib/protobox/cli.rb +43 -0
- data/lib/protobox/command/help.rb +31 -0
- data/lib/protobox/command/init.rb +144 -0
- data/lib/protobox/command/passthrough.rb +19 -0
- data/lib/protobox/commands.rb +59 -0
- data/lib/protobox/errors.rb +8 -0
- data/lib/protobox/util.rb +167 -0
- data/lib/protobox/version.rb +3 -0
- data/protobox.gemspec +54 -0
- metadata +76 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c59abbd1810b4494afce98c76d716a08077208a9
|
4
|
+
data.tar.gz: aa81b1c4e4fbc318cbcd6fdae10df617be784161
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2731cbda804d0b3bef9bedf19abd9e2d85fd3b36bdda31e597f921cbbdf5d9af4fec4df0290ecc7cbe1298d966c97ad6030caa684a513ca0a96fad012caea9bf
|
7
|
+
data.tar.gz: 61947975a0773affef3b8e528658031dea20a70ed0103761062244b3268b8f7472f1c691299d46c024a462ec74cf8bfd21d93348470dbd81de4d67ae98425fe6
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in protoboxs.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
group :development do
|
7
|
+
gem "vagrant", git: "https://github.com/mitchellh/vagrant.git"
|
8
|
+
end
|
9
|
+
|
10
|
+
group :plugins do
|
11
|
+
gem "vagrant-protobox", git: "https://github.com/protobox/vagrant-protobox.git"
|
12
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
GIT
|
2
|
+
remote: https://github.com/mitchellh/vagrant.git
|
3
|
+
revision: 240523b1aa9f328c09060cff34a211bd3f93f7ca
|
4
|
+
specs:
|
5
|
+
vagrant (1.5.1.dev)
|
6
|
+
bundler (~> 1.5.2)
|
7
|
+
childprocess (~> 0.5.0)
|
8
|
+
erubis (~> 2.7.0)
|
9
|
+
i18n (~> 0.6.0)
|
10
|
+
listen (~> 2.4.0)
|
11
|
+
log4r (~> 1.1.9, < 1.1.11)
|
12
|
+
net-scp (~> 1.1.0)
|
13
|
+
net-ssh (>= 2.6.6, < 2.8.0)
|
14
|
+
rb-kqueue (~> 0.2.0)
|
15
|
+
wdm (~> 0.1.0)
|
16
|
+
|
17
|
+
GIT
|
18
|
+
remote: https://github.com/protobox/vagrant-protobox.git
|
19
|
+
revision: 191a2a8842ffd25ecd90f1fda3439da5c2294fbd
|
20
|
+
specs:
|
21
|
+
vagrant-protobox (0.0.1)
|
22
|
+
|
23
|
+
PATH
|
24
|
+
remote: .
|
25
|
+
specs:
|
26
|
+
protobox (0.0.1)
|
27
|
+
|
28
|
+
GEM
|
29
|
+
remote: https://rubygems.org/
|
30
|
+
specs:
|
31
|
+
celluloid (0.15.2)
|
32
|
+
timers (~> 1.1.0)
|
33
|
+
childprocess (0.5.1)
|
34
|
+
ffi (~> 1.0, >= 1.0.11)
|
35
|
+
erubis (2.7.0)
|
36
|
+
ffi (1.9.3)
|
37
|
+
i18n (0.6.9)
|
38
|
+
listen (2.4.1)
|
39
|
+
celluloid (>= 0.15.2)
|
40
|
+
rb-fsevent (>= 0.9.3)
|
41
|
+
rb-inotify (>= 0.9)
|
42
|
+
log4r (1.1.10)
|
43
|
+
net-scp (1.1.2)
|
44
|
+
net-ssh (>= 2.6.5)
|
45
|
+
net-ssh (2.7.0)
|
46
|
+
rb-fsevent (0.9.4)
|
47
|
+
rb-inotify (0.9.3)
|
48
|
+
ffi (>= 0.5.0)
|
49
|
+
rb-kqueue (0.2.2)
|
50
|
+
ffi (>= 0.5.0)
|
51
|
+
timers (1.1.0)
|
52
|
+
wdm (0.1.0)
|
53
|
+
|
54
|
+
PLATFORMS
|
55
|
+
ruby
|
56
|
+
|
57
|
+
DEPENDENCIES
|
58
|
+
bundler (~> 1.5)
|
59
|
+
protobox!
|
60
|
+
vagrant!
|
61
|
+
vagrant-protobox!
|
data/LICENSE
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Patrick Heeney
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
----
|
23
|
+
|
24
|
+
This application bundles or uses portions of third-party
|
25
|
+
packages in accordance with the following licenses:
|
26
|
+
|
27
|
+
----
|
28
|
+
|
29
|
+
Copyright (c) 2009 Chris Wanstrath
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
"Software"), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
45
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
46
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
47
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
48
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Protobox
|
2
|
+
|
3
|
+
Protobox CLI Tools
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Using terminal:
|
8
|
+
|
9
|
+
$ gem install protobox
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
$ protobox
|
14
|
+
|
15
|
+
## Contributing
|
16
|
+
|
17
|
+
1. Fork it ( http://github.com/protobox/gem-protobox/fork )
|
18
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
19
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
20
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
21
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/protobox
ADDED
data/lib/protobox.rb
ADDED
data/lib/protobox/cli.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
module Protobox
|
2
|
+
class Cli
|
3
|
+
attr_reader :args
|
4
|
+
|
5
|
+
def initialize(*args)
|
6
|
+
#@args = Args.new(args)
|
7
|
+
@args = args
|
8
|
+
end
|
9
|
+
|
10
|
+
# Shortcut
|
11
|
+
def self.execute(*args)
|
12
|
+
new(*args).execute
|
13
|
+
end
|
14
|
+
|
15
|
+
def execute
|
16
|
+
Commands.run(@args)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Runs multiple commands in succession; exits at first failure.
|
20
|
+
def execute_command_chain commands
|
21
|
+
commands.each_with_index do |cmd, i|
|
22
|
+
if cmd.respond_to?(:call) then cmd.call
|
23
|
+
elsif i == commands.length - 1
|
24
|
+
# last command in chain
|
25
|
+
STDOUT.flush; STDERR.flush
|
26
|
+
exec(*cmd)
|
27
|
+
else
|
28
|
+
exit($?.exitstatus) unless system(*cmd)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Special-case `echo` for Windows
|
34
|
+
def exec *args
|
35
|
+
if args.first == 'echo' && Util::Context.windows?
|
36
|
+
puts args[1..-1].join(' ')
|
37
|
+
else
|
38
|
+
super
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Protobox
|
2
|
+
module Command
|
3
|
+
class Help
|
4
|
+
def self.execute args
|
5
|
+
global = <<-help
|
6
|
+
usage: protobox [options] <command> [<args>]
|
7
|
+
|
8
|
+
Commands:
|
9
|
+
version Protobox CLI Version
|
10
|
+
init Create a new protobox install in the current directory
|
11
|
+
install Install a protobox configuration locallly
|
12
|
+
switch Switch the protobox configuration file to be used by vagrant
|
13
|
+
|
14
|
+
See 'protobox help <command>' for more information on a specific command.
|
15
|
+
help
|
16
|
+
|
17
|
+
if args.empty?
|
18
|
+
puts global
|
19
|
+
exit
|
20
|
+
end
|
21
|
+
|
22
|
+
cmd = args.first
|
23
|
+
|
24
|
+
system "protobox", cmd, "help"
|
25
|
+
|
26
|
+
# Success, exit status 0
|
27
|
+
0
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
|
3
|
+
module Protobox
|
4
|
+
module Command
|
5
|
+
class Init
|
6
|
+
def self.execute args
|
7
|
+
options = { verbose: false }
|
8
|
+
|
9
|
+
opts = help
|
10
|
+
|
11
|
+
# Parse the options
|
12
|
+
argv = opts.parse(args)
|
13
|
+
#return if !argv
|
14
|
+
|
15
|
+
#if argv.empty? ||
|
16
|
+
if argv.first == 'help'
|
17
|
+
puts opts
|
18
|
+
exit
|
19
|
+
end
|
20
|
+
|
21
|
+
install_folder = Util::System.current_dir
|
22
|
+
git = Util::Platform.git
|
23
|
+
vagrant = Util::Platform.vagrant
|
24
|
+
|
25
|
+
# Get installation folder
|
26
|
+
puts "Protobox will now be installed at:"
|
27
|
+
puts current_dir
|
28
|
+
|
29
|
+
#install_folder = Protobox::Util::Input.get_input
|
30
|
+
Util::Input.enter_or_abort # if STDIN.tty?
|
31
|
+
|
32
|
+
# Check for git
|
33
|
+
if !git
|
34
|
+
raise Errors::FatalError, 'GIT is required'
|
35
|
+
end
|
36
|
+
|
37
|
+
# Check for vagrant
|
38
|
+
if !vagrant
|
39
|
+
raise Errors::FatalError, 'Vagrant is required'
|
40
|
+
end
|
41
|
+
|
42
|
+
# Check for previous installation
|
43
|
+
if !Dir["#{install_folder}/.git/*"].empty?
|
44
|
+
raise Errors::FatalError, <<-MESSAGE
|
45
|
+
It appears something is already installed here. Please run this installer in an empty directory.
|
46
|
+
MESSAGE
|
47
|
+
end
|
48
|
+
|
49
|
+
# Test for permissions
|
50
|
+
if File.directory?(install_folder) and not File.executable?(install_folder)
|
51
|
+
raise Errors::FatalError, <<-MESSAGE
|
52
|
+
The installation folder, #{install_folder}, exists but is not readable. Please fix
|
53
|
+
the permissions and try again:
|
54
|
+
sudo chmod 755 #{install_folder}
|
55
|
+
MESSAGE
|
56
|
+
end
|
57
|
+
|
58
|
+
puts "Starting installation..."
|
59
|
+
|
60
|
+
if File.directory?(install_folder)
|
61
|
+
system "/bin/chmod g+rwx #{install_folder}"
|
62
|
+
else
|
63
|
+
system "/bin/mkdir #{install_folder}"
|
64
|
+
system "/bin/chmod g+rwx #{install_folder}"
|
65
|
+
end
|
66
|
+
|
67
|
+
puts "Downloading and installing protobox..."
|
68
|
+
Dir.chdir(install_folder) do
|
69
|
+
if git
|
70
|
+
# we do it in four steps to avoid merge errors when reinstalling
|
71
|
+
system git, "init", "-q"
|
72
|
+
system git, "remote", "add", "origin", "https://github.com/protobox/protobox"
|
73
|
+
|
74
|
+
args = git, "fetch", "origin", "master:refs/remotes/origin/master", "-n"
|
75
|
+
args << "--depth=1" if ARGV.include? "--fast"
|
76
|
+
system *args
|
77
|
+
|
78
|
+
system git, "reset", "--hard", "origin/master"
|
79
|
+
else
|
80
|
+
# -m to stop tar erroring out if it can't modify the mtime for root owned directories
|
81
|
+
# pipefail to cause the exit status from curl to propogate if it fails
|
82
|
+
# we use -k for curl because Leopard has a bunch of bad SSL certificates
|
83
|
+
#curl_flags = "fsSL"
|
84
|
+
#curl_flags << "k" if macos_version <= "10.5"
|
85
|
+
#system "/bin/bash -o pipefail -c '/usr/bin/curl -#{curl_flags} https://github.com/protobox/protobox/tarball/master | /usr/bin/tar xz -m --strip 1'"
|
86
|
+
|
87
|
+
raise Errors::FatalError, "GIT not found and is required to install"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
puts "Configuring protobox..."
|
92
|
+
|
93
|
+
Dir.chdir(install_folder) do
|
94
|
+
system "/bin/cp data/config/common.yml-dist data/config/common.yml"
|
95
|
+
|
96
|
+
#system "vagrant up" if ARGV.include? "--boot"
|
97
|
+
end
|
98
|
+
|
99
|
+
# Install vagrant tools
|
100
|
+
system vagrant, "plugin", "install", "vagrant-protobox"
|
101
|
+
|
102
|
+
# TODO
|
103
|
+
# - check for arguments to install a config and boot
|
104
|
+
# - protobox init abc123
|
105
|
+
# - this, sets up protobox dir in current directory
|
106
|
+
# - installs vagrant plugin
|
107
|
+
# - passes through vagrant install command
|
108
|
+
# - vagrant up
|
109
|
+
|
110
|
+
puts "Installation successful! Type the following to make sure its working: "
|
111
|
+
#puts "cd #{install_folder}/ && protobox help"
|
112
|
+
puts "protobox help"
|
113
|
+
|
114
|
+
#Cli.exec("protobox help")
|
115
|
+
|
116
|
+
# Success, exit status 0
|
117
|
+
0
|
118
|
+
end
|
119
|
+
|
120
|
+
def self.help
|
121
|
+
return OptionParser.new do |o|
|
122
|
+
o.banner = "Usage: protobox init [options]"
|
123
|
+
o.separator ""
|
124
|
+
o.separator "Options:"
|
125
|
+
o.separator ""
|
126
|
+
|
127
|
+
o.on("-c", "--clean", "Clean any temporary download files") do |c|
|
128
|
+
options[:clean] = c
|
129
|
+
end
|
130
|
+
|
131
|
+
o.on("-f", "--force", "Overwrite an existing box if it exists") do |f|
|
132
|
+
options[:force] = f
|
133
|
+
end
|
134
|
+
|
135
|
+
o.on("--verbose", "Enable verbose output for the installation") do |v|
|
136
|
+
options[:verbose] = v
|
137
|
+
end
|
138
|
+
|
139
|
+
o.separator ""
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Protobox
|
2
|
+
module Command
|
3
|
+
class PassThrough
|
4
|
+
def self.execute args
|
5
|
+
#puts args.inspect
|
6
|
+
|
7
|
+
vagrant = Protobox::Util::Platform.vagrant
|
8
|
+
|
9
|
+
args.insert(0, vagrant)
|
10
|
+
args.insert(1, 'protobox')
|
11
|
+
|
12
|
+
system *args
|
13
|
+
|
14
|
+
# Success, exit status 0
|
15
|
+
0
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Protobox
|
2
|
+
module Commands
|
3
|
+
extend self
|
4
|
+
|
5
|
+
STOCK_COMMANDS = %w[install switch]
|
6
|
+
CUSTOM_COMMANDS = %w[init]
|
7
|
+
|
8
|
+
def run(args)
|
9
|
+
args.unshift 'help' if args.empty?
|
10
|
+
|
11
|
+
# get first argument
|
12
|
+
cmd = args[0]
|
13
|
+
|
14
|
+
# commands can have dashes
|
15
|
+
cmd = cmd.gsub(/(\w)-/, '\1_')
|
16
|
+
|
17
|
+
if STOCK_COMMANDS.include?(cmd)
|
18
|
+
send("pass", args)
|
19
|
+
elsif method_defined?(cmd) and cmd != 'run' and cmd != 'pass'
|
20
|
+
args.shift
|
21
|
+
send(cmd, args)
|
22
|
+
else
|
23
|
+
send("help", args)
|
24
|
+
end
|
25
|
+
rescue Errno::ENOENT
|
26
|
+
if $!.message.include? "No such file or directory - vagrant"
|
27
|
+
abort "Error: `vagrant` command not found"
|
28
|
+
else
|
29
|
+
raise
|
30
|
+
end
|
31
|
+
rescue Errors::Error => err
|
32
|
+
abort "Error: #{err.message}"
|
33
|
+
end
|
34
|
+
|
35
|
+
# $ protobox init
|
36
|
+
def init(args)
|
37
|
+
require_relative 'command/init'
|
38
|
+
Command::Init.execute(args)
|
39
|
+
end
|
40
|
+
|
41
|
+
# $ protobox help
|
42
|
+
def help(args)
|
43
|
+
require_relative 'command/help'
|
44
|
+
Command::Help.execute(args)
|
45
|
+
end
|
46
|
+
|
47
|
+
# $ protobox version
|
48
|
+
def version(args)
|
49
|
+
puts Protobox::VERSION
|
50
|
+
end
|
51
|
+
|
52
|
+
# pass through
|
53
|
+
def pass(args)
|
54
|
+
require_relative 'command/passthrough'
|
55
|
+
Command::PassThrough.execute(args)
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
3
|
+
module Protobox
|
4
|
+
module Util
|
5
|
+
class Platform
|
6
|
+
class << self
|
7
|
+
|
8
|
+
def git
|
9
|
+
@git ||= if ENV['GIT'] and File.executable?(ENV['GIT'])
|
10
|
+
ENV['GIT']
|
11
|
+
elsif Context.command?('git')
|
12
|
+
'git'
|
13
|
+
else
|
14
|
+
s = `xcrun -find git 2>/dev/null`.chomp
|
15
|
+
s if $? and not s.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
return unless @git
|
19
|
+
|
20
|
+
# Github only supports HTTPS fetches on 1.7.10 or later:
|
21
|
+
# https://help.github.com/articles/https-cloning-errors
|
22
|
+
`#{@git} --version` =~ /git version (\d\.\d+\.\d+)/
|
23
|
+
return if $1.nil? or $1 < "1.7.10"
|
24
|
+
|
25
|
+
@git
|
26
|
+
end
|
27
|
+
|
28
|
+
def vagrant
|
29
|
+
@vagrant ||= if ENV['VAGRANT'] and File.executable(ENV['VAGRANT'])
|
30
|
+
ENV['VAGRANT']
|
31
|
+
elsif Context.command?('vagrant')
|
32
|
+
'vagrant'
|
33
|
+
else
|
34
|
+
s = `xcrun -find vagrant 2>/dev/null`.chomp
|
35
|
+
s if $? and not s.empty?
|
36
|
+
end
|
37
|
+
|
38
|
+
return unless @vagrant
|
39
|
+
|
40
|
+
@vagrant
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class Input
|
47
|
+
class << self
|
48
|
+
|
49
|
+
def get_input
|
50
|
+
STDIN.gets.chomp
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_char
|
54
|
+
begin
|
55
|
+
system("stty raw -echo")
|
56
|
+
str = STDIN.getc
|
57
|
+
ensure
|
58
|
+
system("stty -raw echo")
|
59
|
+
end
|
60
|
+
str.chr
|
61
|
+
end
|
62
|
+
|
63
|
+
def enter_or_abort
|
64
|
+
puts
|
65
|
+
puts "Press ENTER to continue or any other key to abort"
|
66
|
+
c = get_char
|
67
|
+
#p c
|
68
|
+
abort unless c == "\r"
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class System
|
75
|
+
class << self
|
76
|
+
|
77
|
+
PWD = Dir.pwd
|
78
|
+
|
79
|
+
def current_dir
|
80
|
+
PWD
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_exec(args)
|
84
|
+
args = Shellwords.shellwords(args) if args.respond_to? :to_str
|
85
|
+
Array(executable) + Array(args)
|
86
|
+
end
|
87
|
+
|
88
|
+
def command_to_string(cmd)
|
89
|
+
full_cmd = to_exec(cmd)
|
90
|
+
full_cmd.respond_to?(:shelljoin) ? full_cmd.shelljoin : full_cmd.join(' ')
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class Context
|
97
|
+
class << self
|
98
|
+
|
99
|
+
# Cross-platform web browser command; respects the value set in $BROWSER.
|
100
|
+
#
|
101
|
+
# Returns an array, e.g.: ['open']
|
102
|
+
def browser_launcher
|
103
|
+
browser = ENV['BROWSER'] || (
|
104
|
+
osx? ? 'open' : windows? ? %w[cmd /c start] :
|
105
|
+
%w[xdg-open cygstart x-www-browser firefox opera mozilla netscape].find { |comm| which comm }
|
106
|
+
)
|
107
|
+
|
108
|
+
abort "Please set $BROWSER to a web launcher to use this command." unless browser
|
109
|
+
Array(browser)
|
110
|
+
end
|
111
|
+
|
112
|
+
def osx?
|
113
|
+
require 'rbconfig'
|
114
|
+
RbConfig::CONFIG['host_os'].to_s.include?('darwin')
|
115
|
+
end
|
116
|
+
|
117
|
+
def windows?
|
118
|
+
require 'rbconfig'
|
119
|
+
RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw|windows/
|
120
|
+
end
|
121
|
+
|
122
|
+
def unix?
|
123
|
+
require 'rbconfig'
|
124
|
+
RbConfig::CONFIG['host_os'] =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
|
125
|
+
end
|
126
|
+
|
127
|
+
# Cross-platform way of finding an executable in the $PATH.
|
128
|
+
#
|
129
|
+
# which('ruby') #=> /usr/bin/ruby
|
130
|
+
def which(cmd)
|
131
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
132
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
133
|
+
exts.each { |ext|
|
134
|
+
exe = "#{path}/#{cmd}#{ext}"
|
135
|
+
return exe if File.executable? exe
|
136
|
+
}
|
137
|
+
end
|
138
|
+
return nil
|
139
|
+
end
|
140
|
+
|
141
|
+
# Checks whether a command exists on this system in the $PATH.
|
142
|
+
#
|
143
|
+
# name - The String name of the command to check for.
|
144
|
+
#
|
145
|
+
# Returns a Boolean.
|
146
|
+
def command?(name)
|
147
|
+
!which(name).nil?
|
148
|
+
end
|
149
|
+
|
150
|
+
def tmp_dir
|
151
|
+
ENV['TMPDIR'] || ENV['TEMP'] || '/tmp'
|
152
|
+
end
|
153
|
+
|
154
|
+
def terminal_width
|
155
|
+
if unix?
|
156
|
+
width = %x{stty size 2>#{NULL}}.split[1].to_i
|
157
|
+
width = %x{tput cols 2>#{NULL}}.to_i if width.zero?
|
158
|
+
else
|
159
|
+
width = 0
|
160
|
+
end
|
161
|
+
width < 10 ? 78 : width
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
data/protobox.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'protobox/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "protobox"
|
8
|
+
spec.version = Protobox::VERSION
|
9
|
+
spec.authors = ["Patrick Heeney"]
|
10
|
+
spec.email = ["patrickheeney@gmail.com"]
|
11
|
+
spec.summary = "Protobox CLI Tools"
|
12
|
+
spec.description = "Protobox CLI Tools"
|
13
|
+
spec.homepage = "http://getprotobox.com"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
#spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
#spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
#spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
#spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
root_path = File.dirname(__FILE__)
|
22
|
+
all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
|
23
|
+
all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
|
24
|
+
|
25
|
+
gitignore_path = File.join(root_path, ".gitignore")
|
26
|
+
gitignore = File.readlines(gitignore_path)
|
27
|
+
gitignore.map! { |line| line.chomp.strip }
|
28
|
+
gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
|
29
|
+
|
30
|
+
unignored_files = all_files.reject do |file|
|
31
|
+
# Ignore any directories, the gemspec only cares about files
|
32
|
+
next true if File.directory?(file)
|
33
|
+
|
34
|
+
# Ignore any paths that match anything in the gitignore. We do
|
35
|
+
# two tests here:
|
36
|
+
#
|
37
|
+
# - First, test to see if the entire path matches the gitignore.
|
38
|
+
# - Second, match if the basename does, this makes it so that things
|
39
|
+
# like '.DS_Store' will match sub-directories too (same behavior
|
40
|
+
# as git).
|
41
|
+
#
|
42
|
+
gitignore.any? do |ignore|
|
43
|
+
File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
|
44
|
+
File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
spec.files = unignored_files
|
49
|
+
spec.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
|
50
|
+
spec.require_path = 'lib'
|
51
|
+
|
52
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
53
|
+
#spec.add_development_dependency "rake"
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: protobox
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrick Heeney
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
description: Protobox CLI Tools
|
28
|
+
email:
|
29
|
+
- patrickheeney@gmail.com
|
30
|
+
executables:
|
31
|
+
- protobox
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- .gitignore
|
36
|
+
- Gemfile
|
37
|
+
- Gemfile.lock
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- bin/protobox
|
42
|
+
- lib/protobox.rb
|
43
|
+
- lib/protobox/cli.rb
|
44
|
+
- lib/protobox/command/help.rb
|
45
|
+
- lib/protobox/command/init.rb
|
46
|
+
- lib/protobox/command/passthrough.rb
|
47
|
+
- lib/protobox/commands.rb
|
48
|
+
- lib/protobox/errors.rb
|
49
|
+
- lib/protobox/util.rb
|
50
|
+
- lib/protobox/version.rb
|
51
|
+
- protobox.gemspec
|
52
|
+
homepage: http://getprotobox.com
|
53
|
+
licenses:
|
54
|
+
- MIT
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.2.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: Protobox CLI Tools
|
76
|
+
test_files: []
|