proviso 0.1.0

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.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Tom Wilson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "proviso"
8
+ gem.summary = %Q{Proviso is a cli for provisioning servers}
9
+ gem.description = %Q{Proviso is a cli plugin system that focuses on provisioning servers, but you can create plugins for anything.}
10
+ gem.email = "tom@jackhq.com"
11
+ gem.homepage = "http://github.com/jackhq/proviso"
12
+ gem.authors = ["Tom Wilson"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'spec/rake/spectask'
22
+ Spec::Rake::SpecTask.new(:spec) do |spec|
23
+ spec.libs << 'lib' << 'spec'
24
+ spec.spec_files = FileList['spec/**/*_spec.rb']
25
+ end
26
+
27
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
28
+ spec.libs << 'lib' << 'spec'
29
+ spec.pattern = 'spec/**/*_spec.rb'
30
+ spec.rcov = true
31
+ end
32
+
33
+ task :spec => :check_dependencies
34
+
35
+ begin
36
+ require 'reek/adapters/rake_task'
37
+ Reek::RakeTask.new do |t|
38
+ t.fail_on_error = true
39
+ t.verbose = false
40
+ t.source_files = 'lib/**/*.rb'
41
+ end
42
+ rescue LoadError
43
+ task :reek do
44
+ abort "Reek is not available. In order to run reek, you must: sudo gem install reek"
45
+ end
46
+ end
47
+
48
+ begin
49
+ require 'roodi'
50
+ require 'roodi_task'
51
+ RoodiTask.new do |t|
52
+ t.verbose = false
53
+ end
54
+ rescue LoadError
55
+ task :roodi do
56
+ abort "Roodi is not available. In order to run roodi, you must: sudo gem install roodi"
57
+ end
58
+ end
59
+
60
+ task :default => :spec
61
+
62
+ require 'rake/rdoctask'
63
+ Rake::RDocTask.new do |rdoc|
64
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
65
+
66
+ rdoc.rdoc_dir = 'rdoc'
67
+ rdoc.title = "proviso #{version}"
68
+ rdoc.rdoc_files.include('README*')
69
+ rdoc.rdoc_files.include('lib/**/*.rb')
70
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/proviso ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib')
6
+
7
+ require 'proviso'
8
+ require 'proviso/command'
9
+
10
+ args = ARGV.dup
11
+ ARGV.clear
12
+ command = args.shift.strip rescue 'help'
13
+
14
+ Proviso::Command.run(command, args)
@@ -0,0 +1,41 @@
1
+ require 'helpers'
2
+ require 'plugin'
3
+
4
+ require 'commands/base'
5
+
6
+
7
+ Dir["#{File.dirname(__FILE__)}/commands/*"].each { |c| require c }
8
+
9
+ module Proviso
10
+ module Command
11
+ class InvalidCommand < RuntimeError; end
12
+ class CommandFailed < RuntimeError; end
13
+
14
+ class << self
15
+ def run(command, args=[])
16
+ Proviso::Plugin.load!
17
+ run_internal(command, args)
18
+ end
19
+
20
+ def error(msg)
21
+ STDERR.puts(msg)
22
+ exit 1
23
+ end
24
+
25
+
26
+ private
27
+ def run_internal(command, args)
28
+ klass, method = parse(command)
29
+ runner = klass.new(args)
30
+ raise InvalidCommand unless runner.respond_to?(method)
31
+ runner.send(method)
32
+ end
33
+
34
+ def parse(command)
35
+ parts = command.split(':')
36
+ return Proviso::Command.const_get(parts.first.capitalize), parts.last
37
+ end
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,46 @@
1
+ require 'plugin_interface'
2
+
3
+ module Proviso::Command
4
+ class Base
5
+ include Proviso::Helpers
6
+ include Proviso::PluginInterface
7
+
8
+ attr_accessor :args
9
+
10
+ def initialize(args)
11
+ @args = args
12
+ end
13
+
14
+ def display(msg, newline=true)
15
+ if newline
16
+ puts(msg)
17
+ else
18
+ print(msg)
19
+ STDOUT.flush
20
+ end
21
+ end
22
+
23
+ def error(msg)
24
+ Proviso::Command.error(msg)
25
+ end
26
+
27
+ def extract_option(options, default=true)
28
+ values = options.is_a?(Array) ? options : [options]
29
+ return unless opt_index = args.select { |a| values.include? a }.first
30
+ opt_position = args.index(opt_index) + 1
31
+ if args.size > opt_position && opt_value = args[opt_position]
32
+ if opt_value.include?('--')
33
+ opt_value = nil
34
+ else
35
+ args.delete_at(opt_position)
36
+ end
37
+ end
38
+ opt_value ||= default
39
+ args.delete(opt_index)
40
+ block_given? ? yield(opt_value) : opt_value
41
+ end
42
+
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,11 @@
1
+ module Proviso::Command
2
+ class Hello < Base
3
+ def world
4
+ "Hello World"
5
+ end
6
+
7
+ end
8
+
9
+ end
10
+
11
+
@@ -0,0 +1,25 @@
1
+ module Proviso::Command
2
+ class Plugins < Base
3
+ def list
4
+ ::Proviso::Plugin.list.each do |plugin|
5
+ display plugin
6
+ end
7
+ end
8
+ alias :index :list
9
+
10
+ def install
11
+ plugin = Proviso::Plugin.new(@args.shift)
12
+ if plugin.install
13
+ display "#{plugin} installed"
14
+ else
15
+ error "Could not install #{plugin}. Please check the URL and try again"
16
+ end
17
+ end
18
+
19
+ def uninstall
20
+ plugin = Proviso::Plugin.new(@args.shift)
21
+ plugin.uninstall
22
+ display "#{plugin} uninstalled"
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # borrowed from heroku
2
+
3
+ module Proviso
4
+ module Helpers
5
+ def home_directory
6
+ running_on_windows? ? ENV['USERPROFILE'] : ENV['HOME']
7
+ end
8
+
9
+ def running_on_windows?
10
+ RUBY_PLATFORM =~ /mswin32|mingw32/
11
+ end
12
+
13
+ def running_on_a_mac?
14
+ RUBY_PLATFORM =~ /-darwin\d/
15
+ end
16
+ end
17
+ end
18
+
19
+ unless String.method_defined?(:shellescape)
20
+ class String
21
+ def shellescape
22
+ empty? ? "''" : gsub(/([^A-Za-z0-9_\-.,:\/@\n])/n, '\\\\\\1').gsub(/\n/, "'\n'")
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,66 @@
1
+ # based on the Heroku and Rails Plugin
2
+ require 'fileutils'
3
+
4
+ module Proviso
5
+ class Plugin
6
+ class << self
7
+ include Proviso::Helpers
8
+ end
9
+
10
+ attr_reader :name, :uri
11
+
12
+ def self.directory
13
+ "#{home_directory}/.proviso/plugins"
14
+ end
15
+
16
+ def self.list
17
+ Dir["#{directory}/*"].map do |folder|
18
+ File.basename(folder)
19
+ end
20
+ end
21
+
22
+ def self.load!
23
+ list.each do |plugin|
24
+ folder = "#{self.directory}/#{plugin}"
25
+ $: << "#{folder}/lib" if File.directory? "#{folder}/lib"
26
+ load "#{folder}/init.rb" if File.exists? "#{folder}/init.rb"
27
+ end
28
+ end
29
+
30
+ def initialize(uri)
31
+ @uri = uri
32
+ guess_name(uri)
33
+ end
34
+
35
+ def to_s
36
+ name
37
+ end
38
+
39
+ def path
40
+ "#{self.class.directory}/#{name}"
41
+ end
42
+
43
+ def install
44
+ FileUtils.mkdir_p(path)
45
+ Dir.chdir(path) do
46
+ system("git init > /dev/null 2>&1")
47
+ if !system("git pull --depth 1 #{uri} > /dev/null 2>&1")
48
+ FileUtils.rm_rf path
49
+ return false
50
+ end
51
+ end
52
+ true
53
+ end
54
+
55
+ def uninstall
56
+ FileUtils.rm_r path if File.directory?(path)
57
+ end
58
+
59
+ private
60
+ def guess_name(url)
61
+ @name = File.basename(url)
62
+ @name = File.basename(File.dirname(url)) if @name.empty?
63
+ @name.gsub!(/\.git$/, '') if @name =~ /\.git$/
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,27 @@
1
+ module Proviso::PluginInterface
2
+
3
+ def self.included(base)
4
+ base.extend Proviso::PluginInterface
5
+ end
6
+
7
+ def selected_application
8
+ base_command.extract_app
9
+ rescue Proviso::Command::CommandFailed
10
+ nil
11
+ end
12
+
13
+ def applications
14
+ @applications ||= (base_command.git_remotes(Dir.pwd) || []).inject({}) do |hash, (remote, app)|
15
+ hash.update(app => remote)
16
+ end
17
+ end
18
+
19
+ def command(command, *args)
20
+ Proviso::Command.run_internal command.to_s, args
21
+ end
22
+
23
+ def base_command
24
+ @base_command ||= Proviso::Command::Base.new(ARGV)
25
+ end
26
+
27
+ end
data/lib/proviso.rb ADDED
@@ -0,0 +1,5 @@
1
+
2
+ module Proviso; end
3
+
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/proviso')
5
+
data/proviso.gemspec ADDED
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{proviso}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Tom Wilson"]
12
+ s.date = %q{2010-08-15}
13
+ s.default_executable = %q{proviso}
14
+ s.description = %q{Proviso is a cli plugin system that focuses on provisioning servers, but you can create plugins for anything.}
15
+ s.email = %q{tom@jackhq.com}
16
+ s.executables = ["proviso"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE"
19
+ ]
20
+ s.files = [
21
+ ".document",
22
+ ".gitignore",
23
+ "LICENSE",
24
+ "Rakefile",
25
+ "VERSION",
26
+ "bin/proviso",
27
+ "lib/proviso.rb",
28
+ "lib/proviso/command.rb",
29
+ "lib/proviso/commands/base.rb",
30
+ "lib/proviso/commands/hello.rb",
31
+ "lib/proviso/commands/plugins.rb",
32
+ "lib/proviso/helpers.rb",
33
+ "lib/proviso/plugin.rb",
34
+ "lib/proviso/plugin_interface.rb",
35
+ "proviso.gemspec",
36
+ "readme.md",
37
+ "spec/fixtures/proviso.yml",
38
+ "spec/proviso/command_spec.rb",
39
+ "spec/proviso/commands/base_spec.rb",
40
+ "spec/proviso_spec.rb",
41
+ "spec/spec.opts",
42
+ "spec/spec_helper.rb"
43
+ ]
44
+ s.homepage = %q{http://github.com/jackhq/proviso}
45
+ s.rdoc_options = ["--charset=UTF-8"]
46
+ s.require_paths = ["lib"]
47
+ s.rubygems_version = %q{1.3.7}
48
+ s.summary = %q{Proviso is a cli for provisioning servers}
49
+ s.test_files = [
50
+ "spec/proviso/command_spec.rb",
51
+ "spec/proviso/commands/base_spec.rb",
52
+ "spec/proviso_spec.rb",
53
+ "spec/spec_helper.rb"
54
+ ]
55
+
56
+ if s.respond_to? :specification_version then
57
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
58
+ s.specification_version = 3
59
+
60
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
61
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
62
+ else
63
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
64
+ end
65
+ else
66
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
67
+ end
68
+ end
69
+
data/readme.md ADDED
@@ -0,0 +1,17 @@
1
+ = proviso
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Tom Wilson. See LICENSE for details.
@@ -0,0 +1,14 @@
1
+ ---
2
+ ec2:
3
+ image_id: ami-2d4aa444
4
+ availability_zone: us-east-1c
5
+ key_name: ec2-keypair
6
+ security_group: default
7
+ max_count: 1
8
+
9
+ zerigo:
10
+ user: user
11
+ password: password
12
+ type: A
13
+ ttl: 15000
14
+
@@ -0,0 +1,26 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe "Proviso Command" do
4
+ before(:each) do
5
+ #hash = {"ec2" => {"image_id"=>"ami-2d4aa444", "availability_zone"=>"us-east-1c", "key_name"=>"ec2-keypair", "security_group"=>"default", "max_count"=>1}}
6
+ #YAML.stub!(:load_file).and_return(hash)
7
+ end
8
+
9
+ it "should return hello world" do
10
+ Proviso::Command.run('hello:world').should == "Hello World"
11
+ end
12
+
13
+ it "should return error on hello:foobar" do
14
+ lambda { Proviso::Command.run('hello:foobar') }.should raise_error
15
+ end
16
+
17
+ # it "should return status of instance" do
18
+ # Proviso::Command.run('ec2:status',['i-3d8b0157'])
19
+ # end
20
+ #
21
+ # it "should link server " do
22
+ # Proviso::Command.run('zerigo:link',['staging.example.com','127.0.0.1'])
23
+ #
24
+ # end
25
+
26
+ end
@@ -0,0 +1,47 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "Proviso Base Command" do
4
+ it "should display" do
5
+ @base = Proviso::Command::Base.new([])
6
+ @base.display("Hello World")
7
+
8
+ end
9
+
10
+ it "should error" do
11
+ Proviso::Command.should_receive(:error).and_return("I see an error")
12
+ Proviso::Command::Base.new([]).error("I see an error")
13
+ end
14
+
15
+ context "option parsing" do
16
+ before(:each) do
17
+ @base = Proviso::Command::Base.new([])
18
+ end
19
+
20
+ it "extracts options from args" do
21
+ @base.stub!(:args).and_return(%w( a b --something value c d ))
22
+ @base.extract_option('--something').should == 'value'
23
+ end
24
+
25
+ it "accepts options without value" do
26
+ @base.stub!(:args).and_return(%w( a b --something))
27
+ @base.extract_option('--something').should be_true
28
+ end
29
+
30
+ it "doesn't consider parameters as a value" do
31
+ @base.stub!(:args).and_return(%w( a b --something --something-else c d))
32
+ @base.extract_option('--something').should be_true
33
+ end
34
+
35
+ it "accepts a default value" do
36
+ @base.stub!(:args).and_return(%w( a b --something))
37
+ @base.extract_option('--something', 'default').should == 'default'
38
+ end
39
+
40
+ it "is not affected by multiple arguments with the same value" do
41
+ @base.stub!(:args).and_return(%w( --arg1 val --arg2 val ))
42
+ @base.extract_option('--arg1').should == 'val'
43
+ @base.args.should == ['--arg2', 'val']
44
+ end
45
+ end
46
+
47
+ end
@@ -0,0 +1,8 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Proviso" do
4
+ it "fails" do
5
+ true.should == true
6
+ #fail "hey buddy, you should probably rename this file and start specing for real"
7
+ end
8
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'proviso'
4
+ require 'proviso/command'
5
+
6
+ require 'spec'
7
+ require 'spec/autorun'
8
+
9
+
10
+
11
+ Spec::Runner.configure do |config|
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: proviso
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Tom Wilson
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-08-15 00:00:00 -04:00
18
+ default_executable: proviso
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 1
30
+ - 2
31
+ - 9
32
+ version: 1.2.9
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Proviso is a cli plugin system that focuses on provisioning servers, but you can create plugins for anything.
36
+ email: tom@jackhq.com
37
+ executables:
38
+ - proviso
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ files:
44
+ - .document
45
+ - .gitignore
46
+ - LICENSE
47
+ - Rakefile
48
+ - VERSION
49
+ - bin/proviso
50
+ - lib/proviso.rb
51
+ - lib/proviso/command.rb
52
+ - lib/proviso/commands/base.rb
53
+ - lib/proviso/commands/hello.rb
54
+ - lib/proviso/commands/plugins.rb
55
+ - lib/proviso/helpers.rb
56
+ - lib/proviso/plugin.rb
57
+ - lib/proviso/plugin_interface.rb
58
+ - proviso.gemspec
59
+ - readme.md
60
+ - spec/fixtures/proviso.yml
61
+ - spec/proviso/command_spec.rb
62
+ - spec/proviso/commands/base_spec.rb
63
+ - spec/proviso_spec.rb
64
+ - spec/spec.opts
65
+ - spec/spec_helper.rb
66
+ has_rdoc: true
67
+ homepage: http://github.com/jackhq/proviso
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --charset=UTF-8
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirements: []
92
+
93
+ rubyforge_project:
94
+ rubygems_version: 1.3.7
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Proviso is a cli for provisioning servers
98
+ test_files:
99
+ - spec/proviso/command_spec.rb
100
+ - spec/proviso/commands/base_spec.rb
101
+ - spec/proviso_spec.rb
102
+ - spec/spec_helper.rb