vagrant-plugins 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ # v0.2.0
2
+
3
+ * Adds a verbose flag. Informs about plugin features such as "provides commands" or "action hook" etc.
4
+ * Adds a `--no-heads` flag. Swicth off the column descriptions.
5
+ * Revamped the internal UI component to use a nifty DSL to describe the column layout.
6
+
1
7
  # v0.1.0
2
8
 
3
9
  * simple list of all loaded plugin names
data/README.md CHANGED
@@ -3,20 +3,23 @@ vagrant-plugins
3
3
 
4
4
  A vagrant plugin to list active vagrant plugins.
5
5
 
6
+ Since *vagrant 1.1* (which is not yet released) you need to specify which plugins you want to load. You may either use the global `.vagrant.rc` file or the projects `Vagrantfile`.
7
+ This can get a bit confusing when having a lot of different configurations or projects.
6
8
 
9
+ This plugin aims to help you keeping track of which plugins are loaded in your project.
7
10
 
8
11
  ## Installation
9
12
 
10
13
  If you use the gem version of Vagrant, use:
11
14
 
12
15
  ```bash
13
- $ gem install vagrant-dns
16
+ $ gem install vagrant-plugins
14
17
  ```
15
18
 
16
19
  otherwise, use:
17
20
 
18
21
  ```bash
19
- $ vagrant gem install vagrant-dns
22
+ $ vagrant gem install vagrant-plugins
20
23
  ```
21
24
 
22
25
  And add this line to your `.vagrantrc` or `Vagrantfile`:
@@ -28,9 +31,11 @@ Vagrant.require_plugin 'vagrant-plugins'
28
31
  ## Usage
29
32
 
30
33
  ```bash
31
- $ vagrant plugins
34
+ $ vagrant plugins [-a|--all]
32
35
  ```
33
36
 
37
+ * `-a|--all` : Display *vagrant's* builtin plugins as well.
38
+
34
39
  ## Contributing
35
40
 
36
41
  1. Fork it
@@ -12,6 +12,14 @@ module VagrantPlugininspection
12
12
  opts.on("-a", "--all", "List builtin vagrant plugins as well.") do
13
13
  options[:all] = true
14
14
  end
15
+
16
+ opts.on("-H", "--no-head", "Do not print descriptive headings") do
17
+ options[:no_heads] = true
18
+ end
19
+
20
+ opts.on("-v", "--verbose", "Be verbose and display plugin features") do
21
+ options[:verbose] = true
22
+ end
15
23
  end
16
24
 
17
25
  argv = parse_options(opts)
@@ -29,14 +37,52 @@ module VagrantPlugininspection
29
37
 
30
38
  plugins = Vagrant.plugin("1").registered.map { |plugin|
31
39
  if options[:all] || !builtins.include?(plugin)
32
- {
40
+ info = {
33
41
  :name => plugin.name,
34
42
  :description => plugin.description
35
43
  }
44
+
45
+ info.merge!({
46
+ :hosts => !!plugin.data[:hosts],
47
+ :guests => !!plugin.data[:guests],
48
+ :provisioners => !!plugin.data[:provisioners],
49
+ :commands => !!plugin.data[:command],
50
+ :action_hooks => !!plugin.data[:action_hooks],
51
+ :configs => !!plugin.data[:config],
52
+ }) if options[:verbose]
53
+
54
+ # return the plugins info Hash
55
+ info
36
56
  end
37
57
  }.compact
38
58
 
39
- ui.print_columns plugins, :column_order => [:name, :description]
59
+ if options[:verbose] && !options[:no_heads]
60
+ head = <<-EOS
61
+ +- hosts
62
+ |+- guests
63
+ ||+- provisioners
64
+ |||+- commands
65
+ ||||+- action_hooks
66
+ |||||+- configs
67
+ EOS
68
+ ui.info head, :prefix => false
69
+ end
70
+
71
+ ui.print_columns(plugins, :heads => !options[:no_heads]) do
72
+ if options[:verbose]
73
+ column :hosts, :name => '|'
74
+ column :guests, :name => '|'
75
+ column :provisioners, :name => '|'
76
+ column :commands, :name => '|'
77
+ column :action_hooks, :name => '|'
78
+ column :configs, :name => '|'
79
+ seperator "\t"
80
+ end
81
+ column :name
82
+ seperator "\t"
83
+ column :description
84
+ end
85
+
40
86
  end
41
87
  end
42
88
 
@@ -2,29 +2,9 @@ module VagrantPlugininspection
2
2
  module UI
3
3
  class Columnized < Vagrant::UI::Colored
4
4
 
5
- def say(type, message, opts=nil)
6
- defaults = { :new_line => true, :prefix => true }
7
- opts = defaults.merge(opts || {})
8
- super
9
- end
10
-
11
- def print_columns(data, opts=nil)
12
- defaults = { :prefix => false }
13
- opts = defaults.merge(opts ||= {})
14
-
15
- columns = opts.delete(:column_order)
16
-
17
- data = clean(data, opts)
18
- size = sizes(data)
5
+ class LayoutError < StandardError; end
19
6
 
20
- table_head = columnize_row(columns.zip(columns), size, columns) + "\n"
21
- table_head << (table_head.gsub(/[^\t]/, '-')) + "\n"
22
- table_body = data.map { |line| columnize_row(line, size, columns) }.join("\n")
23
-
24
- say :info, table_head << table_body, opts
25
- end
26
-
27
- protected
7
+ class Layout
28
8
 
29
9
  BOOL_MAP = {
30
10
  true => '*',
@@ -32,32 +12,139 @@ module VagrantPlugininspection
32
12
  nil => ''
33
13
  }
34
14
 
35
- def clean(data, opts=nil)
36
- data.map{|line|
37
- Hash[line.map{ |col|
38
- col[1] = BOOL_MAP[col[1]] || col[1].to_s.strip.gsub(/^\s+|\s+$/, '').gsub(/\n|\r/,' ')
39
- col
40
- }]
41
- }
15
+ # @param [Array] _optional_ Array with column names for a simple layout. Columns will be seperated by tab.
16
+ def initialize(simple=nil)
17
+ simple.each { |column|
18
+ self.column(column)
19
+ self.seperator("\t")
20
+ } if simple
21
+
22
+ @heads = Hash.new
23
+ @columns = Hash.new
24
+ @stack = Array.new
42
25
  end
43
-
44
- def sizes(data)
45
- s = {}
46
- data.each { |line|
47
- line.each_pair { |key, value|
48
- s[key] = [key.length, value.length, (s[key] || 0)].max
26
+
27
+ # Adds a column definition to the current position
28
+ def column(key, opts=nil)
29
+ defaults = { :name => key.to_s }
30
+ opts = defaults.merge(opts || {})
31
+
32
+ @heads[key] = opts[:name]
33
+ @columns[key] = opts
34
+ @stack << key
35
+ end
36
+
37
+ # Adds a seperator to the current position
38
+ def seperator(str)
39
+ @stack << str.to_s
40
+ end
41
+
42
+ # Returns an Array of columns formatted lines.
43
+ # Also includes column headers and horizonal header line.
44
+ # @return [Array] Returns an Array of formatted lines
45
+ def rows(data, opts=nil)
46
+ defaults = { :heads => true }
47
+ opts = defaults.merge(opts || {})
48
+
49
+ data = clean(data)
50
+ size = sizes(data)
51
+
52
+ rendered = Array.new
53
+ if opts.delete(:heads)
54
+ rendered << columnize_row(@heads, size)
55
+ rendered << horizontal_line(size)
56
+ end
57
+ rendered << data.map { |line| columnize_row(line, size) }
58
+
59
+ # return a flat Array with lines
60
+ rendered.flatten
61
+ end
62
+
63
+ protected
64
+
65
+ def column_name(key)
66
+ col = @heads[key]
67
+ (col || key).to_s
68
+ end
69
+
70
+ # translate boolean values using BOOL_MAP
71
+ # strips whitespace and newline
72
+ def clean(data)
73
+ data.map{|line|
74
+ Hash[line.map{ |col|
75
+ col[1] = BOOL_MAP[col[1]] || col[1].to_s.strip.gsub(/^\s+|\s+$/, '').gsub(/\n|\r/,' ')
76
+ col
77
+ }]
78
+ }
79
+ end
80
+
81
+ # determinate the size of each column
82
+ def sizes(data)
83
+ s = {}
84
+ data.each { |line|
85
+ line.each_pair { |key, value|
86
+ s[key] = [column_name(key).length, value.length, (s[key] || 0)].max
87
+ }
49
88
  }
50
- }
51
- s
89
+ s
90
+ end
91
+
92
+ def columnize_row(row, sizes)
93
+ @stack.map { |piece|
94
+ if piece.is_a? String
95
+ piece
96
+ else
97
+ sprintf "%-#{sizes[piece]}s", row[piece]
98
+ end
99
+ }.join
100
+ end
101
+
102
+ def horizontal_line(sizes)
103
+ @stack.map { |piece|
104
+ if piece.is_a? String
105
+ piece
106
+ else
107
+ '-' * sizes[piece]
108
+ end
109
+ }.join
110
+ end
111
+
112
+ end # Layout
113
+
114
+ def print_columns(data, opts=nil, &block)
115
+ defaults = {}
116
+ opts = defaults.merge(opts ||= {})
117
+ layout = opts.delete(:layout)
118
+ columns = opts.delete(:columns)
119
+
120
+ layout ||= if block_given?
121
+ self.layout(&block)
122
+ elsif columns && !columns.empty?
123
+ Layout.new(columns)
124
+ else
125
+ raise LayoutError, "You need to pass a layout information, either as a block or array."
52
126
  end
53
127
 
54
- def columnize_row(row, size, columns=nil)
55
- data = Hash[row.map { |key, value|
56
- [key, "%-#{size[key]}s" % [value]]
57
- }]
128
+ rendered = layout.rows(data, opts).map { |line|
129
+ format_message(:info, line, opts)
130
+ }.join("\n")
131
+
132
+ # force the prefix off, we'd allready handled that
133
+ opts[:prefix] = false
134
+
135
+ say :info, rendered, opts
136
+ end
137
+
138
+ protected
58
139
 
59
- (columns ? columns.map { |col| data[col] } : data.values).join("\t")
140
+ # helper to create us a Layout instance and prime using a given block
141
+ def layout(&block)
142
+ layout = Layout.new
143
+ layout.instance_eval(&block)
144
+ # return the layout descriptor
145
+ layout
60
146
  end
61
- end
147
+
148
+ end # Columnized
62
149
  end
63
150
  end
@@ -1,3 +1,3 @@
1
1
  module VagrantPlugininspection
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vagrant-plugins
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-15 00:00:00.000000000 Z
12
+ date: 2012-05-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: vagrant