cliutils 1.2.9 → 1.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 97a26794fd111748a7122e364fd21179f7d1f082
4
- data.tar.gz: 78a1352fde30e33340c46340164ddc88a9bf526f
3
+ metadata.gz: c9dcbf526eb200d6ad6ce2b5c1e76ffdcf3ae0c4
4
+ data.tar.gz: 62fe908e18ab47851682dd3dd53c71b425c9aa81
5
5
  SHA512:
6
- metadata.gz: c92816990f22349112121b23694c85ff0d85b04b8420999ec1047fb6727acc688073b3eb321ef68bb94082972c0a69150b1292a1d5254014c05a7cd76ad671c7
7
- data.tar.gz: c9d7ccaaee1a0416cd24030588c936ec285f1b7ea8ed56cc89e9c2c935631b20ab035443da84139a76c426368e33b8f7f540284091eab26b9325567b74722a7f
6
+ metadata.gz: 5916ccafc3e3e5df98ac6edb49a05ab04676df72d271774c4fb1230b7b8fd106d33cfa64813a0a8526314d6026bfbe81e1ce3b6616293337bb8c96c1e1e38912
7
+ data.tar.gz: 1e01491ced1114a355c9721d8c5e3969909d904fa0cc1b4738a17253af92c727870d2b47485e1a9a18c0be7baffcef7df1abd83ce740963bcc545eb32868f10e
data/HISTORY.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.3.9 (2014-04-12)
2
+
3
+ * Revised Configurator version checking
4
+ * Added some documentation
5
+
1
6
  # 1.2.9 (2014-04-09)
2
7
 
3
8
  * Added time Pref validator
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  CLIUtils
2
2
  ====
3
- [![Build Status](https://travis-ci.org/bachya/cliutils.png?branch=master)](https://travis-ci.org/bachya/cliutils)
3
+ [![Build Status](https://travis-ci.org/bachya/cliutils.svg?branch=master)](https://travis-ci.org/bachya/cliutils)
4
4
  [![Gem Version](https://badge.fury.io/rb/cliutils.png)](http://badge.fury.io/rb/cliutils)
5
5
 
6
6
  CLIUtils is a library of functionality designed to alleviate common tasks and headaches when developing command-line (CLI) apps in Ruby.
@@ -66,6 +66,8 @@ First stop on our journey is better client IO via `PrettyIO`. To activate, simpl
66
66
  include CLIUtils::PrettyIO
67
67
  ```
68
68
 
69
+ ### Colored Strings
70
+
69
71
  To start, `PrettyIO` affords you colorized strings:
70
72
 
71
73
  ```ruby
@@ -288,41 +290,39 @@ Assume you have a config file that looks like this:
288
290
  ---
289
291
  app_data:
290
292
  # The current version of the app
291
- APP_VERSION: 1.0.0
292
-
293
- # The last version that required
294
- # a configuration change
295
- NEWEST_CONFIG_VERSION: 1.8.0
293
+ APP_VERSION: 0.8.8
296
294
 
297
295
  # ...other keys...
298
296
  ```
299
297
 
298
+ ...and that, somewhere in your app, you store a constant that contains the config version that requires a re-configuration:
299
+
300
+ ```Ruby
301
+ LATEST_CONFIG_VERSION = 0.9.5
302
+ ```
303
+
300
304
  ...this will initiate a version check (and give you the option to do something with that information):
301
305
 
302
306
  ```Ruby
303
- # Tell your configurator the name of the key that
304
- # stores the app's version in its configuration file.
305
- # NOTE that you don't have to specify the section.
306
- configuration.cur_version_key = :APP_VERSION
307
+ # Store the current version of your app in a
308
+ # property of the Configurator.
309
+ configuration.current_version = configuration.app_data['APP_VERSION']
307
310
 
308
- # Tell your configurator the name of the key that
309
- # stores the last version that needed a configuration change.
310
- # NOTE that you don't have to specify the section.
311
- configuration.last_version_key = :NEWEST_CONFIG_VERSION
311
+ # Store the last version of your app that required
312
+ # a re-configuration in a property of the Configurator.
313
+ configuration.last_version = LATEST_CONFIG_VERSION
312
314
 
313
315
  # Run the check and use a block to get
314
316
  # the current and "last-needing-changes"
315
317
  # versions (and do something about it).
316
318
  configuration.compare_version do |c, l|
317
- if c < l
318
- puts "You need to update your app; here's how:"
319
- # ...do stuff...
320
- else
321
- puts "No need to update your app's config file!"
322
- end
319
+ puts "We need to update from #{c} to #{l}..."
320
+ # ...do stuff...
323
321
  end
324
322
  ```
325
323
 
324
+ Note that if the current version is *later* than the last version that required re-configuration, the whole block is skipped over (allowing your app to get on with its day).
325
+
326
326
  ## Prefs
327
327
 
328
328
  Many times, CLI apps need to ask their users some questions, collect the feedback, validate it, and store it. CLIUtils makes this a breeze via the `Prefs` class.
@@ -8,13 +8,13 @@ module CLIUtils
8
8
  # Stores the Configurator key that refers
9
9
  # to the current configuration version.
10
10
  # @return [Symbol]
11
- attr_accessor :cur_version_key
11
+ attr_accessor :current_version
12
12
 
13
13
  # Stores the Configurator key that refers
14
14
  # to the value at which the app last changed
15
15
  # config versions.
16
16
  # @return [Symbol]
17
- attr_accessor :last_version_key
17
+ attr_accessor :last_version
18
18
 
19
19
  # Stores the path to the configuration file.
20
20
  # @return [String]
@@ -55,15 +55,6 @@ module CLIUtils
55
55
  end
56
56
  end
57
57
 
58
- # Checks to see whether the passed key (and a
59
- # non-nil value) exist in the @data Hash.
60
- # @param [Symbol] key The key to search for
61
- # @return [Boolean]
62
- def check_key_and_value(key)
63
- !@data.recursive_find_by_key(key).nil? &&
64
- !@data.recursive_find_by_key(key).empty?
65
- end
66
-
67
58
  # Compares the current version (if it exists) to
68
59
  # the last version that needed a configuration
69
60
  # change (if it exists). Assuming they exist and
@@ -71,22 +62,11 @@ module CLIUtils
71
62
  # version, execute a passed block.
72
63
  # @return [void]
73
64
  def compare_version
74
- unless check_key_and_value(@cur_version_key)
75
- fail 'Cannot check version; no current version found'
76
- end
77
-
78
- unless check_key_and_value(@last_version_key)
79
- fail 'Cannot check version; no previous version found'
80
- end
81
-
82
- c_version = @data.recursive_find_by_key(@cur_version_key)
83
- c_version_gem = Gem::Version.new(c_version)
84
-
85
- l_version = @data.recursive_find_by_key(@last_version_key)
86
- l_version_gem = Gem::Version.new(l_version)
65
+ c_version = Gem::Version.new(@current_version)
66
+ l_version = Gem::Version.new(@last_version)
87
67
 
88
- if c_version_gem < l_version_gem
89
- yield c_version, l_version
68
+ if c_version < l_version
69
+ yield @current_version, @last_version
90
70
  end
91
71
  end
92
72
 
@@ -1,5 +1,5 @@
1
1
  # Stores constants to use.
2
2
  module CLIUtils
3
3
  # The current version of the gem
4
- VERSION = '1.2.9'
4
+ VERSION = '1.3.0'
5
5
  end
@@ -94,7 +94,7 @@ module CLIUtils
94
94
  end
95
95
 
96
96
  # Empty method so that Messaging doesn't freak
97
- # out when passed a debug message.
97
+ # out when passed a log message.
98
98
  # @return [void]
99
99
  def log(m); end
100
100
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cliutils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.9
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Bach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-09 00:00:00.000000000 Z
11
+ date: 2014-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler