mister_bin 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/mister_bin/command.rb +1 -1
- data/lib/mister_bin/docopt_maker.rb +12 -7
- data/lib/mister_bin/script.rb +25 -13
- data/lib/mister_bin/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7d02c3dbeffc01ef74b5352108585791cfc5abcece9071c1b28fe1ea621809f5
|
4
|
+
data.tar.gz: 207c687438a4c780a28b71bae3e6669db003239ed5d1eb565258f03a260638c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8684082e9172f1f80e03992637f3b2248e802e7ba4f52309a615f95b3d4eca9a82005f54a91b8b073256a15358be563c4947dd4329919450591421b33eb79d2b
|
7
|
+
data.tar.gz: 7a28ea5141dd993b8ca3ab4b4d903f3922d555ca264c0fa24a9cbea42f4a9b84a8759c8470fe47d8ffcdd1fa4edd1275599026eedb38483ab3023539c96fd270
|
data/README.md
CHANGED
@@ -205,8 +205,11 @@ The below example outlines all available DSL commands.
|
|
205
205
|
|
206
206
|
|
207
207
|
```ruby
|
208
|
+
# Optional summary string
|
209
|
+
summary "A short sentence or paragraph describing the command"
|
210
|
+
|
208
211
|
# Optional help string
|
209
|
-
help "A
|
212
|
+
help "A longer explanation can go here"
|
210
213
|
|
211
214
|
# Version string for the command
|
212
215
|
version "0.1.1"
|
data/lib/mister_bin/command.rb
CHANGED
@@ -8,24 +8,29 @@ module MisterBin
|
|
8
8
|
include Colsole
|
9
9
|
|
10
10
|
attr_reader :usages, :options, :examples, :params
|
11
|
-
attr_accessor :help, :version
|
11
|
+
attr_accessor :summary, :help, :version
|
12
12
|
|
13
13
|
def initialize
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
14
|
+
@version = '0.0.0'
|
15
|
+
@help = nil
|
16
|
+
@summary = nil
|
17
|
+
@usages = []
|
18
|
+
@options = []
|
19
|
+
@params = []
|
17
20
|
@examples = []
|
18
|
-
@version = '0.0.0'
|
19
|
-
@help = nil
|
20
21
|
end
|
21
22
|
|
22
23
|
def docopt
|
23
|
-
[help_string, usage_string, options_string,
|
24
|
+
[summary_string, help_string, usage_string, options_string,
|
24
25
|
params_string, examples_string].compact.join "\n"
|
25
26
|
end
|
26
27
|
|
27
28
|
private
|
28
29
|
|
30
|
+
def summary_string
|
31
|
+
summary ? word_wrap(summary) + "\n" : nil
|
32
|
+
end
|
33
|
+
|
29
34
|
def help_string
|
30
35
|
help ? word_wrap(help) + "\n" : nil
|
31
36
|
end
|
data/lib/mister_bin/script.rb
CHANGED
@@ -15,35 +15,32 @@ module MisterBin
|
|
15
15
|
|
16
16
|
def execute(argv=[])
|
17
17
|
build_docopt
|
18
|
-
|
19
|
-
exitcode = action_block.call args if action_block
|
20
|
-
exitcode.is_a?(Numeric) ? exitcode : 0
|
18
|
+
execute! argv
|
21
19
|
rescue Docopt::Exit => e
|
22
20
|
puts e.message
|
23
21
|
1
|
24
22
|
end
|
25
23
|
|
26
|
-
def evaluate
|
27
|
-
instance_eval script
|
28
|
-
metadata
|
29
|
-
end
|
30
|
-
|
31
24
|
def docopt
|
32
25
|
maker.docopt
|
33
26
|
end
|
34
27
|
|
35
28
|
def metadata
|
36
|
-
|
29
|
+
@metadata ||= metadata!
|
37
30
|
end
|
38
31
|
|
39
32
|
# DSL
|
40
33
|
|
41
|
-
def
|
42
|
-
|
34
|
+
def summary(text)
|
35
|
+
maker.summary = text
|
36
|
+
end
|
37
|
+
|
38
|
+
def help(text)
|
39
|
+
maker.help = text
|
43
40
|
end
|
44
41
|
|
45
|
-
def version(text
|
46
|
-
|
42
|
+
def version(text)
|
43
|
+
maker.version = text
|
47
44
|
end
|
48
45
|
|
49
46
|
def usage(text)
|
@@ -68,6 +65,21 @@ module MisterBin
|
|
68
65
|
|
69
66
|
private
|
70
67
|
|
68
|
+
def metadata!
|
69
|
+
instance_eval script
|
70
|
+
|
71
|
+
{
|
72
|
+
summary: (maker.summary || maker.help),
|
73
|
+
version: maker.version
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def execute!(argv)
|
78
|
+
args = Docopt.docopt docopt, version: maker.version, argv: argv
|
79
|
+
exitcode = action_block.call args if action_block
|
80
|
+
exitcode.is_a?(Numeric) ? exitcode : 0
|
81
|
+
end
|
82
|
+
|
71
83
|
def build_docopt
|
72
84
|
@maker = nil
|
73
85
|
instance_eval script
|
data/lib/mister_bin/version.rb
CHANGED