vagrant-devcommands 0.2.0 → 0.3.0

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: c1835de5d77e36ecc2fdda818fd4b6f682d044b8
4
- data.tar.gz: b9edaee5f787c09dd8b4783d5342fb7e55045a0c
3
+ metadata.gz: ec61d0c70a777b0ee45eaa801f90259553d7d3a6
4
+ data.tar.gz: b230c5d5e67753087b152e54ec38ca395b2bdc30
5
5
  SHA512:
6
- metadata.gz: 5cc5094fa2638a80ce20390587e42c26b589c02c8744fe112166cd82f2d54f796983866967af80021ad7c97a5b6caa52cc3fc03f62c412f36525ffca99590b6c
7
- data.tar.gz: 9323285ba6a94e6339f28c44b539c7cc0eb27698acc28b08ea22671a5c08c8a07230f1de03e3ed41cbd7ce6c2aba3bd8517dc5bb704edd4afa436baaa6942198
6
+ metadata.gz: bc241b3fb2810f89b3145c21cceb1169a89ec75f035865088f365d74c72671baab996d057346945c10c03ab5dae4377347e9c857f3468d426ee72e6996eeb1f5
7
+ data.tar.gz: d98282d205e143f5503582d251e52d66d12bf41abbf1a1b02136cfbf7849d1473a0b6f3a42cf4f0f6afacad3ac00d54a5d9edd0f05f0b6b0971715ab70bea1de
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.3.0 (2015-11-21)
4
+
5
+ - Enhancements
6
+ - Commands can be created using `command 'name', 'script'`
7
+
8
+ - Deprecations
9
+ - Commands defined without the new `command ...` syntax are deprecated
10
+
3
11
  ## v0.2.0 (2015-11-02)
4
12
 
5
13
  - Enhancements
data/README.md CHANGED
@@ -10,12 +10,12 @@ Runs vagrant commands from a Commandfile.
10
10
  Add to a `Commandfile` besides your `Vagrantfile`:
11
11
 
12
12
  ```ruby
13
- VagrantDevCommands.define 'basic', 'hostname'
13
+ command 'basic', 'hostname'
14
14
 
15
- VagrantDevCommands.define 'with_options',
15
+ command 'with_options',
16
16
  box: :my_box,
17
17
  desc: 'executes "hostname" on the box "my_box"',
18
- command: 'hostname'
18
+ script: 'hostname'
19
19
  ```
20
20
 
21
21
 
@@ -52,8 +52,8 @@ When using multi-line commands you probably need to define your command using
52
52
  a sigil notation like the following:
53
53
 
54
54
  ```ruby
55
- VagrantDevCommands.define 'long_running_task',
56
- command: %(cd /path/to/somewhere \
55
+ command 'long_running_task',
56
+ script: %(cd /path/to/somewhere \
57
57
  && echo "starting long running task" \
58
58
  && ./long_running_task.sh \
59
59
  && echo "finished long running task")
@@ -6,41 +6,54 @@ module VagrantPlugins
6
6
  'runs vagrant commands from a Commandfile'
7
7
  end
8
8
 
9
+ def initialize(argv, env)
10
+ @registry = Registry.new
11
+
12
+ super(argv, env)
13
+ end
14
+
9
15
  def execute
10
16
  command = @argv.last
11
17
  commandfile = Commandfile.new(@env)
12
18
 
13
19
  return display_error('Missing "Commandfile"') unless commandfile.exist?
14
20
 
15
- commandfile.import
21
+ @registry.read_commandfile(commandfile)
16
22
 
17
23
  return display_help unless command
18
24
 
19
- unless valid_command?(command)
25
+ unless @registry.valid_command?(command)
20
26
  return display_error("Invalid command \"#{command}\"\n")
21
27
  end
22
28
 
23
- run command
29
+ run @registry.commands[command]
24
30
  end
25
31
 
26
32
  private
27
33
 
34
+ attr_accessor :registry
35
+
28
36
  def display_error(msg)
29
37
  puts(msg) && display_help
30
38
  end
31
39
 
32
40
  def display_help
33
- Help.display
41
+ Help.display(@registry)
34
42
 
35
43
  # return exit code
36
44
  127
37
45
  end
38
46
 
39
- def run(name)
40
- cmd = Definer.commands[name]
41
- argv = run_argv(cmd)
47
+ def run(command)
48
+ argv = run_argv(command)
49
+
50
+ with_target_vms(argv, single_target: true) do |vm|
51
+ env = vm.action(:ssh_run,
52
+ ssh_opts: { extra_args: ['-q'] },
53
+ ssh_run_command: command[:script])
42
54
 
43
- run_command(cmd, argv)
55
+ return env[:ssh_run_exit_status] || 0
56
+ end
44
57
  end
45
58
 
46
59
  def run_argv(cmd)
@@ -55,20 +68,6 @@ module VagrantPlugins
55
68
 
56
69
  argv
57
70
  end
58
-
59
- def run_command(cmd, argv)
60
- with_target_vms(argv, single_target: true) do |vm|
61
- env = vm.action(:ssh_run,
62
- ssh_opts: { extra_args: ['-q'] },
63
- ssh_run_command: cmd[:command])
64
-
65
- return env[:ssh_run_exit_status] || 0
66
- end
67
- end
68
-
69
- def valid_command?(command)
70
- Definer.commands.include? command
71
- end
72
71
  end
73
72
  end
74
73
  end
@@ -14,10 +14,6 @@ module VagrantPlugins
14
14
  find_commandfile
15
15
  end
16
16
 
17
- def import
18
- load path
19
- end
20
-
21
17
  private
22
18
 
23
19
  attr_accessor :env
@@ -8,8 +8,14 @@ module VagrantPlugins
8
8
 
9
9
  def self.define(name, options)
10
10
  if options.is_a?(String)
11
- @commands[name] = { command: options }
11
+ @commands[name] = { script: options }
12
12
  else
13
+ if options.include?(:command)
14
+ options[:script] = options[:command]
15
+
16
+ options.delete(:command)
17
+ end
18
+
13
19
  @commands[name] = options
14
20
  end
15
21
  end
@@ -4,23 +4,23 @@ module VagrantPlugins
4
4
  #
5
5
  # Printed when running "vagrant run" without a command
6
6
  class Help
7
- def self.display
8
- if Definer.commands.empty?
7
+ def self.display(registry)
8
+ if registry.commands.empty?
9
9
  puts 'No commands defined!'
10
10
  return
11
11
  end
12
12
 
13
13
  display_header
14
- display_commands
14
+ display_commands(registry)
15
15
  end
16
16
 
17
17
  class << self
18
18
  private
19
19
 
20
- def display_commands
21
- pad_to = Definer.commands.keys.map(&:length).max
20
+ def display_commands(registry)
21
+ pad_to = registry.commands.keys.map(&:length).max
22
22
 
23
- Definer.commands.each do |name, command|
23
+ registry.commands.each do |name, command|
24
24
  if command.key?(:desc)
25
25
  puts " #{name.ljust(pad_to)} #{command[:desc]}"
26
26
  else
@@ -0,0 +1,48 @@
1
+ module VagrantPlugins
2
+ module DevCommands
3
+ # Vagrant command registry
4
+ class Registry
5
+ attr_accessor :commands
6
+
7
+ def initialize
8
+ @commands = {}
9
+ end
10
+
11
+ def read_commandfile(commandfile)
12
+ contents = commandfile.path.read
13
+
14
+ instance_eval(contents)
15
+ append_legacy
16
+ end
17
+
18
+ def valid_command?(command)
19
+ @commands.include? command
20
+ end
21
+
22
+ private
23
+
24
+ def append_legacy
25
+ unless Definer.commands.empty?
26
+ puts "You are using a deprecated way of defining your commands.\n" \
27
+ 'The methods you are using will be removed in an upcoming' \
28
+ " release.\nPlease update your Commandfile!\n\nMore details: " \
29
+ 'https://github.com/mneudert/vagrant-devcommands'
30
+ end
31
+
32
+ Definer.commands.each do |name, options|
33
+ next if @commands.include?(name)
34
+
35
+ command(name, options)
36
+ end
37
+ end
38
+
39
+ def command(name, options)
40
+ if options.is_a?(String)
41
+ @commands[name] = { script: options }
42
+ else
43
+ @commands[name] = options
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -1,6 +1,6 @@
1
1
  module VagrantPlugins
2
2
  # Defines the current plugin version
3
3
  module DevCommands
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
6
6
  end
@@ -5,6 +5,7 @@ require 'vagrant/devcommands/commandfile'
5
5
  require 'vagrant/devcommands/definer'
6
6
  require 'vagrant/devcommands/help'
7
7
  require 'vagrant/devcommands/plugin'
8
+ require 'vagrant/devcommands/registry'
8
9
  require 'vagrant/devcommands/version'
9
10
 
10
11
  require 'vagrant/devcommands/_proxy'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-devcommands
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marc Neudert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-02 00:00:00.000000000 Z
11
+ date: 2015-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -98,6 +98,7 @@ files:
98
98
  - lib/vagrant/devcommands/definer.rb
99
99
  - lib/vagrant/devcommands/help.rb
100
100
  - lib/vagrant/devcommands/plugin.rb
101
+ - lib/vagrant/devcommands/registry.rb
101
102
  - lib/vagrant/devcommands/version.rb
102
103
  homepage: https://github.com/mneudert/vagrant-devcommands
103
104
  licenses: