yuyi 1.1.4 → 1.1.5

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: 7f3964188686f9d45bb9cd37da390d36561ab7d5
4
- data.tar.gz: 3302bf4e8ce29c4ea4c1a91aa9845afa2f261c27
3
+ metadata.gz: f54fc12263a3eb78bf1b72db5bc3d08ff8509306
4
+ data.tar.gz: 43ba00e4b501473bece5e67be9e5d5d33000d845
5
5
  SHA512:
6
- metadata.gz: c5c23f52585108ad78f3b3427f6cc08d1184ec8e0b431e44ada408453f44c4633d360c1f6088d05db5f5760c79d9b2508d85ad379aa95f75266cd6cb8aa2265c
7
- data.tar.gz: 3f69348dbbf591d5d9db58f38b4de7f2ff0b6ce2b5d2714a4820ddc9612d9130007cc501c67a6f8c33dc4a3b6f2e5728f9b2a3a63dd490131b45ec3bbc65c89d
6
+ metadata.gz: de8c5bf7eb451d5ea95428f38aef109b6be9036c07f185e710ccb52d5fbbfad4b329950ccf767a3655b1d88f4a6af56cf129b997f0f59f4192d9bb509f89221c
7
+ data.tar.gz: a70065a9218a8a53ac88d66c5d85a70d60b09eb01c7f16466392ba89e903d9141621da10ef904450b5578546c66a67aa773127ab7449023523b90ba4d1d05139
data/.new CHANGED
@@ -16,4 +16,4 @@ tasks:
16
16
  - spec/**/*.rb
17
17
  project_name: Yuyi
18
18
  type: ruby
19
- version: 1.1.4
19
+ version: 1.1.5
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
+ gem 'colorize'
3
+ gem 'ruby-progressbar'
2
4
  gem 'thor'
3
5
 
4
6
  group :development do
@@ -56,6 +56,7 @@ GEM
56
56
  rspec-mocks (3.0.2)
57
57
  rspec-support (~> 3.0.0)
58
58
  rspec-support (3.0.2)
59
+ ruby-progressbar (1.5.1)
59
60
  semantic (1.3.0)
60
61
  slop (3.5.0)
61
62
  terminal-notifier-guard (1.5.3)
@@ -66,10 +67,12 @@ PLATFORMS
66
67
  ruby
67
68
 
68
69
  DEPENDENCIES
70
+ colorize
69
71
  guard
70
72
  guard-rspec
71
73
  new
72
74
  rake
73
75
  rspec
76
+ ruby-progressbar
74
77
  terminal-notifier-guard
75
78
  thor
data/README.md CHANGED
@@ -124,11 +124,10 @@ end
124
124
  ```
125
125
 
126
126
  ### TODO
127
- * progressbar
128
127
  * vagrant plugins
129
128
  * Enforce required options
130
129
  * New roll generator (use new!)
131
- * show roll options on -l
130
+ * show roll options on list
132
131
  * installation summary
133
132
  * DOCS!
134
133
 
@@ -30,13 +30,14 @@ class Yuyi::Cli < Thor
30
30
  end
31
31
 
32
32
  desc 'start', 'Run Yuyi'
33
- option :verbose, :aliases => '-v', :type => :boolean, :desc => 'Run in verbose mode'
34
- option :upgrade, :aliases => '-u', :type => :boolean, :desc => 'Check for upgrades for rolls on the menu that are already installed'
33
+ option :verbose, :default => false, :aliases => '-v', :type => :boolean, :desc => 'Run in verbose mode'
34
+ option :upgrade, :default => false, :aliases => '-u', :type => :boolean, :desc => 'Check for upgrades for rolls on the menu that are already installed'
35
35
  option :menu, :aliases => '-m', :desc => 'Path to your menu file'
36
36
  def start
37
+ puts options.inspect
37
38
  # enable verbose mode if flag is passed
38
- Yuyi.verbose = true if options[:verbose]
39
- Yuyi.upgrade = true if options[:upgrade]
39
+ Yuyi.verbose = options[:verbose]
40
+ Yuyi.upgrade = options[:upgrade]
40
41
  Yuyi.menu_path = options[:menu]
41
42
 
42
43
  Yuyi.start
@@ -1,3 +1,4 @@
1
+ require 'rubygems' # DEPRECATION: required for ruby 1.8.7
1
2
  require 'tsort'
2
3
 
3
4
  class Array
@@ -1,3 +1,4 @@
1
+ require 'colorize'
1
2
  require 'open3'
2
3
  require 'readline'
3
4
  require 'yaml'
@@ -9,12 +10,14 @@ module Yuyi::Dsl
9
10
  attr_accessor :verbose, :upgrade, :menu_path
10
11
 
11
12
  # Replacement for `puts` that accepts various stylistic arguments
12
- # type: => [symbol] Preset colors for [:fail, :success, :warn]
13
- # color: => [integer] See docs for #colorize for color codes
14
- # justify: => [center|ljust|rjust] The type of justification to use
15
- # padding: => [integer] The maximum string size to justify text in
16
- # indent: => [integer] The maximum string size to justify text in
17
- # newline: => [boolean] True if you want a newline after the output
13
+ # type: => [symbol] Preset colors for [:fail, :success, :warn]
14
+ # color: => [integer] See docs for #colorize for color codes
15
+ # justify: => [center|ljust|rjust] The type of justification to use
16
+ # padding: => [integer] The maximum string size to justify text in
17
+ # indent: => [integer] The maximum string size to justify text in
18
+ # newline: => [boolean] True if you want a newline after the output
19
+ # progressbar: => [boolean] True if you are adding a title to the progresbar
20
+ # overwrite: => [boolean] True if you want to overwrite the previous line
18
21
  #
19
22
  def say text = '', args = {}
20
23
  # defaults
@@ -31,33 +34,43 @@ module Yuyi::Dsl
31
34
  # process last due to the addition of special color codes
32
35
  text = case args[:type]
33
36
  when :fail
34
- Yuyi.colorize text, 31
37
+ text.colorize :red
35
38
  when :success
36
- Yuyi.colorize text, 32
39
+ text.colorize :green
37
40
  when :warn
38
- Yuyi.colorize text, 33
41
+ text.colorize :yellow
39
42
  else
40
- Yuyi.colorize text, args[:color]
43
+ text
44
+ end
45
+
46
+ if args[:color]
47
+ text = text.colorize(args[:color])
41
48
  end
42
49
 
43
50
  if args[:indent]
44
51
  text = (' ' * args[:indent]) + text
45
52
  end
46
53
 
47
- if args[:newline]
48
- STDOUT.puts text
49
- else
54
+ if args[:overwrite]
55
+ STDOUT.flush
56
+ text = text + "\r"
57
+ end
58
+
59
+ if args[:progressbar] && Yuyi.verbose != true && Yuyi::Menu.menu && Yuyi::Menu.menu.progressbar
60
+ Yuyi::Menu.menu.progressbar.log text
61
+ elsif !args[:newline] || args[:overwrite]
50
62
  STDOUT.print text
63
+ else
64
+ STDOUT.puts text
51
65
  end
52
66
  end
53
67
 
54
68
  # Accepts the same arguments as #say
55
69
  #
56
70
  def ask question, options = {}, &block
57
- prompt = '>>> '
71
+ prompt = '>>> '.colorize(:green)
58
72
  options = {
59
73
  :readline => false,
60
- :color => 1
61
74
  }.merge(options)
62
75
 
63
76
  say question, options
@@ -65,7 +78,7 @@ module Yuyi::Dsl
65
78
  output = if options[:readline]
66
79
  Readline.readline(prompt).chomp('/')
67
80
  else
68
- say prompt, :color => 1, :newline => false
81
+ say prompt, :newline => false
69
82
  STDIN.gets
70
83
  end.rstrip
71
84
 
@@ -1,6 +1,9 @@
1
1
  require 'readline'
2
+ require 'ruby-progressbar'
2
3
 
3
4
  class Yuyi::Menu
5
+ attr_accessor :progressbar
6
+
4
7
  # Stores a single menu instance on the class
5
8
  # If a new menu is initialized, it will become the only menu accessible through Yuyi::Menu.menu
6
9
  #
@@ -151,7 +154,7 @@ private
151
154
  def get_menu_path
152
155
  until @yaml
153
156
  Yuyi.say 'Navigate to a menu file...', :type => :success
154
- Yuyi.ask "...or just press enter to load `#{Yuyi::DEFAULT_MENU}`", :readline => true, :color => 36 do |user_path|
157
+ Yuyi.ask "...or just press enter to load `#{Yuyi::DEFAULT_MENU}`", :readline => true do |user_path|
155
158
  menu_path = user_path.empty? ? Yuyi::DEFAULT_MENU : user_path
156
159
  load_from_file menu_path
157
160
  end
@@ -209,47 +212,49 @@ private
209
212
  def order
210
213
  header_length = 80
211
214
  all_rolls = sorted_rolls
212
-
215
+ self.progressbar = ProgressBar.create(:progress_mark => '='.colorize(:green), :length => header_length, :total => all_rolls.length)
213
216
 
214
217
  # pre installs
215
218
  #
216
- Yuyi.say '=' * header_length, :color => 35
217
- Yuyi.say 'APPETIZERS', :color => 35, :justify => :center, :padding => header_length
218
- Yuyi.say 'Pre Install', :justify => :center, :padding => header_length
219
- Yuyi.say
219
+ # Yuyi.say '=' * header_length, :color => :green
220
+ Yuyi.say 'APPETIZERS', :justify => :center, :padding => header_length
220
221
 
222
+ self.progressbar.reset
221
223
  all_rolls.each do |file_name|
222
224
  @rolls[file_name].appetizers
225
+ self.progressbar.increment
223
226
  end
227
+ Yuyi.say
224
228
 
225
229
 
226
230
  # main installs
227
231
  #
228
- Yuyi.say '=' * header_length, :color => 36
229
- Yuyi.say 'ENTREES', :color => 36, :justify => :center, :padding => header_length
230
- Yuyi.say 'Main Install', :justify => :center, :padding => header_length
231
- Yuyi.say
232
+ # Yuyi.say '=' * header_length, :color => :green
233
+ Yuyi.say 'ENTREES', :justify => :center, :padding => header_length
232
234
 
235
+ self.progressbar.reset
233
236
  all_rolls.each do |file_name|
234
237
  @rolls[file_name].entree
238
+ self.progressbar.increment
235
239
  end
240
+ Yuyi.say
236
241
 
237
242
 
238
243
  # post installs
239
244
  #
240
- Yuyi.say '=' * header_length, :color => 35
241
- Yuyi.say 'DESSERT', :color => 35, :justify => :center, :padding => header_length
242
- Yuyi.say 'Post Install', :justify => :center, :padding => header_length
243
- Yuyi.say
245
+ # Yuyi.say '=' * header_length, :color => :green
246
+ Yuyi.say 'DESSERT', :justify => :center, :padding => header_length
244
247
 
248
+ self.progressbar.reset
245
249
  all_rolls.each do |file_name|
246
250
  @rolls[file_name].dessert
251
+ self.progressbar.increment
247
252
  end
253
+ Yuyi.say
248
254
 
249
255
 
250
- Yuyi.say '=' * header_length, :color => 36
251
- Yuyi.say 'YUYI COMPLETED', :color => 36, :justify => :center, :padding => header_length
252
- Yuyi.say '=' * header_length, :color => 36
256
+ Yuyi.say 'YUYI COMPLETED', :color => :light_blue, :justify => :center, :padding => header_length
257
+ Yuyi.say '=' * header_length, :color => :light_blue
253
258
  Yuyi.say
254
259
  end
255
260
 
@@ -47,7 +47,8 @@ class Yuyi::Roll
47
47
 
48
48
  # set option definitions
49
49
  def self.options option_defs = {}
50
- @option_defs = option_defs
50
+ @option_defs ||= {}
51
+ @option_defs.merge! option_defs
51
52
  end
52
53
 
53
54
 
@@ -89,14 +90,14 @@ class Yuyi::Roll
89
90
  def order
90
91
  if installed?
91
92
  if options[:uninstall]
92
- Yuyi.say "🍣\s Uninstalling #{title}...", :color => 33
93
+ say "🍣\s Uninstalling #{title}...", :color => :red, :progressbar => true, :overwrite => true
93
94
  uninstall
94
95
  elsif Yuyi.upgrade
95
- Yuyi.say "🍣\s Upgrading #{title}", :color => 36
96
+ say "🍣\s Upgrading #{title}", :color => :yellow, :progressbar => true, :overwrite => true
96
97
  upgrade
97
98
  end
98
99
  else
99
- Yuyi.say "🍣\s Installing #{title}...", :color => 32
100
+ say "🍣\s Installing #{title}...", :color => :green, :progressbar => true, :overwrite => true
100
101
  install
101
102
  end
102
103
  end
@@ -147,7 +148,7 @@ class Yuyi::Roll
147
148
 
148
149
  def installed?
149
150
  if Yuyi.verbose
150
- say "INSTALLED?: #{self.title}", :color => 36
151
+ say "INSTALLED?: #{self.title}", :color => :yellow
151
152
  end
152
153
 
153
154
  begin
@@ -2,18 +2,18 @@ module Yuyi::Ui
2
2
  def header
3
3
  line_length = 50
4
4
  say
5
- say '-' * line_length, :color => 4
5
+ say '-' * line_length, :color => :light_blue
6
6
  say
7
- say '____ ____ __ __ ____ ____ __ ', :color => 31, :justify => :center, :padding => line_length
8
- say '\ \ / / | | | | \ \ / / | | ', :color => 32, :justify => :center, :padding => line_length
9
- say ' \ \/ / | | | | \ \/ / | | ', :color => 33, :justify => :center, :padding => line_length
10
- say ' \_ _/ | | | | \_ _/ | | ', :color => 34, :justify => :center, :padding => line_length
11
- say ' | | | `--\' | | | | | ', :color => 35, :justify => :center, :padding => line_length
12
- say ' |__| \______/ |__| |__| ', :color => 36, :justify => :center, :padding => line_length
7
+ say '____ ____ __ __ ____ ____ __ ', :justify => :center, :padding => line_length, :color => :red
8
+ say '\ \ / / | | | | \ \ / / | | ', :justify => :center, :padding => line_length, :color => :light_white
9
+ say ' \ \/ / | | | | \ \/ / | | ', :justify => :center, :padding => line_length, :color => :light_blue
10
+ say ' \_ _/ | | | | \_ _/ | | ', :justify => :center, :padding => line_length, :color => :red
11
+ say ' | | | `--\' | | | | | ', :justify => :center, :padding => line_length, :color => :light_white
12
+ say ' |__| \______/ |__| |__| ', :justify => :center, :padding => line_length, :color => :light_blue
13
13
  say
14
14
  say "VERSION #{Yuyi::VERSION}", :justify => :center, :padding => line_length
15
15
  say
16
- say '-' * line_length, :color => 4
16
+ say '-' * line_length, :color => :light_blue
17
17
  say
18
18
  end
19
19
 
@@ -42,6 +42,7 @@ module Yuyi::Ui
42
42
  say 'Yuyi does not need your admin password, but some installations do.', :type => :warn
43
43
  say 'Yuyi will prompt you for a password and attempt to keep your admin timestamp alive.', :type => :warn
44
44
  say 'You may be asked to enter your password several times.', :type => :warn
45
+ say
45
46
 
46
47
  # keep the sudo timestamp fresh just in case
47
48
  `sudo -v`
@@ -59,23 +60,24 @@ module Yuyi::Ui
59
60
  indent = 2
60
61
  longest_option = roll.options.keys.map(&:to_s).max_by(&:length).length + indent
61
62
 
62
- say "Available options for #{roll.title}...", :color => 32
63
+ say "#{roll.title} options", :color => :green
63
64
 
64
65
  roll.option_defs.each do |k, v|
65
- option_color = v[:required] ? 31 : 36
66
+ option_color = v[:required] ? :red : :default
66
67
 
68
+ # show option and description
67
69
  say "#{k.to_s.rjust(longest_option)}: ", :color => option_color, :newline => false
68
70
  say v[:description]
69
- say (' ' * (longest_option + indent)), :newline => false
71
+
72
+ # show default
70
73
  if v[:default]
71
- say 'default: ', :color => 36, :newline => false
74
+ say 'default: ', :indent => (longest_option + indent), :newline => false, :color => :yellow
72
75
  say v[:default]
73
76
  end
74
77
  end
75
78
 
76
79
  if examples
77
80
  examples_hash = {}
78
- example_indent = longest_option + indent
79
81
  options = roll.options.dup
80
82
 
81
83
  # merge examples from roll source in
@@ -88,17 +90,8 @@ module Yuyi::Ui
88
90
  examples_hash[roll.file_name.to_s] = options
89
91
 
90
92
  say
91
- say 'Example', :color => 33, :indent => example_indent, :newline => false
92
- say examples_hash.deep_stringify_keys!.to_yaml.sub('---', '').gsub(/\n(\s*)/, "\n\\1#{' ' * example_indent}")
93
+ say 'Example', :color => :green, :indent => indent, :newline => false
94
+ say examples_hash.deep_stringify_keys!.to_yaml.sub('---', '').gsub(/\n(\s*)/, "\n\\1#{' ' * (indent + indent)}")
93
95
  end
94
96
  end
95
-
96
- # Output text with a certain color (or style)
97
- # Reference for color codes
98
- # https://github.com/flori/term-ansicolor/blob/master/lib/term/ansicolor.rb
99
- #
100
- def colorize text, color_code
101
- return text unless color_code
102
- "\e[#{color_code}m#{text}\e[0m"
103
- end
104
97
  end
@@ -14,16 +14,6 @@ describe Yuyi::Dsl do
14
14
  allow(STDOUT).to receive(:puts).and_call_original
15
15
  end
16
16
 
17
- it 'should output the correct type' do
18
- expect(STDOUT).to receive(:puts).with("\e[31mfoo type\e[0m")
19
- DslTest.say 'foo type', :type => :fail
20
- end
21
-
22
- it 'should output the correct color' do
23
- expect(STDOUT).to receive(:puts).with("\e[123mfoo color\e[0m")
24
- DslTest.say 'foo color', :color => 123
25
- end
26
-
27
17
  it 'should output the correct justification & padding' do
28
18
  expect(STDOUT).to receive(:puts).with(' foo justify padding ')
29
19
  DslTest.say 'foo justify padding', :justify => :center, :padding => 22
@@ -17,10 +17,13 @@ RSpec.configure do |config|
17
17
  c.syntax = :expect
18
18
  end
19
19
 
20
- config.order = 'random'
20
+ config.order = :random
21
21
 
22
22
  config.before do
23
23
  allow(Yuyi).to receive(:say)
24
+ allow(ProgressBar).to receive(:create)
25
+ allow_any_instance_of(Yuyi::Menu).to receive_message_chain('progressbar.reset')
26
+ allow_any_instance_of(Yuyi::Menu).to receive_message_chain('progressbar.increment')
24
27
  end
25
28
  end
26
29
 
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yuyi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Brewster
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-21 00:00:00.000000000 Z
11
+ date: 2014-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-progressbar
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: thor
15
43
  requirement: !ruby/object:Gem::Requirement