cliutils 1.4.0 → 1.4.1
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 +4 -4
- data/HISTORY.md +5 -1
- data/README.md +21 -20
- data/lib/cliutils/constants.rb +1 -1
- data/lib/cliutils/prefs/pref.rb +3 -0
- data/lib/cliutils/prefs/pref_actions/open_url_action.rb +7 -0
- data/lib/cliutils/prefs/pref_actions/pref_action.rb +23 -0
- data/res/readme-images/actions-1.png +0 -0
- data/res/readme-images/actions-2.png +0 -0
- data/res/readme-images/actions-3.png +0 -0
- metadata +6 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2a677b8cc4feed02af57e2037766c05c7d4216ef
|
4
|
+
data.tar.gz: 30029c3645a31d9f9754ee06de442827ac8aaff7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a0ac92ab729efa813a024915493697a501dc9d0f1631b74fb48bddf3fa68bbe373d828ed0813fecf12dca25118ecb57c67b691bea25c9e40bef91ea7e5f7c14
|
7
|
+
data.tar.gz: a81425ca6417a7282078490b2232a6bc7889734a1b45f99738fcafe4f934256fce3491e3ce3e95bf003aae764208c3e8736045cbc2a9e83a76bc118737c39f60
|
data/HISTORY.md
CHANGED
data/README.md
CHANGED
@@ -51,7 +51,7 @@ include CLIUtils
|
|
51
51
|
|
52
52
|
Alternatively, as described below, mix in only the libraries that you want.
|
53
53
|
|
54
|
-
Note that although this README.md is extensive, it may not cover all methods. Check out the [YARD documentation](http://rubydoc.info/github/bachya/
|
54
|
+
Note that although this README.md is extensive, it may not cover all methods. Check out the [YARD documentation](http://rubydoc.info/github/bachya/cliutils/master/frames) and the [tests](https://github.com/bachya/cliutils/tree/master/test) to see more examples.
|
55
55
|
|
56
56
|
# Libraries
|
57
57
|
|
@@ -77,7 +77,7 @@ To start, `PrettyIO` affords you colorized strings:
|
|
77
77
|
```ruby
|
78
78
|
puts 'A sample string'.red
|
79
79
|
```
|
80
|
-

|
81
81
|
|
82
82
|
You get a stable of utility methods for the common ANSI color codes:
|
83
83
|
|
@@ -96,14 +96,14 @@ You also get the `colorize` method, which allows you to define more complex colo
|
|
96
96
|
```ruby
|
97
97
|
puts 'A sample string'.colorize('35;42')
|
98
98
|
```
|
99
|
-

|
100
100
|
|
101
101
|
Naturally, memorizing the ANSI color scheme is a pain, so `PrettyIO` gives you a convenient method to look up these color combinations:
|
102
102
|
|
103
103
|
```ruby
|
104
104
|
color_chart
|
105
105
|
```
|
106
|
-

|
107
107
|
|
108
108
|
# Messaging
|
109
109
|
|
@@ -118,7 +118,7 @@ Once mixed in, you get access to `messenger`, a type of Logger that uses `Pretty
|
|
118
118
|
```ruby
|
119
119
|
messenger.warn('Hey pal, you need to be careful.')
|
120
120
|
```
|
121
|
-

|
122
122
|
|
123
123
|
## Messaging Methods
|
124
124
|
|
@@ -139,7 +139,7 @@ messenger.warn('WARNING: Tie Fighters approaching!')
|
|
139
139
|
messenger.error('Porkins died :(')
|
140
140
|
messenger.success('But Luke still blew up the Death Star!')
|
141
141
|
```
|
142
|
-

|
143
143
|
|
144
144
|
`messenger` also includes two "block" methods that allow you to wrap program execution in messages that are "longer-term".
|
145
145
|
|
@@ -176,7 +176,7 @@ puts ''
|
|
176
176
|
CLIUtils::PrettyIO.wrap = false
|
177
177
|
messenger.info(long_string)
|
178
178
|
```
|
179
|
-

|
180
180
|
|
181
181
|
## Prompting
|
182
182
|
|
@@ -186,7 +186,7 @@ messenger.info(long_string)
|
|
186
186
|
p = messenger.prompt('Are you a fan of Battlestar Galactica?', default = 'Y')
|
187
187
|
messenger.info("You answered: #{ p }")
|
188
188
|
```
|
189
|
-

|
190
190
|
|
191
191
|
When you pass a default to `messaging.prompt`, hitting `Enter` (i.e., leaving the prompt blank) will return the value of the default.
|
192
192
|
|
@@ -217,7 +217,7 @@ messenger.section('This section message should appear only in STDOUT')
|
|
217
217
|
|
218
218
|
In STDOUT:
|
219
219
|
|
220
|
-

|
221
221
|
|
222
222
|
...and in `file.txt`:
|
223
223
|
|
@@ -433,7 +433,7 @@ With valid preferences loaded, simply use `ask` to begin prompting your user:
|
|
433
433
|
```Ruby
|
434
434
|
prefs.ask
|
435
435
|
```
|
436
|
-

|
437
437
|
|
438
438
|
## Prerequisites
|
439
439
|
|
@@ -474,7 +474,7 @@ prompts:
|
|
474
474
|
```Ruby
|
475
475
|
prefs.ask
|
476
476
|
```
|
477
|
-

|
478
478
|
|
479
479
|
Be careful that you don't define any circular prerequisities (e.g., A requires B and B requires A). In that case, both preferences will be ignored by `Prefs.ask`.
|
480
480
|
|
@@ -518,7 +518,7 @@ Once in place:
|
|
518
518
|
```Ruby
|
519
519
|
prefs.ask
|
520
520
|
```
|
521
|
-

|
522
522
|
|
523
523
|
## Validators
|
524
524
|
|
@@ -556,7 +556,7 @@ prompts:
|
|
556
556
|
```Ruby
|
557
557
|
prefs.ask
|
558
558
|
```
|
559
|
-

|
560
560
|
|
561
561
|
Note that validators are evaluated in order, from top to bottom. If any validator fails, `messenger` will display an error and prompt the user to try again.
|
562
562
|
|
@@ -593,7 +593,7 @@ prompts:
|
|
593
593
|
```Ruby
|
594
594
|
prefs.ask
|
595
595
|
```
|
596
|
-

|
597
597
|
|
598
598
|
Note that behaviors are executed in order, which might give you different results than you're expecting. Using the YAML above, for example, placing the `uppercase` behavior last in the list will uppercase *the entire string* (including prefix and suffix).
|
599
599
|
|
@@ -646,8 +646,9 @@ Several items to note:
|
|
646
646
|
1. The action class needs to be wrapped in the CLIUtils module.
|
647
647
|
2. The class name needs to be the camel-case version of the `action` key in the YAML.
|
648
648
|
3. The class name needs to end with "Action".
|
649
|
-
4. The class needs to inherit from the PrefAction class.
|
650
|
-
|
649
|
+
4. The class needs to inherit from the PrefAction class. This allows it to have access to:
|
650
|
+
* `@pref`: the Pref that implemented this action
|
651
|
+
5. The class needs to implement one method: `run(parameters = {})`
|
651
652
|
|
652
653
|
### Testing
|
653
654
|
|
@@ -656,9 +657,9 @@ Let's run it!
|
|
656
657
|
```Ruby
|
657
658
|
prefs.ask
|
658
659
|
```
|
659
|
-

|
661
|
+

|
662
|
+

|
662
663
|
|
663
664
|
## Adding Pref Responses to a Configurator
|
664
665
|
|
@@ -694,7 +695,7 @@ In this case, `Prefs` will look to see if any values already exist for a specifi
|
|
694
695
|
|
695
696
|
To view my current roadmap and objectives, check out the [Trello board](https://trello.com/b/qXs7Yeir/cliutils "CLIUtils on Trello").
|
696
697
|
|
697
|
-
To report bugs with or suggest features/changes for CLIUtils, please use the [Issues Page](http://github.com/bachya/
|
698
|
+
To report bugs with or suggest features/changes for CLIUtils, please use the [Issues Page](http://github.com/bachya/cliutils/issues).
|
698
699
|
|
699
700
|
# Contributing
|
700
701
|
|
data/lib/cliutils/constants.rb
CHANGED
data/lib/cliutils/prefs/pref.rb
CHANGED
@@ -179,6 +179,7 @@ module CLIUtils
|
|
179
179
|
|
180
180
|
if (@pre[:action])
|
181
181
|
action_obj = _load_action(@pre[:action])
|
182
|
+
action_obj.pref = self
|
182
183
|
action_obj.run(@pre[:action_parameters][0])
|
183
184
|
end
|
184
185
|
end
|
@@ -190,6 +191,7 @@ module CLIUtils
|
|
190
191
|
|
191
192
|
if (@post[:action])
|
192
193
|
action_obj = _load_action(@post[:action])
|
194
|
+
action_obj.pref = self
|
193
195
|
action_obj.run(@post[:action_parameters][0])
|
194
196
|
end
|
195
197
|
end
|
@@ -204,6 +206,7 @@ module CLIUtils
|
|
204
206
|
if File.exist?(path_or_name)
|
205
207
|
# If the file exists, we're assuming that the user
|
206
208
|
# passed a filepath.
|
209
|
+
action_path = File.expand_path(path_or_name) if path_or_name.start_with?('~')
|
207
210
|
action_path = "#{ path_or_name }_action"
|
208
211
|
action_name = File.basename(path_or_name, '.*').camelize
|
209
212
|
else
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CLIUtils
|
2
|
+
# The generic base class for a Pref
|
3
|
+
# action.
|
4
|
+
class PrefAction
|
5
|
+
include Messaging
|
6
|
+
|
7
|
+
# Holds a reference to the pref that
|
8
|
+
# is implementing this action.
|
9
|
+
# @return [Pref]
|
10
|
+
attr_accessor :pref
|
11
|
+
|
12
|
+
# Runs the plugin. Note that the
|
13
|
+
# method implemented here shows
|
14
|
+
# an error (indicating that it
|
15
|
+
# needs to be implemented in a
|
16
|
+
# subclass).
|
17
|
+
# @parameter [Hash] parameters
|
18
|
+
# @return [void]
|
19
|
+
def run(parameters = {})
|
20
|
+
messenger.error("`run` method not implemented on caller: #{ self.class }")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cliutils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Bach
|
@@ -93,9 +93,14 @@ files:
|
|
93
93
|
- lib/cliutils/messaging.rb
|
94
94
|
- lib/cliutils/prefs.rb
|
95
95
|
- lib/cliutils/prefs/pref.rb
|
96
|
+
- lib/cliutils/prefs/pref_actions/open_url_action.rb
|
97
|
+
- lib/cliutils/prefs/pref_actions/pref_action.rb
|
96
98
|
- lib/cliutils/prefs/pref_behavior.rb
|
97
99
|
- lib/cliutils/prefs/pref_validation.rb
|
98
100
|
- lib/cliutils/pretty_io.rb
|
101
|
+
- res/readme-images/actions-1.png
|
102
|
+
- res/readme-images/actions-2.png
|
103
|
+
- res/readme-images/actions-3.png
|
99
104
|
- res/readme-images/messenger-types-1.png
|
100
105
|
- res/readme-images/messenger-warn.png
|
101
106
|
- res/readme-images/multi-logger.png
|