mister_bin 0.5.0 → 0.6.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 +12 -7
- data/lib/mister_bin/command.rb +8 -2
- data/lib/mister_bin/runner.rb +8 -6
- data/lib/mister_bin/version.rb +1 -1
- metadata +2 -114
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a2ff2144e3c182ac75eee0201e1fb2c709d070174b3f1d6d3474b4fc2996f2d
|
4
|
+
data.tar.gz: 342666c56d570caa2c791ebf9e3fb259b35c6a94f5c348c6cec168ef381d8c86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 276954e4955705da9a9eed20b1fe803cf702603b35141ebc096cee16537b3adf39b6aec29abeaa36ac0b10e084b7cf998ccd067bc9aca90cb50bef21edf91484
|
7
|
+
data.tar.gz: b9ee0f5d12e13da32eef957066071b6bafaba92a9edc59ddd7d6f73a83c1b9e9be9406ae7d9664958ee6037d77710480a46daf923c4be6fb76563bce64363551
|
data/README.md
CHANGED
@@ -63,6 +63,11 @@ Creating a command line utility with Mister Bin involves at least two files:
|
|
63
63
|
2. One or more subcommand files. These files use the DSL, and will usually be
|
64
64
|
placed in your `lib/<your gem>/commands` folder.
|
65
65
|
|
66
|
+
WHen executing the commands, you can use only the first letters of the
|
67
|
+
command name. Mister Bin will search for the command that starts with your
|
68
|
+
input, and if it finds one and one only, it will execute it. For example,
|
69
|
+
if you have a `server` command, you can execute it with `yourapp s` if it
|
70
|
+
is the only command that starts with an `s`.
|
66
71
|
|
67
72
|
|
68
73
|
Creating the Main Executable
|
@@ -107,9 +112,9 @@ Text to display after the list of commands.
|
|
107
112
|
|
108
113
|
#### `commands`
|
109
114
|
|
110
|
-
A hash of `{ '
|
115
|
+
A hash of `{ 'command_name' => ClassName }` to serve as command routes.
|
111
116
|
This is equivalent to adding routes later with
|
112
|
-
`runner.route '
|
117
|
+
`runner.route 'command_name', to: ClassName`.
|
113
118
|
|
114
119
|
|
115
120
|
#### `handler`
|
@@ -128,7 +133,7 @@ Use the `#route` method as follows:
|
|
128
133
|
|
129
134
|
```ruby
|
130
135
|
runner = MisterBin::Runner.new
|
131
|
-
runner.route <
|
136
|
+
runner.route <command_name>, to: <Class Name>
|
132
137
|
```
|
133
138
|
|
134
139
|
for example:
|
@@ -137,8 +142,7 @@ for example:
|
|
137
142
|
runner = MisterBin::Runner.new
|
138
143
|
runner.route 'dir', to: DirCommand
|
139
144
|
runner.route 'greet', to: GreetCommand
|
140
|
-
runner.route 'config
|
141
|
-
runner.route 'config show', to: ConfigDisplayerCommand
|
145
|
+
runner.route 'config', to: ConfigCommand
|
142
146
|
```
|
143
147
|
|
144
148
|
If you wish to route all commands to the same class, you can use:
|
@@ -159,7 +163,7 @@ runner.route_all to: GlobalCommand
|
|
159
163
|
Creating Commands
|
160
164
|
--------------------------------------------------
|
161
165
|
|
162
|
-
Create command classes by
|
166
|
+
Create command classes by inheriting from `MisterBin::Command`, for example:
|
163
167
|
|
164
168
|
```ruby
|
165
169
|
require 'mister_bin'
|
@@ -169,7 +173,8 @@ class GreetCommand < MisterBin::Command
|
|
169
173
|
usage "app greet [NAME]"
|
170
174
|
param "NAME", "The recipient of the greeting"
|
171
175
|
|
172
|
-
def run
|
176
|
+
def run
|
177
|
+
# args hash is available everywhere in the calss
|
173
178
|
name = args['NAME'] || 'Luke'
|
174
179
|
puts "#{name}... I am your father..."
|
175
180
|
end
|
data/lib/mister_bin/command.rb
CHANGED
@@ -5,6 +5,12 @@ module MisterBin
|
|
5
5
|
class Command
|
6
6
|
include Colsole
|
7
7
|
|
8
|
+
attr_reader :args
|
9
|
+
|
10
|
+
def initialize(args)
|
11
|
+
@args = args
|
12
|
+
end
|
13
|
+
|
8
14
|
class << self
|
9
15
|
def description
|
10
16
|
maker.summary || maker.help || ''
|
@@ -12,9 +18,9 @@ module MisterBin
|
|
12
18
|
|
13
19
|
def execute(argv=[])
|
14
20
|
args = Docopt.docopt docopt, version: maker.version, argv: argv
|
15
|
-
instance = new
|
21
|
+
instance = new args
|
16
22
|
target = find_target_command instance, args
|
17
|
-
exitcode = instance.send target
|
23
|
+
exitcode = instance.send target
|
18
24
|
exitcode.is_a?(Numeric) ? exitcode : 0
|
19
25
|
|
20
26
|
rescue Docopt::Exit => e
|
data/lib/mister_bin/runner.rb
CHANGED
@@ -38,7 +38,8 @@ module MisterBin
|
|
38
38
|
private
|
39
39
|
|
40
40
|
def execute(argv)
|
41
|
-
|
41
|
+
argv = normalize_argv_command argv
|
42
|
+
command = commands[argv[0]]
|
42
43
|
|
43
44
|
if command
|
44
45
|
command.execute argv
|
@@ -48,11 +49,12 @@ module MisterBin
|
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
51
|
-
def
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
def normalize_argv_command(argv)
|
53
|
+
command = argv[0]
|
54
|
+
return argv if commands.has_key? command
|
55
|
+
candidates = commands.keys.select { |key| key =~ /^#{command}/ }
|
56
|
+
argv[0] = candidates.first if candidates.count == 1
|
57
|
+
argv
|
56
58
|
end
|
57
59
|
|
58
60
|
def show_subs
|
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.6.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-12-
|
11
|
+
date: 2018-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -38,118 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.6'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: byebug
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '10.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '10.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rdoc
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '6.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '6.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: rspec
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '3.6'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '3.6'
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: rspec_fixtures
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: '0.3'
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: '0.3'
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: runfile
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - "~>"
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: '0.10'
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - "~>"
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: '0.10'
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: runfile-tasks
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: '0.4'
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: '0.4'
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: simplecov
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: '0.16'
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: '0.16'
|
139
|
-
- !ruby/object:Gem::Dependency
|
140
|
-
name: yard
|
141
|
-
requirement: !ruby/object:Gem::Requirement
|
142
|
-
requirements:
|
143
|
-
- - "~>"
|
144
|
-
- !ruby/object:Gem::Version
|
145
|
-
version: '0.9'
|
146
|
-
type: :development
|
147
|
-
prerelease: false
|
148
|
-
version_requirements: !ruby/object:Gem::Requirement
|
149
|
-
requirements:
|
150
|
-
- - "~>"
|
151
|
-
- !ruby/object:Gem::Version
|
152
|
-
version: '0.9'
|
153
41
|
description: Easily add command line interface to your gems
|
154
42
|
email: db@dannyben.com
|
155
43
|
executables: []
|