vagrant-templated 0.1.2

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 247f877832f380fcdab41739e48f3ab5efc68cf3
4
+ data.tar.gz: '05639944992e7a4f91c738a07d08f7e0ebe3faa4'
5
+ SHA512:
6
+ metadata.gz: ce291b4a1a994e1903fc4925c2397a19ac26df60a80a7a3a60b1d3d20ee0630a44dd7fa1162dc8d55b5d886e3b1a54ab19477545c9aeaf930beb615ef24bbdaf
7
+ data.tar.gz: 5491a031e7d820e91c21b037c62e5d282521027477ff1200ae577aea7cdd1bd1007b57785420bb1eeeeba756b4e23da5f90bbb9a972a25b0bfa8011f61366fa4
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /spec/tmp/*
11
+ *.gem
12
+ .vagrant
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.3
data/Berksfile ADDED
@@ -0,0 +1,6 @@
1
+ # Berksfile generated with https://github.com/afaundez/vagrant-templated
2
+
3
+ source 'https://supermarket.chef.io'
4
+
5
+ cookbook 'apt', '~> 6.1.0'
6
+ cookbook 'ruby_rbenv', '~> 1.2.0'
data/Berksfile.lock ADDED
@@ -0,0 +1,29 @@
1
+ DEPENDENCIES
2
+ apt (~> 6.1.0)
3
+ ruby_rbenv (~> 1.2.0)
4
+
5
+ GRAPH
6
+ apt (6.1.3)
7
+ build-essential (8.0.3)
8
+ mingw (>= 1.1)
9
+ seven_zip (>= 0.0.0)
10
+ compat_resource (12.19.0)
11
+ dmg (4.0.0)
12
+ git (6.1.0)
13
+ build-essential (>= 0.0.0)
14
+ dmg (>= 0.0.0)
15
+ yum-epel (>= 0.0.0)
16
+ mingw (2.0.1)
17
+ seven_zip (>= 0.0.0)
18
+ ohai (5.1.0)
19
+ ruby_build (1.1.0)
20
+ git (>= 0.0.0)
21
+ yum-epel (>= 0.0.0)
22
+ ruby_rbenv (1.2.1)
23
+ ruby_build (>= 1.1.0)
24
+ seven_zip (2.0.2)
25
+ windows (>= 1.2.2)
26
+ windows (3.1.1)
27
+ ohai (>= 4.0.0)
28
+ yum-epel (2.1.2)
29
+ compat_resource (>= 12.16.3)
data/CHANGELOG.md ADDED
@@ -0,0 +1,19 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
5
+ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.1.2] - 2017-08-04
10
+ ### Added
11
+ - Fix locale load
12
+
13
+ ## [0.1.0] - 2017-08-04
14
+ ### Added
15
+ - Fix gesmpec dependencies
16
+
17
+ ## [0.1.0] - 2017-08-04
18
+ ### Added
19
+ - Add init command with two templates: rails5 and vagrant-plugin
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at alvaro@faundez.net. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ group :development do
6
+ gem 'vagrant', git: 'https://github.com/mitchellh/vagrant.git'
7
+ end
8
+
9
+ group :plugins do
10
+ gemspec
11
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,127 @@
1
+ GIT
2
+ remote: https://github.com/mitchellh/vagrant.git
3
+ revision: 1a7bfc81cd11047a184587ba72f2c12d2c9d9540
4
+ specs:
5
+ vagrant (1.9.8.dev)
6
+ childprocess (~> 0.6.0)
7
+ erubis (~> 2.7.0)
8
+ hashicorp-checkpoint (~> 0.1.1)
9
+ i18n (>= 0.6.0, <= 0.8.0)
10
+ listen (~> 3.1.5)
11
+ log4r (~> 1.1.9, < 1.1.11)
12
+ net-scp (~> 1.2.0)
13
+ net-sftp (~> 2.1)
14
+ net-ssh (~> 4.1.0)
15
+ rb-kqueue (~> 0.2.0)
16
+ rest-client (>= 1.6.0, < 3.0)
17
+ ruby_dep (<= 1.3.1)
18
+ wdm (~> 0.1.0)
19
+ winrm (~> 2.1)
20
+ winrm-elevated (~> 1.1)
21
+ winrm-fs (~> 1.0)
22
+
23
+ PATH
24
+ remote: .
25
+ specs:
26
+ vagrant-templated (0.1.0)
27
+
28
+ GEM
29
+ remote: https://rubygems.org/
30
+ specs:
31
+ builder (3.2.3)
32
+ childprocess (0.6.3)
33
+ ffi (~> 1.0, >= 1.0.11)
34
+ diff-lcs (1.3)
35
+ domain_name (0.5.20170404)
36
+ unf (>= 0.0.5, < 1.0.0)
37
+ erubis (2.7.0)
38
+ ffi (1.9.18)
39
+ gssapi (1.2.0)
40
+ ffi (>= 1.0.1)
41
+ gyoku (1.3.1)
42
+ builder (>= 2.1.2)
43
+ hashicorp-checkpoint (0.1.4)
44
+ http-cookie (1.0.3)
45
+ domain_name (~> 0.5)
46
+ httpclient (2.8.3)
47
+ i18n (0.8.0)
48
+ listen (3.1.5)
49
+ rb-fsevent (~> 0.9, >= 0.9.4)
50
+ rb-inotify (~> 0.9, >= 0.9.7)
51
+ ruby_dep (~> 1.2)
52
+ little-plugger (1.1.4)
53
+ log4r (1.1.10)
54
+ logging (2.2.2)
55
+ little-plugger (~> 1.1)
56
+ multi_json (~> 1.10)
57
+ mime-types (3.1)
58
+ mime-types-data (~> 3.2015)
59
+ mime-types-data (3.2016.0521)
60
+ multi_json (1.12.1)
61
+ net-scp (1.2.1)
62
+ net-ssh (>= 2.6.5)
63
+ net-sftp (2.1.2)
64
+ net-ssh (>= 2.6.5)
65
+ net-ssh (4.1.0)
66
+ netrc (0.11.0)
67
+ nori (2.6.0)
68
+ rake (10.4.2)
69
+ rb-fsevent (0.10.2)
70
+ rb-inotify (0.9.10)
71
+ ffi (>= 0.5.0, < 2)
72
+ rb-kqueue (0.2.5)
73
+ ffi (>= 0.5.0)
74
+ rest-client (2.0.2)
75
+ http-cookie (>= 1.0.2, < 2.0)
76
+ mime-types (>= 1.16, < 4.0)
77
+ netrc (~> 0.8)
78
+ rspec (3.6.0)
79
+ rspec-core (~> 3.6.0)
80
+ rspec-expectations (~> 3.6.0)
81
+ rspec-mocks (~> 3.6.0)
82
+ rspec-core (3.6.0)
83
+ rspec-support (~> 3.6.0)
84
+ rspec-expectations (3.6.0)
85
+ diff-lcs (>= 1.2.0, < 2.0)
86
+ rspec-support (~> 3.6.0)
87
+ rspec-mocks (3.6.0)
88
+ diff-lcs (>= 1.2.0, < 2.0)
89
+ rspec-support (~> 3.6.0)
90
+ rspec-support (3.6.0)
91
+ ruby_dep (1.3.1)
92
+ rubyntlm (0.6.2)
93
+ rubyzip (1.2.1)
94
+ unf (0.1.4)
95
+ unf_ext
96
+ unf_ext (0.0.7.4)
97
+ wdm (0.1.1)
98
+ winrm (2.2.3)
99
+ builder (>= 2.1.2)
100
+ erubis (~> 2.7)
101
+ gssapi (~> 1.2)
102
+ gyoku (~> 1.0)
103
+ httpclient (~> 2.2, >= 2.2.0.2)
104
+ logging (>= 1.6.1, < 3.0)
105
+ nori (~> 2.0)
106
+ rubyntlm (~> 0.6.0, >= 0.6.1)
107
+ winrm-elevated (1.1.0)
108
+ winrm (~> 2.0)
109
+ winrm-fs (~> 1.0)
110
+ winrm-fs (1.0.1)
111
+ erubis (~> 2.7)
112
+ logging (>= 1.6.1, < 3.0)
113
+ rubyzip (~> 1.1)
114
+ winrm (~> 2.0)
115
+
116
+ PLATFORMS
117
+ ruby
118
+
119
+ DEPENDENCIES
120
+ bundler (~> 1.15)
121
+ rake (~> 10.0)
122
+ rspec (~> 3.6)
123
+ vagrant!
124
+ vagrant-templated!
125
+
126
+ BUNDLED WITH
127
+ 1.15.3
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Álvaro Faúndez
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # Vagrant Templated Plugin
2
+
3
+ Vagrant Templated is [Vagrant](https://www.vagrantup.com/downloads.html) plugin that add a new vagrant action to start a new Project. You will be able to choose between templates and start with a project with a Vagrantfile (and Berksfile) with cookbooks and configurations.
4
+
5
+ I started this gem because every time I start a new project, for production or just testing something, after the traditional vagrant init I had look in others projects looking for a specific configuration (for example, a Rails 5 project)
6
+
7
+ ## Installation
8
+
9
+ With vagrant:
10
+
11
+ ```shell
12
+ vagrant plugin install vagrant-templated
13
+ ```
14
+
15
+ To use the Vagranfile and Berksfile created, you will need [chefdk](https://downloads.chef.io/chefdk), [vagrant-berkshelf](https://github.com/berkshelf/vagrant-berkshelf) and [vagrant-omnibus](https://github.com/chef/vagrant-omnibus).
16
+
17
+
18
+ ## Usage
19
+
20
+ The new init action runs like this:
21
+
22
+ ```shell
23
+ vagrant templated init <template>
24
+ ```
25
+
26
+ The templates available at this moment are `rails5` and `vagrant-plugin`.
27
+
28
+ In both cases a Vagrantfile and a Berksfile will be generated where you executing the command.
29
+
30
+ Then, you just should `vagrant up` and enter the matrix.
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bundle install` to install dependencies. Then, run `bundle exec rake spec` to run the tests. Run `bundle exec vagrant templated init -h` and help will arise.
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/afaundes/vagrant-templated. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
43
+
44
+ ## Code of Conduct
45
+
46
+ Everyone interacting in the Vagrant::Templated project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/afaundes/vagrant-templated/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ begin
5
+ require 'rspec/core/rake_task'
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task default: :spec
8
+ rescue LoadError
9
+ # rspec not available
10
+ end
data/Vagrantfile ADDED
@@ -0,0 +1,40 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+ # Vagrantfile generated with https://github.com/afaundez/vagrant-templated
4
+
5
+ ["vagrant-omnibus", "vagrant-berkshelf"].each do |plugin_name|
6
+ unless Vagrant.has_plugin? plugin_name
7
+ raise "#{plugin_name} plugin is required. Please run `vagrant plugin install #{plugin_name}`"
8
+ end
9
+ end
10
+
11
+ Vagrant.configure('2') do |config|
12
+ config.vm.box = 'bento/ubuntu-16.04'
13
+ config.omnibus.chef_version = :latest
14
+ config.vm.provision :chef_solo do |chef|
15
+ chef.add_recipe 'apt'
16
+ chef.add_recipe 'ruby_build'
17
+ chef.add_recipe 'ruby_rbenv::user'
18
+
19
+ chef.json = {
20
+ "rbenv": {
21
+ "user_installs": [
22
+ {
23
+ "user": "vagrant",
24
+ "rubies": [
25
+ "2.3.4"
26
+ ],
27
+ "global": "2.3.4",
28
+ "gems": {
29
+ "2.3.4": [
30
+ {
31
+ "name": "bundler"
32
+ }
33
+ ]
34
+ }
35
+ }
36
+ ]
37
+ }
38
+ }
39
+ end
40
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'vagrant-templated'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ en:
2
+ vagrant:
3
+ errors:
4
+ vagrantfile_templated_exists: |-
5
+ A `Vagrantfile` already exists in this directory. Remove it before
6
+ running `vagrant templated init`.
7
+ berksfile_templated_exists: |-
8
+ A `Berksfile` already exists in this directory. Remove it before
9
+ running `vagrant templated init`.
10
+ vagrant_templated_option_not_found: |-
11
+ Option for template not available. Check templates availables
12
+ running `vagrant templated init --help`.
@@ -0,0 +1,102 @@
1
+ require 'optparse'
2
+
3
+ module Vagrant
4
+ module Templated
5
+ module Command
6
+ class Init < Vagrant.plugin('2', :command)
7
+
8
+ def execute
9
+ defaults = YAML.load_file File.join(File.dirname(File.expand_path(__FILE__)), '../templates/defaults.yml')
10
+ options = {}
11
+
12
+ opts = OptionParser.new do |o|
13
+ o.banner = 'Usage: vagrant templated init [options] <template>'
14
+
15
+ o.separator ''
16
+ o.separator 'Templates availables: rails'
17
+ o.separator ''
18
+ o.separator ' rails5'
19
+ o.separator ' vagrant-plugin'
20
+
21
+ o.separator ''
22
+ o.separator 'Options:'
23
+ o.separator ''
24
+
25
+ o.on('-f', '--force', 'Overwrite an existing box if it exists') do |f|
26
+ options[:force] = f
27
+ end
28
+
29
+ o.on('-s', '--suffix SUFFIX', String,
30
+ "Output suffix for Vagrantfile and Bersfile. '-' for stdout") do |suffix|
31
+ options[:suffix] = suffix
32
+ end
33
+ end
34
+
35
+ argv = parse_options(opts)
36
+ return if !argv
37
+ if argv.empty? || argv.length > 2
38
+ raise Vagrant::Errors::CLIInvalidUsage,
39
+ help: opts.help.chomp
40
+ end
41
+
42
+ template = argv[0]
43
+ if argv.length == 2
44
+ options[:name] = argv[0]
45
+ template = argv[1]
46
+ end
47
+
48
+ @env.ui.info("Detected template: #{template}", prefix: false, color: :yellow)
49
+ raise Vagrant::Errors::VagrantTemplatedOptionNotFound unless defaults.keys.include? template
50
+
51
+ vagrantfile_save_path = nil
52
+ berksfile_save_path = nil
53
+ if options[:suffix] != "-"
54
+ vagrantfile_save_path = Pathname.new(['Vagrantfile', options[:suffix]].compact.join('.')).expand_path(@env.cwd)
55
+ vagrantfile_save_path.delete if vagrantfile_save_path.exist? && options[:force]
56
+ raise Vagrant::Errors::VagrantfileTemplatedExistsError if vagrantfile_save_path.exist?
57
+ berksfile_save_path = Pathname.new(['Berksfile', options[:suffix]].compact.join('.')).expand_path(@env.cwd)
58
+ berksfile_save_path.delete if berksfile_save_path.exist? && options[:force]
59
+ raise Vagrant::Errors::BerksfileTemplatedExistsError if berksfile_save_path.exist?
60
+ end
61
+
62
+ vagrantfile = ERB.new File.read(File.join(File.dirname(__FILE__), '../templates/Vagrantfile.erb')), nil, '-'
63
+ berksfile = ERB.new File.read(File.join(File.dirname(__FILE__), '../templates/Berksfile.erb')), nil, '-'
64
+
65
+ contents = vagrantfile.result binding
66
+ if vagrantfile_save_path
67
+ begin
68
+ vagrantfile_save_path.open('w+') do |f|
69
+ f.write(contents)
70
+ end
71
+ rescue Errno::EACCES
72
+ raise Vagrant::Errors::VagrantfileWriteError
73
+ end
74
+
75
+ @env.ui.info('Templated Vagranfile created successfully', prefix: false)
76
+ else
77
+ @env.ui.info('VAGRANTFILE', prefix: false, color: :green)
78
+ @env.ui.info(contents, prefix: false)
79
+ end
80
+
81
+ contents = berksfile.result binding
82
+ if berksfile_save_path
83
+ begin
84
+ berksfile_save_path.open('w+') do |f|
85
+ f.write(contents)
86
+ end
87
+ rescue Errno::EACCES
88
+ raise Vagrant::Errors::BerksfileWriteError
89
+ end
90
+
91
+ @env.ui.info('Templated Berksfile created successfully', prefix: false)
92
+ else
93
+ @env.ui.info('BERKSFILE', prefix: false, color: :green)
94
+ @env.ui.info(contents, prefix: false)
95
+ end
96
+ @env.ui.info('Vagrant Templated finished successfully.', prefix: false, color: :green)
97
+ 0
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,59 @@
1
+ require 'optparse'
2
+
3
+ module Vagrant
4
+ module Templated
5
+ module Command
6
+ class Root < Vagrant.plugin('2', :command)
7
+
8
+ def initialize(argv, env)
9
+ super
10
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
11
+
12
+ @subcommands = Vagrant::Registry.new
13
+ @subcommands.register(:init) do
14
+ require File.expand_path('../init', __FILE__)
15
+ Init
16
+ end
17
+ end
18
+
19
+ def execute
20
+ if @main_args.include?('-h') || @main_args.include?('--help')
21
+ # Print the help for all the template commands.
22
+ return help
23
+ end
24
+
25
+ # If we reached this far then we must have a subcommand. If not,
26
+ # then we also just print the help and exit.
27
+ command_class = @subcommands.get(@sub_command.to_sym) if @sub_command
28
+ return help if !command_class || !@sub_command
29
+ @logger.debug("Invoking command class: #{command_class} #{@sub_args.inspect}")
30
+
31
+ # Initialize and execute the command class
32
+ command_class.new(@sub_args, @env).execute
33
+ end
34
+
35
+ def help
36
+ opts = OptionParser.new do |opts|
37
+ opts.banner = "Usage: vagrant templated <subcommand> [<args>]"
38
+ opts.separator ""
39
+ opts.separator "Available subcommands:"
40
+
41
+ # Add the available subcommands as separators in order to print them
42
+ # out as well.
43
+ keys = []
44
+ @subcommands.each { |key, value| keys << key.to_s }
45
+
46
+ keys.sort.each do |key|
47
+ opts.separator " #{key}"
48
+ end
49
+
50
+ opts.separator ""
51
+ opts.separator "For help on any individual subcommand run `vagrant templated <subcommand> -h`"
52
+ end
53
+
54
+ @env.ui.info(opts.help, prefix: false)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,15 @@
1
+ module Vagrant
2
+ module Errors
3
+ class VagrantfileTemplatedExistsError < VagrantError
4
+ error_key(:vagrantfile_templated_exists)
5
+ end
6
+
7
+ class BerksfileTemplatedExistsError < VagrantError
8
+ error_key(:berksfile_templated_exists)
9
+ end
10
+
11
+ class VagrantTemplatedOptionNotFound < VagrantError
12
+ error_key(:vagrant_templated_option_not_found)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Vagrant
2
+ module Templated
3
+ class Plugin < Vagrant.plugin('2')
4
+ name 'vagrant templated'
5
+ description 'The `templated` command gives you a way to init a project with a templated Vagrantfile'
6
+
7
+ command 'templated' do
8
+ require_relative 'command/root'
9
+ Command::Root
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ # Berksfile generated with https://github.com/afaundez/vagrant-templated
2
+
3
+ source 'https://supermarket.chef.io'
4
+
5
+ <%- defaults[template]['berkself']['cookbooks'].each do |name, version| -%>
6
+ cookbook '<%= name %>', '<%= version %>'
7
+ <%- end -%>
@@ -0,0 +1,26 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+ # Vagrantfile generated with https://github.com/afaundez/vagrant-templated
4
+
5
+ <%- if defaults[template]['require'] && defaults[template]['require']['vagrant-plugins'] -%>
6
+ <%= defaults[template]['require']['vagrant-plugins'].to_a %>.each do |plugin_name|
7
+ unless Vagrant.has_plugin? plugin_name
8
+ raise "#{plugin_name} plugin is required. Please run `vagrant plugin install #{plugin_name}`"
9
+ end
10
+ end
11
+ <%- end -%>
12
+
13
+ Vagrant.configure('2') do |config|
14
+ config.vm.box = 'bento/ubuntu-16.04'
15
+ config.omnibus.chef_version = :latest
16
+ config.vm.provision :chef_solo do |chef|
17
+ <%- defaults[template]['chef']['recipes'].each do |recipe| -%>
18
+ chef.add_recipe '<%= recipe %>'
19
+ <%- end -%>
20
+ <% lines = JSON.pretty_generate(defaults[template]['chef']['json']).lines %>
21
+ chef.json = <%= lines.shift.strip %>
22
+ <%- lines.each do |line| -%>
23
+ <%= line.rstrip %>
24
+ <%- end -%>
25
+ end
26
+ end
@@ -0,0 +1,58 @@
1
+ rails5:
2
+ berkself:
3
+ cookbooks:
4
+ apt: ~> 6.1.0
5
+ timezone-ii: ~> 0.2.0
6
+ ruby_rbenv: ~> 1.2.0
7
+ nodejs: ~> 4.0.0
8
+ postgresql: ~> 6.1.1
9
+ chef:
10
+ recipes:
11
+ - apt
12
+ - timezone-ii
13
+ - ruby_build
14
+ - ruby_rbenv::user
15
+ - nodejs
16
+ - postgresql::server
17
+ json:
18
+ tz: UTC
19
+ rbenv:
20
+ user_installs:
21
+ - user: vagrant
22
+ rubies:
23
+ - 2.4.1
24
+ global: 2.4.1
25
+ gems:
26
+ 2.4.1:
27
+ - name: bundler
28
+ postgresql:
29
+ password:
30
+ postgres: password
31
+ require:
32
+ vagrant-plugins:
33
+ - vagrant-omnibus
34
+ - vagrant-berkshelf
35
+ vagrant-plugin:
36
+ berkself:
37
+ cookbooks:
38
+ apt: ~> 6.1.0
39
+ ruby_rbenv: ~> 1.2.0
40
+ chef:
41
+ recipes:
42
+ - apt
43
+ - ruby_build
44
+ - ruby_rbenv::user
45
+ json:
46
+ rbenv:
47
+ user_installs:
48
+ - user: vagrant
49
+ rubies:
50
+ - 2.3.4
51
+ global: 2.3.4
52
+ gems:
53
+ 2.3.4:
54
+ - name: bundler
55
+ require:
56
+ vagrant-plugins:
57
+ - vagrant-omnibus
58
+ - vagrant-berkshelf
@@ -0,0 +1,5 @@
1
+ module Vagrant
2
+ module Templated
3
+ VERSION = '0.1.2'
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ begin
2
+ require 'vagrant'
3
+ rescue LoadError
4
+ Bundler.require(:default, :development)
5
+ end
6
+
7
+ require 'vagrant-templated/version'
8
+ require 'vagrant-templated/plugin'
9
+ require 'vagrant-templated/errors'
10
+ require 'vagrant-templated/command/root'
11
+ require 'vagrant-templated/command/init'
12
+
13
+ require 'erb'
14
+ require 'yaml'
15
+ require 'i18n'
16
+ I18n.load_path << Dir.glob(File.join(File.dirname(File.expand_path(__FILE__)), "../config/locales/*.{rb,yml}"))
@@ -0,0 +1,3 @@
1
+ require 'rspec'
2
+ require 'securerandom'
3
+ require_relative '../lib/vagrant-templated'
data/spec/tmp/.keep ADDED
File without changes
@@ -0,0 +1,136 @@
1
+ require_relative 'spec_helper'
2
+ require 'stringio'
3
+
4
+ describe Vagrant::Templated::Command::Init do
5
+
6
+ before :context do
7
+ @tmp = File.join File.dirname(__FILE__), 'tmp'
8
+ end
9
+
10
+ before :example do
11
+ @cwd = File.join @tmp, SecureRandom.urlsafe_base64
12
+ FileUtils.mkdir_p @cwd
13
+ @env = Vagrant::Environment.new cwd: @cwd
14
+ @vagrantfile = File.join @cwd, 'Vagrantfile'
15
+ @berksfile = File.join @cwd, 'Berksfile'
16
+ end
17
+
18
+ after :example do
19
+ FileUtils.rm_rf @cwd
20
+ end
21
+
22
+ it 'should have a version number' do
23
+ expect(::Vagrant::Templated::VERSION).to be_truthy
24
+ end
25
+
26
+ it 'should display help whitout any argument' do
27
+ expect{
28
+ described_class.new([], @env).execute
29
+ }.to raise_error Vagrant::Errors::CLIInvalidUsage
30
+ end
31
+
32
+ context 'when asking for help' do
33
+
34
+ it 'should display usage' do
35
+ usage = /Usage: vagrant templated init \[options\] <template>/
36
+ expect{
37
+ described_class.new(['-h'], @env).execute
38
+ }.to output(usage).to_stdout_from_any_process
39
+ end
40
+
41
+ end
42
+
43
+ context 'when using a valid template' do
44
+
45
+ it 'should raise error if Vagrantfile exists' do
46
+ FileUtils.touch @vagrantfile
47
+ expect{
48
+ described_class.new(['rails5'], @env).execute
49
+ }.to raise_error Vagrant::Errors::VagrantfileTemplatedExistsError
50
+ end
51
+
52
+ let(:vagrantfile_tag) { '# Vagrantfile generated with ' \
53
+ 'https://github.com/afaundez/vagrant-templated'
54
+ }
55
+ let(:berksfile_tag) { '# Berksfile generated with ' \
56
+ 'https://github.com/afaundez/vagrant-templated'
57
+ }
58
+
59
+ it 'should raise error if Berksfile exists' do
60
+ FileUtils.touch @berksfile
61
+ expect{
62
+ described_class.new(['rails5'], @env).execute
63
+ }.to raise_error Vagrant::Errors::BerksfileTemplatedExistsError
64
+ end
65
+
66
+ it 'should create Vagrantfile and Berksfile if both do not exist' do
67
+ expect{
68
+ described_class.new(['rails5'], @env).execute
69
+ }.to_not raise_error
70
+ expect(File.open(@vagrantfile).read).to include(vagrantfile_tag)
71
+ expect(File.open(@berksfile).read).to include(berksfile_tag)
72
+ end
73
+
74
+ context 'and using a suffix' do
75
+
76
+ it 'should create Vagrantfile and Berksfile if both do not exist' do
77
+ suffix = 'custom-sufix'
78
+ expect{
79
+ described_class.new(['rails5', '--suffix', suffix], @env).execute
80
+ }.to_not raise_error
81
+ tag_vagrantfile = [@vagrantfile, suffix].join('.')
82
+ expect(File.open(tag_vagrantfile).read).to include(vagrantfile_tag)
83
+ tag_berksfile = [@berksfile, suffix].join('.')
84
+ expect(File.open(tag_berksfile).read).to include(berksfile_tag)
85
+ end
86
+
87
+ end
88
+
89
+ context 'and forcing' do
90
+
91
+ it 'should replace existing Vagrantfile' do
92
+ FileUtils.touch File.join(@cwd, 'Vagrantfile')
93
+ args = ['rails5', '--force']
94
+ expect{
95
+ described_class.new(args, @env).execute
96
+ }.to_not raise_error
97
+ expect(File.open(@vagrantfile).read).to include(vagrantfile_tag)
98
+ expect(File.open(@berksfile).read).to include(berksfile_tag)
99
+ end
100
+
101
+ it 'should replace existing Berksfile' do
102
+ FileUtils.touch File.join(@cwd, 'Berksfile')
103
+ args = ['rails5', '--force']
104
+ expect{
105
+ described_class.new(args, @env).execute
106
+ }.to_not raise_error
107
+ expect(File.open(@vagrantfile).read).to include(vagrantfile_tag)
108
+ expect(File.open(@berksfile).read).to include(berksfile_tag)
109
+ end
110
+
111
+ it 'should replace existing Vagrantfile and Berksfile' do
112
+ FileUtils.touch File.join(@cwd, 'Vagrantfile')
113
+ FileUtils.touch File.join(@cwd, 'Berksfile')
114
+ args = ['rails5', '--force']
115
+ expect{
116
+ described_class.new(args, @env).execute
117
+ }.to_not raise_error
118
+ expect(File.open(@vagrantfile).read).to include(vagrantfile_tag)
119
+ expect(File.open(@berksfile).read).to include(berksfile_tag)
120
+ end
121
+
122
+ end
123
+
124
+ end
125
+
126
+ context 'when using a invalid template' do
127
+
128
+ it 'should raise an error' do
129
+ expect{
130
+ described_class.new(['fake-template'], @env).execute
131
+ }.to raise_error Vagrant::Errors::VagrantTemplatedOptionNotFound
132
+ end
133
+
134
+ end
135
+
136
+ end
@@ -0,0 +1,69 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'vagrant-templated/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'vagrant-templated'
8
+ spec.version = Vagrant::Templated::VERSION
9
+ spec.authors = ['Álvaro Faúndez']
10
+ spec.email = ['alvaro@faundez.net']
11
+
12
+ spec.summary = %q{Enable Vagrant to init with a Vagrantfile and Berksfile with specific configurations}
13
+ spec.description = %q{Enable Vagrant to init with a Vagrantfile and Berksfile with specific configurations like Rails 5 and Vagrant Plugin}
14
+ spec.homepage = 'https://github.com/afaundez/vagrant-templated'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ else
22
+ raise 'RubyGems 2.0 or newer is required to protect against ' \
23
+ 'public gem pushes.'
24
+ end
25
+
26
+ spec.add_development_dependency 'bundler', '~> 1.15'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'rspec', '~> 3.6'
29
+
30
+ # spec.bindir = 'exe'
31
+
32
+
33
+ # spec.files = `git ls-files -z`.split("\x0").reject do |f|
34
+ # f.match(%r{^(test|spec|features)/})
35
+ # end
36
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
37
+ # spec.require_paths = ['lib']
38
+
39
+ # copied from
40
+ root_path = File.dirname(__FILE__)
41
+ all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
42
+ all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
43
+ gitignore_path = File.join(root_path, ".gitignore")
44
+ gitignore = File.readlines(gitignore_path)
45
+ gitignore.map! { |line| line.chomp.strip }
46
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
47
+
48
+ unignored_files = all_files.reject do |file|
49
+ # Ignore any directories, the gemspec only cares about files
50
+ next true if File.directory?(file)
51
+
52
+ # Ignore any paths that match anything in the gitignore. We do
53
+ # two tests here:
54
+ #
55
+ # - First, test to see if the entire path matches the gitignore.
56
+ # - Second, match if the basename does, this makes it so that things
57
+ # like '.DS_Store' will match sub-directories too (same behavior
58
+ # as git).
59
+ #
60
+ gitignore.any? do |ignore|
61
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
62
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
63
+ end
64
+ end
65
+
66
+ spec.files = unignored_files
67
+ spec.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
68
+ spec.require_path = 'lib'
69
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-templated
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Álvaro Faúndez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-04 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.6'
55
+ description: Enable Vagrant to init with a Vagrantfile and Berksfile with specific
56
+ configurations like Rails 5 and Vagrant Plugin
57
+ email:
58
+ - alvaro@faundez.net
59
+ executables:
60
+ - console
61
+ - setup
62
+ extensions: []
63
+ extra_rdoc_files: []
64
+ files:
65
+ - ".gitignore"
66
+ - ".travis.yml"
67
+ - Berksfile
68
+ - Berksfile.lock
69
+ - CHANGELOG.md
70
+ - CODE_OF_CONDUCT.md
71
+ - Gemfile
72
+ - Gemfile.lock
73
+ - LICENSE.txt
74
+ - README.md
75
+ - Rakefile
76
+ - Vagrantfile
77
+ - bin/console
78
+ - bin/setup
79
+ - config/locales/en.yml
80
+ - lib/vagrant-templated.rb
81
+ - lib/vagrant-templated/command/init.rb
82
+ - lib/vagrant-templated/command/root.rb
83
+ - lib/vagrant-templated/errors.rb
84
+ - lib/vagrant-templated/plugin.rb
85
+ - lib/vagrant-templated/templates/Berksfile.erb
86
+ - lib/vagrant-templated/templates/Vagrantfile.erb
87
+ - lib/vagrant-templated/templates/defaults.yml
88
+ - lib/vagrant-templated/version.rb
89
+ - spec/spec_helper.rb
90
+ - spec/tmp/.keep
91
+ - spec/vagrant_templated_spec.rb
92
+ - vagrant-templated.gemspec
93
+ homepage: https://github.com/afaundez/vagrant-templated
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ allowed_push_host: 'TODO: Set to ''http://mygemserver.com'''
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: '0'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.5.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Enable Vagrant to init with a Vagrantfile and Berksfile with specific configurations
118
+ test_files: []