mister_bin 0.7.5 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 913595208325759296ef5f3d504d5980d0c2f9083f5b25ef49eccdc4679231a4
4
- data.tar.gz: 147428144596b31f175e0e92495479c6eb0b49e73187e0de7b1daba2d477f2f5
3
+ metadata.gz: b8b37499324199dee43edefc92606a2a697ce9dd132c6ef11803a6037e259c23
4
+ data.tar.gz: 5bd2375c5eea1a0a936cdbde439d8864975bc068ab61ac24a79f6c52ef2987a8
5
5
  SHA512:
6
- metadata.gz: 5c39bd237a0930017599d9832bdaebd7396f2727500f486bfd56b8b743d89e89990f428cf258ddf8c7330ff190e6655b02d229cfe1da5ff003470431c7744b3d
7
- data.tar.gz: e1372df188c909c7e1a0d6e49513d63e64c4d07f98db07d0967eadca1c98b2f428726685d429739e1ab65ca5e3f7513bf99367e619151e395d7258967997eaed
6
+ metadata.gz: e31a33f9192da8ad523bc29a299bc373d39dcedbc8dc96d39e4a90e748a5e4321189eaea462a1823ee88226f2d22bcebf8fab05cfca5850219ef9d2fb094560b
7
+ data.tar.gz: 97c81e608bc71af98922ce740792dc0ee0d235a1dca08c18f6383fe9aa87a23d0d09cb620c564ad3066cd848d0918a0c499e1e43075205058b18051cf8bf9f4f
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
- Mister Bin
2
- ==================================================
1
+ # Mister Bin
3
2
 
4
3
  [![Gem Version](https://badge.fury.io/rb/mister_bin.svg)](https://badge.fury.io/rb/mister_bin)
5
4
  [![Build Status](https://github.com/DannyBen/mister_bin/workflows/Test/badge.svg)](https://github.com/DannyBen/mister_bin/actions?query=workflow%3ATest)
@@ -12,55 +11,32 @@ interfaces for your gem or other Ruby application.
12
11
 
13
12
  ---
14
13
 
15
- Contents
16
- --------------------------------------------------
17
-
18
- * [Installation](#installation)
19
- * [Feature Highlights](#feature-highlights)
20
- * [Examples](#examples)
21
- * [Usage](#usage)
22
- * [Creating the Main Executable](#creating-the-main-executable)
23
- * [Runner Options](#runner-options)
24
- * [Runner Routes](#runner-routes)
25
- * [Creating Commands](#creating-commands)
26
- * [Command DSL](#command-dsl)
27
- * [Interactive Terminal](#interactive-terminal)
28
- * [Terminal features](#terminal-features)
29
- * [Terminal options](#terminal-options)
30
- * [In the Wild](#in-the-wild)
31
-
32
-
33
-
34
- Installation
35
- --------------------------------------------------
36
-
37
- $ gem install mister_bin
38
-
14
+ ## Installation
39
15
 
16
+ ```
17
+ $ gem install mister_bin
18
+ ```
40
19
 
41
- Feature Highlights
42
- --------------------------------------------------
20
+ ## Feature Highlights
43
21
 
44
22
  - Easy to use and minimalistic DSL for describing your command line actions.
45
23
  - Each command is defined with a separate class for maximum testability and
46
24
  scalability.
47
25
  - Commands can have subcommands.
48
- - Designed for gem developers.
49
-
26
+ - Commands can have aliases.
27
+ - Designed primarily for gem developers.
50
28
 
29
+ ## Examples
51
30
 
52
- Examples
53
- --------------------------------------------------
31
+ This screencast shows the command line output of several Ruby gems that were
32
+ created with Mister Bin:
54
33
 
55
- ![Demo](https://raw.githubusercontent.com/DannyBen/mister_bin/master/demo/demo.gif)
34
+ ![Demo](support/demo/cast.gif)
56
35
 
57
36
  - See the [examples](/examples) folder for several example use cases.
58
37
  - For real world examples, see the [In the Wild](#in-the-wild) section.
59
38
 
60
-
61
-
62
- Usage
63
- --------------------------------------------------
39
+ ## Usage
64
40
 
65
41
  Creating a command line utility with Mister Bin involves at least two files:
66
42
 
@@ -75,10 +51,7 @@ input, and if it finds one and one only, it will execute it. For example,
75
51
  if you have a `server` command, you can execute it with `yourapp s` if it
76
52
  is the only command that starts with an `s`.
77
53
 
78
-
79
-
80
- Creating the Main Executable
81
- --------------------------------------------------
54
+ ## Creating the Main Executable
82
55
 
83
56
  The main executable is usually simple and only serves to initialize Mister
84
57
  Bin with options.
@@ -152,6 +125,15 @@ runner.route 'greet', to: GreetCommand
152
125
  runner.route 'config', to: ConfigCommand
153
126
  ```
154
127
 
128
+ The first argument to the `route` method can be an array. In this case, the
129
+ first element of the array will be considered the primary command name, and the
130
+ other elements will be considered aliases.
131
+
132
+ ```ruby
133
+ runner = MisterBin::Runner.new
134
+ runner.route %w[dir ls list], to: DirCommand
135
+ ```
136
+
155
137
  If you wish to route all commands to the same class, you can use:
156
138
 
157
139
  ```ruby
@@ -166,10 +148,7 @@ runner = MisterBin::Runner.new
166
148
  runner.route_all to: GlobalCommand
167
149
  ```
168
150
 
169
-
170
-
171
- Creating Commands
172
- --------------------------------------------------
151
+ ## Creating Commands
173
152
 
174
153
  Create command classes by inheriting from `MisterBin::Command`, for example:
175
154
 
@@ -182,7 +161,7 @@ class GreetCommand < MisterBin::Command
182
161
  param "NAME", "The recipient of the greeting"
183
162
 
184
163
  def run
185
- # args hash is available everywhere in the calss
164
+ # args hash is available everywhere in the class
186
165
  name = args['NAME'] || 'Luke'
187
166
  puts "#{name}... I am your father..."
188
167
  end
@@ -240,14 +219,12 @@ example "app ls"
240
219
  example "app ls --all"
241
220
  ```
242
221
 
222
+ ## Interactive Terminal
243
223
 
244
-
245
- Interactive Terminal
246
- --------------------------------------------------
247
224
  Mister Bin comes with an interactive terminal that allows you to set up a
248
225
  console that sends all commands to your runner.
249
226
 
250
- ![Demo](https://raw.githubusercontent.com/DannyBen/mister_bin/master/demo/terminal.gif)
227
+ ![Demo](support/demo/terminal.gif)
251
228
 
252
229
  See the [terminal example](/examples/06-terminal) folder.
253
230
 
@@ -276,7 +253,7 @@ terminal.start
276
253
  The `MisterBin::Terminal.new` command accepts an optional second argument. If
277
254
  provided, it should be a options hash:
278
255
 
279
- ```
256
+ ```ruby
280
257
  terminal = MisterBin::Terminal.new runner, {
281
258
  header: "Welcome",
282
259
  autocomplete: %w[--help greet]
@@ -288,7 +265,7 @@ commands that are not handled by your runner. For example, this piece of code
288
265
  will capture the `/cd ...` command from the terminal and pass it to your
289
266
  block:
290
267
 
291
- ```
268
+ ```ruby
292
269
  terminal = MisterBin::Terminal.new runner
293
270
  terminal.on '/cd' do |args|
294
271
  Dir.chdir args[0] if args[0]
@@ -340,8 +317,7 @@ If true, commands that start with `/` will *not* be delegated to the stsrem.
340
317
  Default: `false`.
341
318
 
342
319
 
343
- In the Wild
344
- --------------------------------------------------
320
+ ## In the Wild
345
321
 
346
322
  Several examples of real world use of Mister Bin in the wild (well,
347
323
  "In the Back Yard" really...).
@@ -351,16 +327,18 @@ Several examples of real world use of Mister Bin in the wild (well,
351
327
  - [Jobly] - Compact job server with API, CLI and Web UI
352
328
  - [Kojo] - Command line utility for generating config files from templates and definition files
353
329
  - [Madman] - The Markdown Swiss Army Knife
330
+ - [Madness] - Instant Markdown Server
354
331
  - [Slacktail] - Command line utility for following your Slack chat from the terminal
355
332
  - [Site Link Analyzer] - Command line utility for finding broken links in a site
356
333
 
357
334
 
358
- [docopt]: http://docopt.org/
359
- [Kojo]: https://github.com/DannyBen/kojo
360
- [Madman]: https://github.com/DannyBen/madman
361
335
  [AudioAddict]: https://github.com/DannyBen/audio_addict
336
+ [Bashly]: https://github.com/DannyBen/bashly
362
337
  [Colsole]: https://github.com/dannyben/colsole
338
+ [docopt]: http://docopt.org/
363
339
  [Jobly]: https://github.com/dannyben/jobly
364
- [Slacktail]: https://github.com/dannyben/slacktail
340
+ [Kojo]: https://github.com/DannyBen/kojo
341
+ [Madman]: https://github.com/DannyBen/madman
342
+ [Madness]: https://github.com/DannyBen/madness
365
343
  [Site Link Analyzer]: https://github.com/dannyben/sla
366
- [Bashly]: https://github.com/DannyBen/bashly
344
+ [Slacktail]: https://github.com/dannyben/slacktail
@@ -18,7 +18,7 @@ module MisterBin
18
18
  exitcode.is_a?(Numeric) ? exitcode : 0
19
19
  rescue DocoptNG::Exit => e
20
20
  puts e.message
21
- 1
21
+ e.exit_code
22
22
  end
23
23
 
24
24
  class << self
@@ -1,4 +1,5 @@
1
1
  require 'colsole'
2
+ require 'debug'
2
3
 
3
4
  module MisterBin
4
5
  class Runner
@@ -15,7 +16,13 @@ module MisterBin
15
16
  end
16
17
 
17
18
  def route(key, to:)
18
- commands[key] = to
19
+ if key.is_a? Array
20
+ target = key.shift
21
+ commands[target] = to
22
+ key.each { |alias_name| aliases[alias_name] = target }
23
+ else
24
+ commands[key] = to
25
+ end
19
26
  end
20
27
 
21
28
  def route_all(to:)
@@ -30,13 +37,16 @@ module MisterBin
30
37
  elsif (argv == ['--help']) || (argv == ['-h'])
31
38
  show_help
32
39
  elsif version && ((argv == ['--version']) || (argv == ['-v']))
33
- puts version
34
- 1
40
+ show_version
35
41
  else
36
42
  execute argv
37
43
  end
38
44
  end
39
45
 
46
+ def aliases
47
+ @aliases ||= {}
48
+ end
49
+
40
50
  private
41
51
 
42
52
  def execute(argv)
@@ -55,11 +65,25 @@ module MisterBin
55
65
  command = argv[0]
56
66
  return argv if commands.has_key? command
57
67
 
58
- candidates = commands.keys.grep(/^#{command}/)
59
- argv[0] = candidates.first if candidates.count == 1
68
+ argv[0] = find_target_command argv[0]
60
69
  argv
61
70
  end
62
71
 
72
+ def find_target_command(input)
73
+ candidates = commands.keys.grep(/^#{input}/)
74
+ return candidates.first if candidates.count == 1
75
+
76
+ candidates = aliases.keys.grep(/^#{input}/)
77
+ return aliases[candidates.first] if candidates.count == 1
78
+
79
+ input
80
+ end
81
+
82
+ def show_version
83
+ puts version
84
+ 0
85
+ end
86
+
63
87
  def show_subs
64
88
  if commands.empty?
65
89
  say 'No subcommands found'
@@ -89,11 +113,11 @@ module MisterBin
89
113
  def show_help
90
114
  if commands.empty?
91
115
  say 'No subcommands found'
116
+ 1
92
117
  else
93
118
  show_help!
119
+ 0
94
120
  end
95
-
96
- 1
97
121
  end
98
122
 
99
123
  def show_help!
@@ -1,3 +1,3 @@
1
1
  module MisterBin
2
- VERSION = '0.7.5'
2
+ VERSION = '0.8.0'
3
3
  end
data/lib/mister_bin.rb CHANGED
@@ -1,6 +1,6 @@
1
- require 'mister_bin/command'
2
- require 'mister_bin/command_meta'
3
- require 'mister_bin/runner'
4
- require 'mister_bin/terminal'
5
-
6
- require 'byebug' if ENV['BYEBUG']
1
+ module MisterBin
2
+ autoload :Command, 'mister_bin/command'
3
+ autoload :CommandMeta, 'mister_bin/command_meta'
4
+ autoload :Runner, 'mister_bin/runner'
5
+ autoload :Terminal, 'mister_bin/terminal'
6
+ 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.7.5
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-10 00:00:00.000000000 Z
11
+ date: 2024-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -37,6 +37,9 @@ dependencies:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0.7'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.7.1
40
43
  type: :runtime
41
44
  prerelease: false
42
45
  version_requirements: !ruby/object:Gem::Requirement
@@ -44,6 +47,9 @@ dependencies:
44
47
  - - "~>"
45
48
  - !ruby/object:Gem::Version
46
49
  version: '0.7'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.7.1
47
53
  description: Easily add command line interface to your gems
48
54
  email: db@dannyben.com
49
55
  executables: []
@@ -61,8 +67,11 @@ homepage: https://github.com/dannyben/mister_bin
61
67
  licenses:
62
68
  - MIT
63
69
  metadata:
70
+ bug_tracker_uri: https://github.com/DannyBen/mister_bin/issues
71
+ changelog_uri: https://github.com/DannyBen/mister_bin/blob/master/CHANGELOG.md
72
+ source_code_uri: https://github.com/DannyBen/mister_bin
64
73
  rubygems_mfa_required: 'true'
65
- post_install_message:
74
+ post_install_message:
66
75
  rdoc_options: []
67
76
  require_paths:
68
77
  - lib
@@ -70,15 +79,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
79
  requirements:
71
80
  - - ">="
72
81
  - !ruby/object:Gem::Version
73
- version: '2.7'
82
+ version: '3.0'
74
83
  required_rubygems_version: !ruby/object:Gem::Requirement
75
84
  requirements:
76
85
  - - ">="
77
86
  - !ruby/object:Gem::Version
78
87
  version: '0'
79
88
  requirements: []
80
- rubygems_version: 3.4.6
81
- signing_key:
89
+ rubygems_version: 3.5.23
90
+ signing_key:
82
91
  specification_version: 4
83
92
  summary: Command line interface for your gems
84
93
  test_files: []