vagrant-shortcuts 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6e94cfdd7ea4c44cfd7229753110286711a8d56d
4
- data.tar.gz: bd63397478fadfe26c7063db0967367a3610c932
3
+ metadata.gz: 71d2c0e6f8bcb8ac7e62e3759b0fcd3d1adf87d8
4
+ data.tar.gz: baac53ae8c2bd4c46879822dcbd551a0435aad7c
5
5
  SHA512:
6
- metadata.gz: 9c1460c365caa674562192e88114f6d047e6ce597d2c1eb26191d228558625b04671a2a244932524ee358be6283076d32cd0d90a77101ca3fe5d84817674473a
7
- data.tar.gz: 0363294843abab4f01b45613d3238480e219bc60b9b9a3f30dcd0a537f5b9db5add022c18c6de6a3a3433c0718f9db4ccb51cfa7aef601c528d92a16c5a8523d
6
+ metadata.gz: 817dfc4ce02cebd664f8a098845fefba8753ab4fe88e1a71a8459eacc89015fd5b93fa01d2071266b284f2073b257085a3ed861212e3c1ac89dd2a2ea9dd4c7f
7
+ data.tar.gz: 2a3e0e12abc1087778d732572395295c149d3730f39ab0e3868dd5de503279a5a21997871bcded76ea878f06d9af6e3f3c3c96295240b24b36967196bbd67bce
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
@@ -2,57 +2,107 @@ require "vagrant-shortcuts/version"
2
2
 
3
3
  module VagrantPlugins
4
4
 
5
- class Shortcut
6
- def initialize(callable, start_machine: true)
7
- @callable = callable
8
- @start_machine = start_machine
5
+ module Shortcuts
6
+
7
+ # Get some i18n going
8
+ def self.setup_i18n
9
+ I18n.load_path << File.expand_path('locales/en.yml', source_root)
10
+ I18n.reload!
9
11
  end
10
12
 
11
- def call(machine)
12
- if @start_machine
13
- machine.action(:up, {:provision_ignore_sentinel => false})
14
- end
15
- @callable.call(machine)
13
+ def self.source_root
14
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
16
15
  end
17
- end
18
16
 
19
- class Shortcuts < Vagrant.plugin("2")
20
- name "Shortcuts plugin"
17
+ # `Shortcut` handles running shortcuts and any associated options
18
+ class Shortcut
19
+ def initialize(callable, start_machine: true)
20
+ @callable = callable
21
+ @start_machine = start_machine
22
+ end
21
23
 
22
- command "do" do
23
- class Command < Vagrant.plugin("2", :command)
24
- def initialize(argv, env)
25
- super
26
- @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
24
+ def call(machine)
25
+ if @start_machine
26
+ machine.action(:up, {:provision_ignore_sentinel => false})
27
27
  end
28
+ @callable.call(machine)
29
+ end
30
+ end
31
+
32
+ class Plugin < Vagrant.plugin("2")
33
+ name "Shortcuts plugin"
34
+ description <<-DESC
35
+ This plugin allows defining shortcut commands in a Vagrantfile
36
+ DESC
37
+
38
+ # Where the real work is done: Running a shortcut
39
+ command "do" do
40
+ class Command < Vagrant.plugin("2", :command)
41
+ def initialize(argv, env)
42
+ super
43
+ @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv)
44
+
45
+ # Not a great spot for this, but I dont know where else to put it.
46
+ Shortcuts.setup_i18n
47
+ end
48
+
49
+ def execute
50
+ with_target_vms(@sub_args) do |machine|
51
+
52
+ if @sub_command == nil
53
+ raise MissingShortcutError.new
54
+ end
55
+
56
+ shortcut_name = @sub_command.to_sym
57
+ shortcuts = machine.config.shortcuts
58
+
59
+ if not shortcuts.has?(shortcut_name)
60
+ raise UnknownShortcutError.new shortcut: shortcut_name
61
+ end
28
62
 
29
- def execute
30
- with_target_vms(@sub_args) do |machine|
31
- shortcut_name = @sub_command.to_sym
32
- shortcut = machine.config.shortcuts.get(shortcut_name)
33
- shortcut.call(machine)
63
+ shortcut = machine.config.shortcuts.get(shortcut_name)
64
+ shortcut.call(machine)
65
+ end
66
+ 0
34
67
  end
35
- 0
36
68
  end
69
+ Command
37
70
  end
38
- Command
39
- end
40
71
 
41
- config "shortcuts" do
42
- class Config < Vagrant.plugin(2, :config)
43
- attr_accessor :shortcuts
72
+ # Add a new config group for shortcuts.
73
+ # End-users should only really care about `add`
74
+ config "shortcuts" do
75
+ class Config < Vagrant.plugin(2, :config)
76
+ attr_accessor :shortcuts
44
77
 
45
- def initialize
46
- @shortcuts = {}
47
- end
48
- def add(name, *args, &block)
49
- @shortcuts[name] = Shortcut.new(block, *args)
50
- end
51
- def get(name)
52
- @shortcuts[name]
78
+ def initialize
79
+ @shortcuts = {}
80
+ end
81
+ def add(name, *args, &block)
82
+ @shortcuts[name] = Shortcut.new(block, *args)
83
+ end
84
+ def get(name)
85
+ @shortcuts[name]
86
+ end
87
+ def has?(name)
88
+ return @shortcuts.key?(name)
89
+ end
53
90
  end
91
+ Config
54
92
  end
55
- Config
93
+ end
94
+
95
+ # For when stuff breaks
96
+ class ShortcutsError < Vagrant::Errors::VagrantError
97
+ error_namespace("vagrant.plugins.shortcuts")
98
+ end
99
+
100
+ class MissingShortcutError < ShortcutsError
101
+ error_key(:missing_shortcut)
102
+ end
103
+
104
+ class UnknownShortcutError < ShortcutsError
105
+ error_key(:unknown_shortcut)
56
106
  end
57
107
  end
58
108
  end
@@ -1,3 +1,3 @@
1
1
  module VagrantShortcuts
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -0,0 +1,6 @@
1
+ en:
2
+ vagrant:
3
+ plugins:
4
+ shortcuts:
5
+ unknown_shortcut: "Unknown shortcut: %{shortcut}"
6
+ missing_shortcut: "You must name a shortcut to run\n\n vagrant do <shortcut>"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-shortcuts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Heap
@@ -52,6 +52,7 @@ files:
52
52
  - Rakefile
53
53
  - lib/vagrant-shortcuts.rb
54
54
  - lib/vagrant-shortcuts/version.rb
55
+ - locales/en.yml
55
56
  - vagrant-shortcuts.gemspec
56
57
  homepage: https://bitbucket.org/tim_heap/vagrant-shortcuts
57
58
  licenses: