mister_bin 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +62 -23
- data/lib/mister_bin/commands.rb +10 -3
- data/lib/mister_bin/path_helper.rb +1 -0
- data/lib/mister_bin/runner.rb +9 -13
- 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: 6f6758cdef54004ba6fc9f83f4b73f318213919800393c072f00d6b21daef46b
|
4
|
+
data.tar.gz: 665a7f2759ac11bf3f7850cfbc2319cded0009f4776806f821c01b1b77691f26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c493f1c9e7e104be1c95d86baa4c3a806ae90272e592938787d17ae363b82a442265f7984ff32ba4708bc764124563a534b029f15180ba852430cc8d0b35e63
|
7
|
+
data.tar.gz: 600cda0b6a7faaa6b98a32eb970cfcc19e725dcf4402eb741d29ce036568c062e64a07602b580d1330191e87fe99b9a4c816fd6ceb8356c78d264336b2eb5fc3
|
data/README.md
CHANGED
@@ -4,6 +4,7 @@ Mister Bin
|
|
4
4
|
[![Gem Version](https://badge.fury.io/rb/mister_bin.svg)](https://badge.fury.io/rb/mister_bin)
|
5
5
|
[![Build Status](https://travis-ci.org/DannyBen/mister_bin.svg?branch=master)](https://travis-ci.org/DannyBen/mister_bin)
|
6
6
|
[![Maintainability](https://api.codeclimate.com/v1/badges/ae82443a99c2839d8ba8/maintainability)](https://codeclimate.com/github/DannyBen/mister_bin/maintainability)
|
7
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/ae82443a99c2839d8ba8/test_coverage)](https://codeclimate.com/github/DannyBen/mister_bin/test_coverage)
|
7
8
|
|
8
9
|
---
|
9
10
|
|
@@ -11,6 +12,20 @@ Build modular command line utilities.
|
|
11
12
|
|
12
13
|
---
|
13
14
|
|
15
|
+
Contents
|
16
|
+
--------------------------------------------------
|
17
|
+
|
18
|
+
* [Contents](#contents)
|
19
|
+
* [Installation](#installation)
|
20
|
+
* [Design Goals](#design-goals)
|
21
|
+
* [Example](#example)
|
22
|
+
* [Usage](#usage)
|
23
|
+
* [Creating the Main Executable](#creating-the-main-executable)
|
24
|
+
* [Runner Options](#runner-options)
|
25
|
+
* [Creating Commands](#creating-commands)
|
26
|
+
* [Command DSL](#command-dsl)
|
27
|
+
|
28
|
+
|
14
29
|
Installation
|
15
30
|
--------------------------------------------------
|
16
31
|
|
@@ -57,10 +72,12 @@ The `git` executable:
|
|
57
72
|
#!/usr/bin/env ruby
|
58
73
|
require 'mister_bin'
|
59
74
|
|
60
|
-
|
75
|
+
runner = MisterBin::Runner.new 'git', basedir: __dir__
|
76
|
+
exitcode = runner.run ARGV
|
61
77
|
```
|
62
78
|
|
63
79
|
The file to handle the `git push` command:
|
80
|
+
|
64
81
|
```ruby
|
65
82
|
# git-push.rb
|
66
83
|
version "0.1.0"
|
@@ -107,47 +124,69 @@ file, simply implement these instead:
|
|
107
124
|
Creating the Main Executable
|
108
125
|
--------------------------------------------------
|
109
126
|
|
110
|
-
The main executable is usually simple
|
127
|
+
The main executable is usually simple and only serves to initialize Mister
|
128
|
+
Bin with options.
|
129
|
+
|
130
|
+
This is the minimal code:
|
111
131
|
|
112
132
|
```ruby
|
113
133
|
# git
|
114
134
|
#!/usr/bin/env ruby
|
115
135
|
require 'mister_bin'
|
116
136
|
|
117
|
-
|
137
|
+
runner = MisterBin::Runner.new 'appname'
|
138
|
+
exitcode = runner.run ARGV
|
139
|
+
exit exitcode
|
118
140
|
```
|
119
141
|
|
120
|
-
|
121
|
-
when running it.
|
142
|
+
### Runner Options
|
122
143
|
|
123
|
-
The `Runner
|
144
|
+
The `Runner` method requires only the name of the main executable:
|
124
145
|
|
125
|
-
|
126
|
-
|
127
|
-
|
146
|
+
```ruby
|
147
|
+
runner = MisterBin::Runner.new 'appname'
|
148
|
+
```
|
128
149
|
|
129
|
-
In addition, you
|
130
|
-
displayed when executing without arguments:
|
150
|
+
In addition, you can provide an options hash:
|
131
151
|
|
132
152
|
```ruby
|
133
|
-
|
134
|
-
|
135
|
-
|
153
|
+
options = {
|
154
|
+
header: 'My command line app'
|
155
|
+
footer: 'Use --help for additional info',
|
156
|
+
basedir: __dir__,
|
157
|
+
isolate: true
|
158
|
+
}
|
159
|
+
|
160
|
+
runner = MisterBin::Runner.new 'appname', options
|
161
|
+
```
|
136
162
|
|
137
|
-
|
138
|
-
header: "This is a sample header.",
|
139
|
-
footer: "This is a sample footer."
|
163
|
+
#### `header`
|
140
164
|
|
141
|
-
|
142
|
-
|
165
|
+
Text to display before the list of commands.
|
166
|
+
|
167
|
+
#### `footer`
|
168
|
+
|
169
|
+
Text to display after the list of commands.
|
170
|
+
|
171
|
+
#### `basedir`
|
143
172
|
|
173
|
+
The directory that holds the command files.
|
144
174
|
|
175
|
+
By default, the runner will look for its command files in all the `PATH`
|
176
|
+
directories. You may add another directory to this search path by specifying
|
177
|
+
it with `basedir`
|
145
178
|
|
146
|
-
|
179
|
+
#### `isolate`
|
180
|
+
|
181
|
+
If you wish to prevent runner from searching in the `PATH` directories,
|
182
|
+
specify `isolate: true`
|
183
|
+
|
184
|
+
|
185
|
+
Creating Commands
|
147
186
|
--------------------------------------------------
|
148
187
|
|
149
188
|
When the main executable is executed, it will look for files matching a
|
150
|
-
specific pattern in the same directory
|
189
|
+
specific pattern in the same directory and in the `PATH`.
|
151
190
|
|
152
191
|
Assuming the main executable is called `myapp`, it will look for
|
153
192
|
`myapp-*.rb` files (e.g. `myapp-status.rb`)
|
@@ -157,8 +196,7 @@ their actions.
|
|
157
196
|
|
158
197
|
|
159
198
|
|
160
|
-
|
161
|
-
--------------------------------------------------
|
199
|
+
### Command DSL
|
162
200
|
|
163
201
|
The DSL is designed to create a [docopt][1] document. Most commands are
|
164
202
|
optional.
|
@@ -201,3 +239,4 @@ end
|
|
201
239
|
|
202
240
|
|
203
241
|
[1]: http://docopt.org/
|
242
|
+
|
data/lib/mister_bin/commands.rb
CHANGED
@@ -2,11 +2,12 @@ module MisterBin
|
|
2
2
|
|
3
3
|
# This class handles listing and finding command files
|
4
4
|
class Commands
|
5
|
-
attr_reader :basename, :basedir
|
5
|
+
attr_reader :basename, :basedir, :isolate
|
6
6
|
|
7
|
-
def initialize(basename, basedir='.')
|
7
|
+
def initialize(basename, basedir='.', isolate: false)
|
8
8
|
@basename = basename
|
9
9
|
@basedir = basedir
|
10
|
+
@isolate = isolate
|
10
11
|
end
|
11
12
|
|
12
13
|
def all
|
@@ -45,7 +46,13 @@ module MisterBin
|
|
45
46
|
end
|
46
47
|
|
47
48
|
def path_helper
|
48
|
-
@path_helper ||=
|
49
|
+
@path_helper ||= path_helper!
|
50
|
+
end
|
51
|
+
|
52
|
+
def path_helper!
|
53
|
+
helper = PathHelper.new(additional_dir: basedir)
|
54
|
+
helper.paths = [basedir] if isolate
|
55
|
+
helper
|
49
56
|
end
|
50
57
|
end
|
51
58
|
end
|
data/lib/mister_bin/runner.rb
CHANGED
@@ -4,18 +4,14 @@ module MisterBin
|
|
4
4
|
class Runner
|
5
5
|
include Colsole
|
6
6
|
|
7
|
-
attr_reader :
|
8
|
-
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
@
|
15
|
-
@header = header
|
16
|
-
@footer = footer
|
17
|
-
@basedir = File.dirname basefile
|
18
|
-
@name = File.basename basefile
|
7
|
+
attr_reader :name, :basedir, :header, :footer, :isolate
|
8
|
+
|
9
|
+
def initialize(name, opts={})
|
10
|
+
@name = name
|
11
|
+
@header = opts[:header]
|
12
|
+
@footer = opts[:footer]
|
13
|
+
@isolate = opts[:isolate]
|
14
|
+
@basedir = opts[:basedir]
|
19
15
|
end
|
20
16
|
|
21
17
|
def run(argv=[])
|
@@ -57,7 +53,7 @@ module MisterBin
|
|
57
53
|
end
|
58
54
|
|
59
55
|
def commands
|
60
|
-
@commands ||= Commands.new name, basedir
|
56
|
+
@commands ||= Commands.new name, basedir, isolate: isolate
|
61
57
|
end
|
62
58
|
end
|
63
59
|
end
|
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.
|
4
|
+
version: 0.2.0
|
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-04-
|
11
|
+
date: 2018-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|