README.md in cliutils-1.2.9 vs README.md in cliutils-1.3.0

- old
+ new

@@ -1,8 +1,8 @@ CLIUtils ==== -[![Build Status](https://travis-ci.org/bachya/cliutils.png?branch=master)](https://travis-ci.org/bachya/cliutils) +[![Build Status](https://travis-ci.org/bachya/cliutils.svg?branch=master)](https://travis-ci.org/bachya/cliutils) [![Gem Version](https://badge.fury.io/rb/cliutils.png)](http://badge.fury.io/rb/cliutils) CLIUtils is a library of functionality designed to alleviate common tasks and headaches when developing command-line (CLI) apps in Ruby. # Why? @@ -64,10 +64,12 @@ ```ruby include CLIUtils::PrettyIO ``` +### Colored Strings + To start, `PrettyIO` affords you colorized strings: ```ruby puts 'A sample string'.red ``` @@ -286,43 +288,41 @@ ```YAML --- app_data: # The current version of the app - APP_VERSION: 1.0.0 + APP_VERSION: 0.8.8 - # The last version that required - # a configuration change - NEWEST_CONFIG_VERSION: 1.8.0 - # ...other keys... ``` +...and that, somewhere in your app, you store a constant that contains the config version that requires a re-configuration: + +```Ruby +LATEST_CONFIG_VERSION = 0.9.5 +``` + ...this will initiate a version check (and give you the option to do something with that information): ```Ruby -# Tell your configurator the name of the key that -# stores the app's version in its configuration file. -# NOTE that you don't have to specify the section. -configuration.cur_version_key = :APP_VERSION +# Store the current version of your app in a +# property of the Configurator. +configuration.current_version = configuration.app_data['APP_VERSION'] -# Tell your configurator the name of the key that -# stores the last version that needed a configuration change. -# NOTE that you don't have to specify the section. -configuration.last_version_key = :NEWEST_CONFIG_VERSION +# 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). configuration.compare_version do |c, l| - if c < l - puts "You need to update your app; here's how:" - # ...do stuff... - else - puts "No need to update your app's config file!" - end + 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). ## 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.