vagrant-shortcuts 0.2.0 → 0.2.1
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 +4 -4
- data/.gitignore +1 -0
- data/lib/vagrant-shortcuts.rb +87 -37
- data/lib/vagrant-shortcuts/version.rb +1 -1
- data/locales/en.yml +6 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71d2c0e6f8bcb8ac7e62e3759b0fcd3d1adf87d8
|
4
|
+
data.tar.gz: baac53ae8c2bd4c46879822dcbd551a0435aad7c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 817dfc4ce02cebd664f8a098845fefba8753ab4fe88e1a71a8459eacc89015fd5b93fa01d2071266b284f2073b257085a3ed861212e3c1ac89dd2a2ea9dd4c7f
|
7
|
+
data.tar.gz: 2a3e0e12abc1087778d732572395295c149d3730f39ab0e3868dd5de503279a5a21997871bcded76ea878f06d9af6e3f3c3c96295240b24b36967196bbd67bce
|
data/.gitignore
CHANGED
data/lib/vagrant-shortcuts.rb
CHANGED
@@ -2,57 +2,107 @@ require "vagrant-shortcuts/version"
|
|
2
2
|
|
3
3
|
module VagrantPlugins
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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
|
12
|
-
|
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
|
-
|
20
|
-
|
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
|
-
|
23
|
-
|
24
|
-
|
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
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
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
|
data/locales/en.yml
ADDED
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.
|
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:
|