cliutils 1.2.9 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +5 -0
- data/README.md +20 -20
- data/lib/cliutils/configurator.rb +6 -26
- data/lib/cliutils/constants.rb +1 -1
- data/lib/cliutils/pretty_io.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9dcbf526eb200d6ad6ce2b5c1e76ffdcf3ae0c4
|
4
|
+
data.tar.gz: 62fe908e18ab47851682dd3dd53c71b425c9aa81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5916ccafc3e3e5df98ac6edb49a05ab04676df72d271774c4fb1230b7b8fd106d33cfa64813a0a8526314d6026bfbe81e1ce3b6616293337bb8c96c1e1e38912
|
7
|
+
data.tar.gz: 1e01491ced1114a355c9721d8c5e3969909d904fa0cc1b4738a17253af92c727870d2b47485e1a9a18c0be7baffcef7df1abd83ce740963bcc545eb32868f10e
|
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
CLIUtils
|
2
2
|
====
|
3
|
-
[![Build Status](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:
|
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
|
-
#
|
304
|
-
#
|
305
|
-
|
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
|
-
#
|
309
|
-
#
|
310
|
-
|
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
|
-
|
318
|
-
|
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 :
|
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 :
|
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
|
-
|
75
|
-
|
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
|
89
|
-
yield
|
68
|
+
if c_version < l_version
|
69
|
+
yield @current_version, @last_version
|
90
70
|
end
|
91
71
|
end
|
92
72
|
|
data/lib/cliutils/constants.rb
CHANGED
data/lib/cliutils/pretty_io.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2014-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|