You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+36-37
Original file line number
Diff line number
Diff line change
@@ -48,16 +48,26 @@ After installing the **Commandable** gem require it somewhere that gets loaded b
48
48
49
49
Extend your class with the **Commandable** module:
50
50
51
-
class Widget
51
+
require 'commandable'
52
+
53
+
class Foo
52
54
extend Commandable
55
+
56
+
end
53
57
54
58
Then put `command` and a description above the method you want to make accessible. The description is optional but can be helpful
55
59
since it's used when automatically building your help/usage instructions.
56
60
57
-
command "create a new widget"
58
-
def new(name)
59
-
...
61
+
require 'commandable'
62
+
63
+
class Foo
64
+
extend Commandable
65
+
66
+
command "Explain what the command does"
67
+
def bar
68
+
puts "Foo::bar"
60
69
end
70
+
end
61
71
62
72
### The "`command`" command and its options
63
73
@@ -201,8 +211,7 @@ A typical help output looks something like this:
201
211
readme : displays the readme file (default)
202
212
v : <xor> Application Version
203
213
version : <xor> Application Version
204
-
help : you're looking at it now
205
-
214
+
help : you're looking at it now
206
215
207
216
208
217
### Complete demonstration app and some example classes ###
@@ -237,6 +246,16 @@ If set to true help instructions will include the default values in the paramete
237
246
# Will print:
238
247
command arg1 [arg2]
239
248
249
+
###Screen Clearing Options
250
+
251
+
**Commandable.clear\_screen**
252
+
_default = false_
253
+
Set to true to enable clearing the screen when printing help/usage instructions.
254
+
255
+
**Commandable.color\clear\_screen\_code**
256
+
_default = "\e[H\e[2J"
257
+
The escape codes used to clear the screen.
258
+
240
259
### Colorized Output Options
241
260
242
261
The help information can be colored using the standard ANSI escape commands found in the `term-ansicolor` gem. The `term-ansicolor` gem is installed as a dependency but just in case you have problems you can install it yourself by running:
@@ -263,8 +282,8 @@ Then you can do something like this:
263
282
###Color options
264
283
265
284
**Commandable.color\_output**
266
-
_default = true_
267
-
Set to false to disable colorized help/usage instructions. You might find the colors really, really annoying...
285
+
_default = false_
286
+
Set to true to enable colorized help/usage instructions.
268
287
269
288
**Commandable.color\_app\_info**
270
289
_default = intense\_white_ + bold
@@ -302,13 +321,8 @@ The color the friendly name of the error will be in error messages
302
321
\_default = intense\_black_ + bold
303
322
The color the error description will be in error messages
304
323
305
-
**Commandable.color\screen\_clear_code**
306
-
_default = "\e[H\e[2J"
307
-
The color the error description will be in error messages
308
-
309
324
The best way to see what all this means it just type `commandable help` and you'll see the help instructions in color.
310
325
311
-
312
326
### Executing the Command Line
313
327
314
328
There are two ways of using **Commandable** to run your methods. You can use its built in execute method to automatically run whatever is entered on the command line or you can have **Commandable** build an array of procs that you can execute yourself. This allows you to have finer grain control over the execution of the commands as you can deal with the return values as you run each command.
@@ -380,7 +394,6 @@ You just need to configure your bin file with the app settings and then run `Com
380
394
381
395
# Make sure you require your app after Commandable, or use
382
396
# a configuration file to load the settings then your app
383
-
# See the Widget app for an example of this.
384
397
require 'yourappname'
385
398
Commandable.execute(ARGV)
386
399
@@ -390,9 +403,7 @@ You just need to configure your bin file with the app settings and then run `Com
390
403
# Commandable.execute(ARGV, :silent)
391
404
392
405
393
-
I actually prefer to create a separate file for my **Commandable** configuration and load it in my main app file in the `lib` directory. Again, take a look at `Widget` to see what I mean.
394
-
395
-
You can get a copy of widget by running `commandable widget [path]` and it will copy the example app to the directory you specify.
406
+
I actually prefer to create a separate file for my **Commandable** configuration and load it in my main app file in the `lib` directory.
396
407
397
408
## In closing... ##
398
409
@@ -409,20 +420,17 @@ Most of all it should be simple to use so if you have any problems please drop m
409
420
410
421
2012-01-20 - Version: 0.3.0
411
422
423
+
* All features are off by default to make Commandable more friendly across platforms.
412
424
* Added ability to disable screen clearing and to set your own screen clear escape code. (Based on [John Sumsion](https://github.com/jdsumsion)'s idea)
413
425
* Decoupled screen clearing from coloring; you can have either or both.
414
426
* Fixed bug that disabled help output in silent mode. (fixed by [John Sumsion](https://github.com/jdsumsion))
415
427
* Fixed bug that didn't label the default method if screen colors were off.
416
428
* Removed monkey patch from FileUtils. It was more philosophical than necessary.
417
429
* Changed terminal coloring gem back to official the term-ansicolor from my own fork now that my changes have been pulled into it.
418
430
* Code clean up. While mostly not a real refactor I've separated out the code into functional groups (aka files).
419
-
* Removed Widget example - it was making the examples too tightly coupled to HashModel.
431
+
* Removed Widget gem example - it was making the examples too tightly coupled to HashModel.
420
432
* Removed Cucumber features.
421
433
422
-
To do
423
-
424
-
* Added some more examples.
425
-
* Updated docs to reflect changes.
426
434
427
435
2011-09-27 - Version: 0.2.3
428
436
@@ -444,28 +452,19 @@ To do
444
452
445
453
* First public release. It's 0.2.0 because 0.1.0, going by the name of Cloptions, wasn't released.
446
454
447
-
## To Do
448
-
449
-
Add ability to easily use nested argument trees without hard-coding case blocks. For instance a command that takes set of commands like `foo remote set "ftp_svr" 10.250.1.100` or `foo remote delete "ftp_svr"`.
450
-
451
-
### Next major version:
455
+
### Possible future upgrades/improvements
452
456
457
+
* See if there's a elegant way to add nested argument trees without case blocks. e.g. a command that takes set of commands like `foo remote set "ftp_svr" 10.250.1.100` and `foo remote delete "ftp_svr"`.
453
458
* Add a way to use or discover version numbers. Might have to force standardization and not allow configuration since it should be DRY.
454
-
* Needs a massive refactoring.
455
459
* Add a generator to automatically add Commandable support to your app.
456
-
* Reorganize docs to be more logical and less the result of my scribblings as I develop.
457
-
* Try to figure out how to trap `alias` so I don't you don't have to use an additional `command`.
458
-
* Better formatting of help/usage instructions, the existing one is fairly ugly.
459
-
* Use comments below `command` as the description text so you don't have to repeat yourself to get RDoc to give you docs for your functions.
460
+
* Try to figure out how to trap `alias` so you don't have to use an additional `command`.
461
+
* Use comments below `command` as the description text so you don't have to repeat yourself when documenting your code.
460
462
* Clean up RSpecs. I'm doing too many ugly tests instead of specifying behavior.
461
-
* Allow sorting of commands alphabetically or by priority
462
-
463
-
###Future versions:
464
-
465
-
* Accepting your suggestions...
463
+
* Allow sorting of commands alphabetically or by priority in the help output
466
464
* Make the help/usage directions format available to programmers without having to hack the code.
467
465
* More edge case testing.
468
466
* Allow optional parameters values to be reloaded so changing things like verbose_parameters makes the command list change. (**very** low priority)
0 commit comments