README.md in cliutils-1.3.0 vs README.md in cliutils-1.3.1
- old
+ new
@@ -141,11 +141,11 @@
```Ruby
# Outputs 'Starting up...', runs the code in
# `# do stuff here`, and once complete,
# outputs 'Done!' on the same line.
-messenger.info_block('Starting up...', 'Done!', multiline = false) {
+messenger.info_block('Starting up...', 'Done!', multiline = false) {
# ...do stuff here...
}
# Outputs 'MY SECTION' and then runs
# the code in `# do stuff here` before
@@ -280,12 +280,14 @@
age: 45
```
### Checking Configuration Versions
-Often, you'll want to check the user's current version of your app against the last version that required some sort of configuration change. `configurator` allows for this via its `compare_version` method.
+Often, you'll want to check the user's current version of your app against the last version that required some sort of configuration change; moreover, you'll want to run some "re-configuration" steps if the user's version is older than the last version that required a configuration update.
+`configurator` allows for this via its `compare_version` method.
+
Assume you have a config file that looks like this:
```YAML
---
app_data:
@@ -310,21 +312,24 @@
# Store the last version of your app that required
# a re-configuration in a property of the Configurator.
configuration.last_version = LATEST_CONFIG_VERSION
-# Run the check and use a block to get
-# the current and "last-needing-changes"
-# versions (and do something about it).
+# Run the check. If the current version is older than
+# the "last" version, use a block to tell the Configurator
+# what to do.
configuration.compare_version do |c, l|
puts "We need to update from #{c} to #{l}..."
# ...do stuff...
end
```
-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).
+Two items to note:
+1. If the `current_version` parameter is `nil`, the Configurator will assume that it the app needs to be updated when `compare_version` is run.
+2. 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).
+
## Prefs
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.
### Basic Schema
@@ -557,10 +562,10 @@
validators:
- capitalize # Turns "answer" into "Answer"
- expand_filepath # Runs File.expand_path on the answer
- lowercase # Turns "AnSwEr" into "answer"
- prefix: 'test ' # Prepends 'test ' to the answer
- - suffix: 'test ' # Appends 'test ' to the answer
+ - suffix: 'test ' # Appends 'test ' to the answer
- titlecase # Turns "the answer" into "The Answer"
- uppercase # Turns "answer" to "ANSWER"
```
An example: