mister_bin 0.7.6 → 0.8.1
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 +22 -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: 3487443d2b2758402bb54ce0a57afbde6e9d1bf6531dfa9b45183caf78b41c39
|
4
|
+
data.tar.gz: 13593c3486780bfff261d324382956d99afc130f96586a046c47d3271dca76e3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f6e796132ba220de7175363927d1e887e80d902022570905530f940d5db425fb43c33c12b842b77cec29027493ff9af465cfeaaaaf424e292d748ac4f3fd828
|
7
|
+
data.tar.gz: 7f9964a5522fb33dffdf8aa96e2f8381b93393f752d21e4005dd9ea3ff45469e0cc9d2f663ce539cbf8cdc94434f95de7198df97f4f8b09481b13f74dcd932ad
|
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
@@ -15,7 +15,13 @@ module MisterBin
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def route(key, to:)
|
18
|
-
|
18
|
+
if key.is_a? Array
|
19
|
+
target = key.shift
|
20
|
+
commands[target] = to
|
21
|
+
key.each { |alias_name| aliases[alias_name] = target }
|
22
|
+
else
|
23
|
+
commands[key] = to
|
24
|
+
end
|
19
25
|
end
|
20
26
|
|
21
27
|
def route_all(to:)
|
@@ -36,6 +42,10 @@ module MisterBin
|
|
36
42
|
end
|
37
43
|
end
|
38
44
|
|
45
|
+
def aliases
|
46
|
+
@aliases ||= {}
|
47
|
+
end
|
48
|
+
|
39
49
|
private
|
40
50
|
|
41
51
|
def execute(argv)
|
@@ -54,11 +64,20 @@ module MisterBin
|
|
54
64
|
command = argv[0]
|
55
65
|
return argv if commands.has_key? command
|
56
66
|
|
57
|
-
|
58
|
-
argv[0] = candidates.first if candidates.count == 1
|
67
|
+
argv[0] = find_target_command argv[0]
|
59
68
|
argv
|
60
69
|
end
|
61
70
|
|
71
|
+
def find_target_command(input)
|
72
|
+
candidates = commands.keys.grep(/^#{input}/)
|
73
|
+
return candidates.first if candidates.count == 1
|
74
|
+
|
75
|
+
candidates = aliases.keys.grep(/^#{input}/)
|
76
|
+
return aliases[candidates.first] if candidates.count == 1
|
77
|
+
|
78
|
+
input
|
79
|
+
end
|
80
|
+
|
62
81
|
def show_version
|
63
82
|
puts version
|
64
83
|
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.1
|
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: []
|