mister_bin 0.1.2 → 0.2.0

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: e87b4752236683e3e699872c4d324ab6d715234789459211b12cbd5238192a13
4
- data.tar.gz: 58588e6731278f5e1c8f9802f2186eec49333d54836992782437be643a07829e
3
+ metadata.gz: 6f6758cdef54004ba6fc9f83f4b73f318213919800393c072f00d6b21daef46b
4
+ data.tar.gz: 665a7f2759ac11bf3f7850cfbc2319cded0009f4776806f821c01b1b77691f26
5
5
  SHA512:
6
- metadata.gz: f212bb72a9f67c744250135248f4bd2890142e8c11fde10c9fc9d1dbf25400cfdfa3e016e8ba89446ccea2053e089444d06b95d369d3c11f2ed6f0b557ef6ebd
7
- data.tar.gz: aa0f21c1fe5cbfba66b9bf1042073eadfe12fd7ce5ef8f47620f63a287c314d8a47891fdb2a611f7daf68ee37889565fbbb0aa4b37a417741f409270f293d975
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
- exit MisterBin::Runner.run __FILE__, ARGV
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, and contains this code:
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
- exit MisterBin::Runner.run __FILE__, ARGV
137
+ runner = MisterBin::Runner.new 'appname'
138
+ exitcode = runner.run ARGV
139
+ exit exitcode
118
140
  ```
119
141
 
120
- It will start the execution chain based on the arguments provided
121
- when running it.
142
+ ### Runner Options
122
143
 
123
- The `Runner.run` method requires two parameters:
144
+ The `Runner` method requires only the name of the main executable:
124
145
 
125
- 1. The path to the base executable file (usually, `__FILE__` is what you
126
- need).
127
- 2. An array of arguments (usually `ARGV` is what you need).
146
+ ```ruby
147
+ runner = MisterBin::Runner.new 'appname'
148
+ ```
128
149
 
129
- In addition, you may provide a `header` and a `footer` that will be
130
- displayed when executing without arguments:
150
+ In addition, you can provide an options hash:
131
151
 
132
152
  ```ruby
133
- # git
134
- #!/usr/bin/env ruby
135
- require 'mister_bin'
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
- exitcode = MisterBin::Runner.run __FILE__, ARGV,
138
- header: "This is a sample header.",
139
- footer: "This is a sample footer."
163
+ #### `header`
140
164
 
141
- exit exitcode
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
- Creating Subcommands
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
- The DSL
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
+
@@ -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 ||= PathHelper.new(additional_dir: basedir)
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
@@ -2,6 +2,7 @@ module MisterBin
2
2
 
3
3
  class PathHelper
4
4
  attr_reader :pathspec, :additional_dir
5
+ attr_writer :paths
5
6
 
6
7
  def initialize(additional_dir: nil, pathspec: nil)
7
8
  @additional_dir = additional_dir
@@ -4,18 +4,14 @@ module MisterBin
4
4
  class Runner
5
5
  include Colsole
6
6
 
7
- attr_reader :basefile, :basedir, :name, :header, :footer
8
-
9
- def self.run(basefile, argv=[], header: nil, footer: nil)
10
- new(basefile, header: header, footer: footer).run argv
11
- end
12
-
13
- def initialize(basefile, header: nil, footer: nil)
14
- @basefile = basefile
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
@@ -1,3 +1,3 @@
1
1
  module MisterBin
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
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.1.2
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-15 00:00:00.000000000 Z
11
+ date: 2018-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole