cliutils 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.DS_Store +0 -0
  3. data/.gitignore +1 -0
  4. data/Gemfile +4 -0
  5. data/Gemfile.lock +48 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +288 -0
  8. data/README.rdoc +19 -0
  9. data/Rakefile +45 -0
  10. data/bin/cliutils +38 -0
  11. data/cliutils.gemspec +28 -0
  12. data/features/cli_manager.feature +13 -0
  13. data/features/step_definitions/cli_manager_steps.rb +1 -0
  14. data/features/support/env.rb +16 -0
  15. data/html/CLIUtils/Configuration.html +271 -0
  16. data/html/CLIUtils/Configurator.html +504 -0
  17. data/html/CLIUtils/LoggerDelegator.html +344 -0
  18. data/html/CLIUtils/Messenging.html +284 -0
  19. data/html/CLIUtils/Prefs.html +330 -0
  20. data/html/CLIUtils/PrettyIO.html +799 -0
  21. data/html/CLIUtils.html +112 -0
  22. data/html/Hash.html +453 -0
  23. data/html/Logger.html +183 -0
  24. data/html/Object.html +120 -0
  25. data/html/README_md.html +454 -0
  26. data/html/String.html +413 -0
  27. data/html/created.rid +13 -0
  28. data/html/fonts/Lato-Light.ttf +0 -0
  29. data/html/fonts/Lato-LightItalic.ttf +0 -0
  30. data/html/fonts/Lato-Regular.ttf +0 -0
  31. data/html/fonts/Lato-RegularItalic.ttf +0 -0
  32. data/html/fonts/SourceCodePro-Bold.ttf +0 -0
  33. data/html/fonts/SourceCodePro-Regular.ttf +0 -0
  34. data/html/fonts.css +167 -0
  35. data/html/images/add.png +0 -0
  36. data/html/images/arrow_up.png +0 -0
  37. data/html/images/brick.png +0 -0
  38. data/html/images/brick_link.png +0 -0
  39. data/html/images/bug.png +0 -0
  40. data/html/images/bullet_black.png +0 -0
  41. data/html/images/bullet_toggle_minus.png +0 -0
  42. data/html/images/bullet_toggle_plus.png +0 -0
  43. data/html/images/date.png +0 -0
  44. data/html/images/delete.png +0 -0
  45. data/html/images/find.png +0 -0
  46. data/html/images/loadingAnimation.gif +0 -0
  47. data/html/images/macFFBgHack.png +0 -0
  48. data/html/images/package.png +0 -0
  49. data/html/images/page_green.png +0 -0
  50. data/html/images/page_white_text.png +0 -0
  51. data/html/images/page_white_width.png +0 -0
  52. data/html/images/plugin.png +0 -0
  53. data/html/images/ruby.png +0 -0
  54. data/html/images/tag_blue.png +0 -0
  55. data/html/images/tag_green.png +0 -0
  56. data/html/images/transparent.png +0 -0
  57. data/html/images/wrench.png +0 -0
  58. data/html/images/wrench_orange.png +0 -0
  59. data/html/images/zoom.png +0 -0
  60. data/html/index.html +455 -0
  61. data/html/js/darkfish.js +140 -0
  62. data/html/js/jquery.js +18 -0
  63. data/html/js/navigation.js +142 -0
  64. data/html/js/search.js +109 -0
  65. data/html/js/search_index.js +1 -0
  66. data/html/js/searcher.js +228 -0
  67. data/html/rdoc.css +580 -0
  68. data/html/table_of_contents.html +399 -0
  69. data/lib/.DS_Store +0 -0
  70. data/lib/cliutils/configuration.rb +48 -0
  71. data/lib/cliutils/configurator.rb +119 -0
  72. data/lib/cliutils/ext/Hash+Extensions.rb +145 -0
  73. data/lib/cliutils/ext/Logger+Extensions.rb +27 -0
  74. data/lib/cliutils/ext/String+Extensions.rb +26 -0
  75. data/lib/cliutils/logger-delegator.rb +66 -0
  76. data/lib/cliutils/messenging.rb +51 -0
  77. data/lib/cliutils/prefs.rb +116 -0
  78. data/lib/cliutils/pretty-io.rb +255 -0
  79. data/lib/cliutils/version.rb +3 -0
  80. data/lib/cliutils.rb +15 -0
  81. data/res/readme-images/messenger-types-1.png +0 -0
  82. data/res/readme-images/messenger-warn.png +0 -0
  83. data/res/readme-images/multi-logger.png +0 -0
  84. data/res/readme-images/prettyio-color-chart.png +0 -0
  85. data/res/readme-images/prettyio-gnarly-text.png +0 -0
  86. data/res/readme-images/prettyio-red-text.png +0 -0
  87. data/res/readme-images/prompting.png +0 -0
  88. data/res/readme-images/wrapping.png +0 -0
  89. data/test/configurator_test.rb +50 -0
  90. data/test/hash_extensions_test.rb +50 -0
  91. data/test/logger_extensions_test.rb +16 -0
  92. data/test/messenging_test.rb +53 -0
  93. data/test/prefs_test.rb +29 -0
  94. data/test/string_extesions_test.rb +14 -0
  95. data/test/test_files/prefstest.yaml +33 -0
  96. metadata +199 -0
Binary file
Binary file
Binary file
@@ -0,0 +1,50 @@
1
+ require 'fileutils'
2
+ require 'test/unit'
3
+
4
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/configurator')
5
+
6
+ class TestConfigurator < Test::Unit::TestCase
7
+ def setup
8
+ @config_path = '/tmp/test.config'
9
+ @config = CLIUtils::Configurator.new(@config_path)
10
+ end
11
+
12
+ def teardown
13
+ FileUtils.rm(@config_path) if File.exists?(@config_path)
14
+ end
15
+
16
+ def test_add_section
17
+ @config.add_section(:test)
18
+ assert_equal(@config.data, {test: {}})
19
+ end
20
+
21
+ def test_delete_section
22
+ @config.add_section(:test)
23
+ @config.add_section(:test2)
24
+ @config.delete_section(:test)
25
+ assert_equal(@config.data, {test2: {}})
26
+ end
27
+
28
+ def test_accessing
29
+ @config.add_section(:test)
30
+ @config.data[:test].merge!(name: 'Bob')
31
+ assert_equal(@config.test, {name: 'Bob'})
32
+ end
33
+
34
+ def test_reset
35
+ @config.add_section(:test)
36
+ @config.data[:test].merge!(name: 'Bob')
37
+ @config.reset
38
+ assert_equal(@config.data, {})
39
+ end
40
+
41
+ def test_save
42
+ @config.add_section(:section1)
43
+ @config.section1.merge!({ a: 'test', b: 'test' })
44
+ @config.save
45
+
46
+ File.open(@config_path, 'r') do |f|
47
+ assert_output("---\nsection1:\n a: test\n b: test\n") { puts f.read }
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,50 @@
1
+ require 'test/unit'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/ext/Hash+Extensions')
4
+
5
+ class TestHashExtensions < Test::Unit::TestCase
6
+ def test_deep_merge!
7
+ h1 = {key: 'value', key2: ['value1', 'value2']}
8
+ h2 = {key3: {subkey1: 'value1'}, key: 'another_value'}
9
+ exp_result = {:key=>"another_value", :key2=>["value1", "value2"], :key3=>{:subkey1=>"value1"}}
10
+ actual_result = h1.deep_merge!(h2)
11
+
12
+ assert_equal(exp_result, actual_result)
13
+ end
14
+
15
+ def test_deep_stringify_keys
16
+ h = {key: {subkey1: 'value1', subkey2: {subsubkey1: 'value'}}}
17
+ exp_result = {'key' => {'subkey1' => 'value1', 'subkey2' => {'subsubkey1' => 'value'}}}
18
+ actual_result = h.deep_stringify_keys
19
+
20
+ assert_not_equal(h, actual_result)
21
+ assert_equal(exp_result, actual_result)
22
+ end
23
+
24
+ def test_deep_stringify_keys!
25
+ h = {key: {subkey1: 'value1', subkey2: {subsubkey1: 'value'}}}
26
+ exp_result = {'key' => {'subkey1' => 'value1', 'subkey2' => {'subsubkey1' => 'value'}}}
27
+ actual_result = h.deep_stringify_keys!
28
+
29
+ assert_equal(h, actual_result)
30
+ assert_equal(exp_result, actual_result)
31
+ end
32
+
33
+ def test_deep_symbolize_keys
34
+ h = {'key' => {'subkey1' => 'value1', 'subkey2' => {'subsubkey1' => 'value'}}}
35
+ exp_result = {key: {subkey1: 'value1', subkey2: {subsubkey1: 'value'}}}
36
+ actual_result = h.deep_symbolize_keys
37
+
38
+ assert_not_equal(h, actual_result)
39
+ assert_equal(exp_result, actual_result)
40
+ end
41
+
42
+ def test_deep_symbolize_keys!
43
+ h = {'key' => {'subkey1' => 'value1', 'subkey2' => {'subsubkey1' => 'value'}}}
44
+ exp_result = {key: {subkey1: 'value1', subkey2: {subsubkey1: 'value'}}}
45
+ actual_result = h.deep_symbolize_keys!
46
+
47
+ assert_equal(h, actual_result)
48
+ assert_equal(exp_result, actual_result)
49
+ end
50
+ end
@@ -0,0 +1,16 @@
1
+ require 'test/unit'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/ext/Logger+Extensions')
4
+
5
+ class TestLoggerExtensions < Test::Unit::TestCase
6
+ def test_custom_level
7
+ l = Logger.new(STDOUT)
8
+ l.formatter = proc do |severity, datetime, progname, msg|
9
+ puts "#{ severity }: #{ msg }"
10
+ end
11
+
12
+ assert_output("PROMPT: test\n") { l.prompt('test') }
13
+ assert_output("SECTION: test\n") { l.section('test') }
14
+ assert_output("SUCCESS: test\n") { l.success('test') }
15
+ end
16
+ end
@@ -0,0 +1,53 @@
1
+ require 'fileutils'
2
+ require 'logger'
3
+ require 'test/unit'
4
+
5
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/ext/String+Extensions')
6
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/pretty-io')
7
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/logger-delegator')
8
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/messenging')
9
+
10
+ class TestMessenging < Test::Unit::TestCase
11
+ include CLIUtils::Messenging
12
+
13
+ def setup
14
+ @file1path = '/tmp/file1.txt'
15
+ end
16
+
17
+ def teardown
18
+ FileUtils.rm(@file1path) if File.exists?(@file1path)
19
+ end
20
+
21
+ def test_stdout_output
22
+ assert_output('# This is error'.red + "\n") { messenger.send(:error, 'This is error') }
23
+ assert_output('# This is info'.blue + "\n") { messenger.send(:info, 'This is info') }
24
+ assert_output('---> This is section'.purple + "\n") { messenger.send(:section, 'This is section') }
25
+ assert_output('# This is success'.green + "\n") { messenger.send(:success, 'This is success') }
26
+ assert_output('# This is warn'.yellow + "\n") { messenger.send(:warn, 'This is warn') }
27
+ end
28
+
29
+ def test_wrapping
30
+ CLIUtils::PrettyIO.wrap_at(35)
31
+
32
+ long_str = 'This is a really long string that should wrap itself at some point, okay?'
33
+ expected_str = long_str.gsub(/\n/, ' ').gsub(/(.{1,#{CLIUtils::PrettyIO.wrap_limit - 2}})(\s+|$)/, "# \\1\n").strip
34
+ assert_output(expected_str.blue + "\n") { messenger.send(:info, long_str) }
35
+ end
36
+
37
+ def test_attach_detach
38
+ file_logger = Logger.new(@file1path)
39
+ file_logger.formatter = proc do |severity, datetime, progname, msg|
40
+ "#{ severity }: #{ msg }\n"
41
+ end
42
+
43
+ messenger.attach(file_logger)
44
+ messenger.send(:info, 'Info test')
45
+ messenger.send(:error, 'Error test')
46
+ messenger.detach(file_logger)
47
+ messenger.send(:warn, 'Warn test')
48
+
49
+ File.open(@file1path, 'r') do |f|
50
+ assert_output("INFO: Info test\nERROR: Error test\n") { puts f.read.lines[1..-1].join }
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,29 @@
1
+ require 'fileutils'
2
+ require 'test/unit'
3
+ require 'yaml'
4
+
5
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/ext/Hash+Extensions')
6
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/prefs')
7
+
8
+ class TestPrefs < Test::Unit::TestCase
9
+ def setup
10
+ @prefs_arr = [{:prompt=>"What is the hostname of your DD-WRT router?", :default=>"192.168.1.1", :key=>"hostname", :section=>"ssh_info"}, {:prompt=>"What is the SSH username of your DD-WRT router?", :default=>"root", :key=>"username", :section=>"ssh_info"}, {:prompt=>"What SSH port does your DD-WRT router use?", :default=>22, :key=>"port", :section=>"ssh_info"}, {:prompt=>"How do you use password or key authentication?", :default=>"password", :key=>"auth_method", :section=>"ssh_info", :options=>["password", "key"]}, {:prompt=>"Where is your key located?", :default=>"~/.ssh", :key=>"key_location", :section=>"ssh_info", :requirements=>[{:key=>"auth_method", :value=>"key"}]}, {:prompt=>"What is your password?", :key=>"password", :section=>"ssh_info", :requirements=>[{:key=>"auth_method", :value=>"password"}]}]
11
+
12
+ @prefs_filepath = '/tmp/prefstest.yaml'
13
+ FileUtils.cp(File.join(File.dirname(__FILE__), '..', 'test/test_files/prefstest.yaml'), @prefs_filepath)
14
+ end
15
+
16
+ def teardown
17
+ FileUtils.rm(@prefs_filepath) if File.exists?(@prefs_filepath)
18
+ end
19
+
20
+ def test_file_creation
21
+ p = CLIUtils::Prefs.new(@prefs_filepath)
22
+ assert_equal(YAML::load_file(@prefs_filepath).deep_symbolize_keys!, p.prompts)
23
+ end
24
+
25
+ def test_hash_creation
26
+ p = CLIUtils::Prefs.new(@prefs_arr)
27
+ assert_equal({:prompts => @prefs_arr}.deep_symbolize_keys!, p.prompts)
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ require 'test/unit'
2
+
3
+ require File.join(File.dirname(__FILE__), '..', 'lib/cliutils/ext/String+Extensions')
4
+
5
+ class TestStringExtensions < Test::Unit::TestCase
6
+ def test_custom_colors
7
+ assert_output("\e[34mtest\e[0m\n") { puts 'test'.blue }
8
+ assert_output("\e[36mtest\e[0m\n") { puts 'test'.cyan }
9
+ assert_output("\e[32mtest\e[0m\n") { puts 'test'.green }
10
+ assert_output("\e[35mtest\e[0m\n") { puts 'test'.purple }
11
+ assert_output("\e[31mtest\e[0m\n") { puts 'test'.red }
12
+ assert_output("\e[33mtest\e[0m\n") { puts 'test'.yellow }
13
+ end
14
+ end
@@ -0,0 +1,33 @@
1
+ prompts:
2
+ - prompt: What is the hostname of your DD-WRT router?
3
+ default: 192.168.1.1
4
+ key: hostname
5
+ section: ssh_info
6
+ - prompt: What is the SSH username of your DD-WRT router?
7
+ default: root
8
+ key: username
9
+ section: ssh_info
10
+ - prompt: What SSH port does your DD-WRT router use?
11
+ default: 22
12
+ key: port
13
+ section: ssh_info
14
+ - prompt: Do you use password or key authentication?
15
+ default: password
16
+ key: auth_method
17
+ section: ssh_info
18
+ options: ['password', 'key']
19
+ - prompt: Where is your key located?
20
+ default: ~/.ssh
21
+ key: key_location
22
+ section: ssh_info
23
+ requirements:
24
+ - key: auth_method
25
+ value: key
26
+ - prompt: What is your password?
27
+ key: password
28
+ section: ssh_info
29
+ requirements:
30
+ - key: auth_method
31
+ value: password
32
+
33
+
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cliutils
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Bach
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: A library of functionality designed to alleviate common tasks and headaches
56
+ when developing command-line (CLI) apps in Ruby.
57
+ email:
58
+ - bachya1208@googlemail.com
59
+ executables:
60
+ - cliutils
61
+ extensions: []
62
+ extra_rdoc_files:
63
+ - README.md
64
+ files:
65
+ - ".DS_Store"
66
+ - ".gitignore"
67
+ - Gemfile
68
+ - Gemfile.lock
69
+ - LICENSE.txt
70
+ - README.md
71
+ - README.rdoc
72
+ - Rakefile
73
+ - bin/cliutils
74
+ - cliutils.gemspec
75
+ - features/cli_manager.feature
76
+ - features/step_definitions/cli_manager_steps.rb
77
+ - features/support/env.rb
78
+ - html/CLIUtils.html
79
+ - html/CLIUtils/Configuration.html
80
+ - html/CLIUtils/Configurator.html
81
+ - html/CLIUtils/LoggerDelegator.html
82
+ - html/CLIUtils/Messenging.html
83
+ - html/CLIUtils/Prefs.html
84
+ - html/CLIUtils/PrettyIO.html
85
+ - html/Hash.html
86
+ - html/Logger.html
87
+ - html/Object.html
88
+ - html/README_md.html
89
+ - html/String.html
90
+ - html/created.rid
91
+ - html/fonts.css
92
+ - html/fonts/Lato-Light.ttf
93
+ - html/fonts/Lato-LightItalic.ttf
94
+ - html/fonts/Lato-Regular.ttf
95
+ - html/fonts/Lato-RegularItalic.ttf
96
+ - html/fonts/SourceCodePro-Bold.ttf
97
+ - html/fonts/SourceCodePro-Regular.ttf
98
+ - html/images/add.png
99
+ - html/images/arrow_up.png
100
+ - html/images/brick.png
101
+ - html/images/brick_link.png
102
+ - html/images/bug.png
103
+ - html/images/bullet_black.png
104
+ - html/images/bullet_toggle_minus.png
105
+ - html/images/bullet_toggle_plus.png
106
+ - html/images/date.png
107
+ - html/images/delete.png
108
+ - html/images/find.png
109
+ - html/images/loadingAnimation.gif
110
+ - html/images/macFFBgHack.png
111
+ - html/images/package.png
112
+ - html/images/page_green.png
113
+ - html/images/page_white_text.png
114
+ - html/images/page_white_width.png
115
+ - html/images/plugin.png
116
+ - html/images/ruby.png
117
+ - html/images/tag_blue.png
118
+ - html/images/tag_green.png
119
+ - html/images/transparent.png
120
+ - html/images/wrench.png
121
+ - html/images/wrench_orange.png
122
+ - html/images/zoom.png
123
+ - html/index.html
124
+ - html/js/darkfish.js
125
+ - html/js/jquery.js
126
+ - html/js/navigation.js
127
+ - html/js/search.js
128
+ - html/js/search_index.js
129
+ - html/js/searcher.js
130
+ - html/rdoc.css
131
+ - html/table_of_contents.html
132
+ - lib/.DS_Store
133
+ - lib/cliutils.rb
134
+ - lib/cliutils/configuration.rb
135
+ - lib/cliutils/configurator.rb
136
+ - lib/cliutils/ext/Hash+Extensions.rb
137
+ - lib/cliutils/ext/Logger+Extensions.rb
138
+ - lib/cliutils/ext/String+Extensions.rb
139
+ - lib/cliutils/logger-delegator.rb
140
+ - lib/cliutils/messenging.rb
141
+ - lib/cliutils/prefs.rb
142
+ - lib/cliutils/pretty-io.rb
143
+ - lib/cliutils/version.rb
144
+ - res/readme-images/messenger-types-1.png
145
+ - res/readme-images/messenger-warn.png
146
+ - res/readme-images/multi-logger.png
147
+ - res/readme-images/prettyio-color-chart.png
148
+ - res/readme-images/prettyio-gnarly-text.png
149
+ - res/readme-images/prettyio-red-text.png
150
+ - res/readme-images/prompting.png
151
+ - res/readme-images/wrapping.png
152
+ - test/configurator_test.rb
153
+ - test/hash_extensions_test.rb
154
+ - test/logger_extensions_test.rb
155
+ - test/messenging_test.rb
156
+ - test/prefs_test.rb
157
+ - test/string_extesions_test.rb
158
+ - test/test_files/prefstest.yaml
159
+ homepage: https://github.com/bachya/cli-utils
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options:
165
+ - "--title"
166
+ - CLIUtils
167
+ - "--main"
168
+ - README.md
169
+ - "-ri"
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubyforge_project:
184
+ rubygems_version: 2.2.2
185
+ signing_key:
186
+ specification_version: 4
187
+ summary: Sugary goodness for Ruby CLI apps.
188
+ test_files:
189
+ - features/cli_manager.feature
190
+ - features/step_definitions/cli_manager_steps.rb
191
+ - features/support/env.rb
192
+ - test/configurator_test.rb
193
+ - test/hash_extensions_test.rb
194
+ - test/logger_extensions_test.rb
195
+ - test/messenging_test.rb
196
+ - test/prefs_test.rb
197
+ - test/string_extesions_test.rb
198
+ - test/test_files/prefstest.yaml
199
+ has_rdoc: true