mister_bin 0.3.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df7d632c9b2d36ebd6cd52b961d4f690868575234528fa77c563e2766d4449b2
4
- data.tar.gz: 8fef21a944ed08a965139c21ce96bf2560f1acfd0016b076345cd113d70933df
3
+ metadata.gz: 544ea89862e3731beab20f7a6e180109377fbf4ee428dc87577f4315d9d4656e
4
+ data.tar.gz: b911335298d0939f37fd7c515c573f15f5b4a84b07935fa04bdce34427cb3bd3
5
5
  SHA512:
6
- metadata.gz: 48f0fc73b3731e339e4d131df19519c203b2ce8f1e9030323867eac715fe21793d9be8193675376a6538783a1bbbadfb1c4af40fce5076377f81a5ba1a3f82cd
7
- data.tar.gz: 49f22c1ec956275a8c3c8a0681d9fc324e147db4595dea3681b5bc85212933a78738833b57dfa8eaa7221219f4dad172578c9726ea52d96cd38df0d9ca2dc2b1
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
- * [Example](#example)
20
+ * [Examples](#examples)
22
21
  * [Usage](#usage)
23
22
  * [Creating the Main Executable](#creating-the-main-executable)
24
- * [Runner Options](#runner-options)
23
+ * [Runner Options](#runner-options)
24
+ * [Runner Routes](#runner-routes)
25
25
  * [Creating Commands](#creating-commands)
26
- * [Command DSL](#command-dsl)
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
- Example
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
@@ -1,7 +1,10 @@
1
1
  require 'docopt'
2
+ require 'colsole'
2
3
 
3
4
  module MisterBin
4
5
  class Command
6
+ include Colsole
7
+
5
8
  class << self
6
9
  def description
7
10
  maker.summary || maker.help || ''
@@ -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 argv.empty?
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
@@ -1,3 +1,3 @@
1
1
  module MisterBin
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
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.0
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-05 00:00:00.000000000 Z
11
+ date: 2018-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole