mister_bin 0.7.6 → 0.8.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 +17 -5
- data/lib/mister_bin/runner.rb +23 -3
- data/lib/mister_bin/version.rb +1 -1
- data/lib/mister_bin.rb +6 -6
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b8b37499324199dee43edefc92606a2a697ce9dd132c6ef11803a6037e259c23
|
4
|
+
data.tar.gz: 5bd2375c5eea1a0a936cdbde439d8864975bc068ab61ac24a79f6c52ef2987a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e31a33f9192da8ad523bc29a299bc373d39dcedbc8dc96d39e4a90e748a5e4321189eaea462a1823ee88226f2d22bcebf8fab05cfca5850219ef9d2fb094560b
|
7
|
+
data.tar.gz: 97c81e608bc71af98922ce740792dc0ee0d235a1dca08c18f6383fe9aa87a23d0d09cb620c564ad3066cd848d0918a0c499e1e43075205058b18051cf8bf9f4f
|
data/README.md
CHANGED
@@ -13,7 +13,9 @@ interfaces for your gem or other Ruby application.
|
|
13
13
|
|
14
14
|
## Installation
|
15
15
|
|
16
|
-
|
16
|
+
```
|
17
|
+
$ gem install mister_bin
|
18
|
+
```
|
17
19
|
|
18
20
|
## Feature Highlights
|
19
21
|
|
@@ -21,7 +23,8 @@ interfaces for your gem or other Ruby application.
|
|
21
23
|
- Each command is defined with a separate class for maximum testability and
|
22
24
|
scalability.
|
23
25
|
- Commands can have subcommands.
|
24
|
-
-
|
26
|
+
- Commands can have aliases.
|
27
|
+
- Designed primarily for gem developers.
|
25
28
|
|
26
29
|
## Examples
|
27
30
|
|
@@ -122,6 +125,15 @@ runner.route 'greet', to: GreetCommand
|
|
122
125
|
runner.route 'config', to: ConfigCommand
|
123
126
|
```
|
124
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
|
+
|
125
137
|
If you wish to route all commands to the same class, you can use:
|
126
138
|
|
127
139
|
```ruby
|
@@ -149,7 +161,7 @@ class GreetCommand < MisterBin::Command
|
|
149
161
|
param "NAME", "The recipient of the greeting"
|
150
162
|
|
151
163
|
def run
|
152
|
-
# args hash is available everywhere in the
|
164
|
+
# args hash is available everywhere in the class
|
153
165
|
name = args['NAME'] || 'Luke'
|
154
166
|
puts "#{name}... I am your father..."
|
155
167
|
end
|
@@ -241,7 +253,7 @@ terminal.start
|
|
241
253
|
The `MisterBin::Terminal.new` command accepts an optional second argument. If
|
242
254
|
provided, it should be a options hash:
|
243
255
|
|
244
|
-
```
|
256
|
+
```ruby
|
245
257
|
terminal = MisterBin::Terminal.new runner, {
|
246
258
|
header: "Welcome",
|
247
259
|
autocomplete: %w[--help greet]
|
@@ -253,7 +265,7 @@ commands that are not handled by your runner. For example, this piece of code
|
|
253
265
|
will capture the `/cd ...` command from the terminal and pass it to your
|
254
266
|
block:
|
255
267
|
|
256
|
-
```
|
268
|
+
```ruby
|
257
269
|
terminal = MisterBin::Terminal.new runner
|
258
270
|
terminal.on '/cd' do |args|
|
259
271
|
Dir.chdir args[0] if args[0]
|
data/lib/mister_bin/runner.rb
CHANGED
@@ -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
|
-
|
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:)
|
@@ -36,6 +43,10 @@ module MisterBin
|
|
36
43
|
end
|
37
44
|
end
|
38
45
|
|
46
|
+
def aliases
|
47
|
+
@aliases ||= {}
|
48
|
+
end
|
49
|
+
|
39
50
|
private
|
40
51
|
|
41
52
|
def execute(argv)
|
@@ -54,11 +65,20 @@ module MisterBin
|
|
54
65
|
command = argv[0]
|
55
66
|
return argv if commands.has_key? command
|
56
67
|
|
57
|
-
|
58
|
-
argv[0] = candidates.first if candidates.count == 1
|
68
|
+
argv[0] = find_target_command argv[0]
|
59
69
|
argv
|
60
70
|
end
|
61
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
|
+
|
62
82
|
def show_version
|
63
83
|
puts version
|
64
84
|
0
|
data/lib/mister_bin/version.rb
CHANGED
data/lib/mister_bin.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
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.
|
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:
|
11
|
+
date: 2024-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -67,8 +67,11 @@ homepage: https://github.com/dannyben/mister_bin
|
|
67
67
|
licenses:
|
68
68
|
- MIT
|
69
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
|
70
73
|
rubygems_mfa_required: 'true'
|
71
|
-
post_install_message:
|
74
|
+
post_install_message:
|
72
75
|
rdoc_options: []
|
73
76
|
require_paths:
|
74
77
|
- lib
|
@@ -76,15 +79,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
76
79
|
requirements:
|
77
80
|
- - ">="
|
78
81
|
- !ruby/object:Gem::Version
|
79
|
-
version: '
|
82
|
+
version: '3.0'
|
80
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
84
|
requirements:
|
82
85
|
- - ">="
|
83
86
|
- !ruby/object:Gem::Version
|
84
87
|
version: '0'
|
85
88
|
requirements: []
|
86
|
-
rubygems_version: 3.
|
87
|
-
signing_key:
|
89
|
+
rubygems_version: 3.5.23
|
90
|
+
signing_key:
|
88
91
|
specification_version: 4
|
89
92
|
summary: Command line interface for your gems
|
90
93
|
test_files: []
|