mister_bin 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +47 -14
- data/lib/mister_bin/command.rb +3 -0
- data/lib/mister_bin/runner.rb +10 -3
- data/lib/mister_bin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 544ea89862e3731beab20f7a6e180109377fbf4ee428dc87577f4315d9d4656e
|
4
|
+
data.tar.gz: b911335298d0939f37fd7c515c573f15f5b4a84b07935fa04bdce34427cb3bd3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ada4970fd1a7a1de6ad509e537e97fe8a2544d6c1594205d0921e18988ce6a536d9c3e6833fd2817b1951efeb1808b4bd5484734860a8dcf3807bfd259df050
|
7
|
+
data.tar.gz: 4df60533f5e1935911e9827f742978583256841be72667da39b79586e58ba1ad8cdc87adce4e529ea0f626b70f44bef04d1b9fb3f82f40d0fe8a7691a0193f17
|
data/README.md
CHANGED
@@ -15,15 +15,17 @@ A command line framework for adding command line utilities to your gems.
|
|
15
15
|
Contents
|
16
16
|
--------------------------------------------------
|
17
17
|
|
18
|
-
* [Contents](#contents)
|
19
18
|
* [Installation](#installation)
|
20
19
|
* [Design Goals](#design-goals)
|
21
|
-
* [
|
20
|
+
* [Examples](#examples)
|
22
21
|
* [Usage](#usage)
|
23
22
|
* [Creating the Main Executable](#creating-the-main-executable)
|
24
|
-
|
23
|
+
* [Runner Options](#runner-options)
|
24
|
+
* [Runner Routes](#runner-routes)
|
25
25
|
* [Creating Commands](#creating-commands)
|
26
|
-
|
26
|
+
* [Command DSL](#command-dsl)
|
27
|
+
* [In the Wild](#in-the-wild)
|
28
|
+
|
27
29
|
|
28
30
|
|
29
31
|
Installation
|
@@ -37,8 +39,6 @@ Design Goals
|
|
37
39
|
--------------------------------------------------
|
38
40
|
|
39
41
|
- Provide an easy and minimalistic DSL for building command line utilities.
|
40
|
-
- Drastically reduce the need for boilerplate code and unnecessary wrappers
|
41
|
-
involved in building command line utilities.
|
42
42
|
- Provide a mechanism for separating each command and subcommand to its
|
43
43
|
own file.
|
44
44
|
- Allow gem developers to easily add command line interface to their gems.
|
@@ -46,10 +46,10 @@ Design Goals
|
|
46
46
|
|
47
47
|
|
48
48
|
|
49
|
-
|
49
|
+
Examples
|
50
50
|
--------------------------------------------------
|
51
51
|
|
52
|
-
See the [example](/example) folder.
|
52
|
+
See the [example](/example) folder for several example use cases.
|
53
53
|
|
54
54
|
|
55
55
|
|
@@ -105,6 +105,19 @@ Text to display before the list of commands.
|
|
105
105
|
|
106
106
|
Text to display after the list of commands.
|
107
107
|
|
108
|
+
#### `commands`
|
109
|
+
|
110
|
+
A hash of `{ 'regex' => ClassName }` to serve as command routes.
|
111
|
+
This is equivalent to adding routes later with
|
112
|
+
`runner.route 'regex', to: ClassName`.
|
113
|
+
|
114
|
+
|
115
|
+
#### `handler`
|
116
|
+
|
117
|
+
Provide a single handler to all commands. When this is provided, `commands`
|
118
|
+
are ignored.
|
119
|
+
This is equivalent to using `runner.route_all to: ClassName`.
|
120
|
+
|
108
121
|
|
109
122
|
### Runner Routes
|
110
123
|
|
@@ -128,6 +141,20 @@ runner.route 'config init', to: ConfigInitializerCommand
|
|
128
141
|
runner.route 'config show', to: ConfigDisplayerCommand
|
129
142
|
```
|
130
143
|
|
144
|
+
If you wish to route all commands to the same class, you can use:
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
runner = MisterBin::Runner.new
|
148
|
+
runner.route_all to: <Class Name>
|
149
|
+
```
|
150
|
+
|
151
|
+
for example:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
runner = MisterBin::Runner.new
|
155
|
+
runner.route_all to: GlobalCommand
|
156
|
+
```
|
157
|
+
|
131
158
|
|
132
159
|
Creating Commands
|
133
160
|
--------------------------------------------------
|
@@ -192,13 +219,19 @@ environment "SECRET", "There is no spoon"
|
|
192
219
|
# Provide examples
|
193
220
|
example "app ls"
|
194
221
|
example "app ls --all"
|
195
|
-
|
196
|
-
# Define the actual action to execute when the command is called
|
197
|
-
# All arguments will be provided to your block.
|
198
|
-
action do |args|
|
199
|
-
puts args['--all'] ? "success --all" : "success"
|
200
|
-
end
|
201
222
|
```
|
202
223
|
|
203
224
|
|
225
|
+
In the Wild
|
226
|
+
--------------------------------------------------
|
227
|
+
|
228
|
+
Several examples of real world use of Mister Bin in the wild (well,
|
229
|
+
"In the Back Yard" really...).
|
230
|
+
|
231
|
+
- [Kojo][2] - Command line utility for generating config files from templates and definition files
|
232
|
+
- [Madman][3] - The Markdown Swiss Army Knife
|
233
|
+
|
234
|
+
|
204
235
|
[1]: http://docopt.org/
|
236
|
+
[2]: https://github.com/DannyBen/kojo
|
237
|
+
[3]: https://github.com/DannyBen/madman
|
data/lib/mister_bin/command.rb
CHANGED
data/lib/mister_bin/runner.rb
CHANGED
@@ -4,21 +4,28 @@ module MisterBin
|
|
4
4
|
class Runner
|
5
5
|
include Colsole
|
6
6
|
|
7
|
-
attr_reader :header, :footer, :version, :commands
|
7
|
+
attr_reader :header, :footer, :version, :commands, :handler
|
8
8
|
|
9
9
|
def initialize(opts={})
|
10
10
|
@header = opts[:header]
|
11
11
|
@footer = opts[:footer]
|
12
12
|
@version = opts[:version]
|
13
13
|
@commands = opts[:commands] || {}
|
14
|
+
@handler = opts[:handler]
|
14
15
|
end
|
15
16
|
|
16
|
-
def route(key, to:
|
17
|
+
def route(key, to:)
|
17
18
|
commands[key] = to
|
18
19
|
end
|
19
20
|
|
21
|
+
def route_all(to:)
|
22
|
+
@handler = to
|
23
|
+
end
|
24
|
+
|
20
25
|
def run(argv=[])
|
21
|
-
if
|
26
|
+
if handler
|
27
|
+
handler.execute argv
|
28
|
+
elsif argv.empty?
|
22
29
|
show_subs
|
23
30
|
elsif argv == ['--version'] and version
|
24
31
|
puts version
|
data/lib/mister_bin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mister_bin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-08-
|
11
|
+
date: 2018-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|