mister_bin 0.2.0 → 0.2.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 +0 -1
- data/lib/mister_bin/command.rb +9 -5
- data/lib/mister_bin/commands.rb +7 -6
- data/lib/mister_bin/docopt_maker.rb +0 -6
- data/lib/mister_bin/runner.rb +19 -6
- data/lib/mister_bin/script.rb +32 -18
- data/lib/mister_bin/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9ead1a61f1fa10257fdada263fe53831d50eb347cb72511b9a84380f22c1fa0
|
4
|
+
data.tar.gz: 98d279539bbcefe16e28a29d8106fbac79613ce6eb9a8adf80359a7204c5933c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c43175939978e46c952ca8d89b02111e8a5f6c001d1c973e6c18bed8da09cc81d2aa3fbb186896bf94bc0d7459d050ecac7972aefa899803f18282b9740110e0
|
7
|
+
data.tar.gz: 977f09d4e624c8870c0011a22d4cf6143751246b21b0dcdc19e81a225c6400abdb0e8e6fff4bb82d1c9a1c5c91cc05341c8a242d7e564017f5dbaf6661f08fa0
|
data/README.md
CHANGED
data/lib/mister_bin/command.rb
CHANGED
@@ -9,13 +9,17 @@ module MisterBin
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def run(argv=[])
|
12
|
-
script = Script.new file
|
13
|
-
script.build_docopt
|
14
12
|
script.execute argv
|
15
13
|
end
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
def metadata
|
16
|
+
script.evaluate
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def script
|
22
|
+
@script ||= Script.new file
|
23
|
+
end
|
20
24
|
end
|
21
25
|
end
|
data/lib/mister_bin/commands.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
1
3
|
module MisterBin
|
2
4
|
|
3
5
|
# This class handles listing and finding command files
|
4
6
|
class Commands
|
7
|
+
extend Forwardable
|
8
|
+
|
5
9
|
attr_reader :basename, :basedir, :isolate
|
10
|
+
def_delegators :all, :[], :<<, :each, :size, :keys, :values, :empty?
|
6
11
|
|
7
12
|
def initialize(basename, basedir='.', isolate: false)
|
8
13
|
@basename = basename
|
@@ -14,12 +19,8 @@ module MisterBin
|
|
14
19
|
@all ||= all!
|
15
20
|
end
|
16
21
|
|
17
|
-
def names
|
18
|
-
all.keys.sort
|
19
|
-
end
|
20
|
-
|
21
22
|
def find(command, subcommand=nil)
|
22
|
-
if subcommand and
|
23
|
+
if subcommand and keys.include? "#{command} #{subcommand}"
|
23
24
|
all["#{command} #{subcommand}"]
|
24
25
|
else
|
25
26
|
all["#{command}"]
|
@@ -38,7 +39,7 @@ module MisterBin
|
|
38
39
|
end
|
39
40
|
result[command] = Command.new command, file
|
40
41
|
end
|
41
|
-
result
|
42
|
+
result.sort.to_h
|
42
43
|
end
|
43
44
|
|
44
45
|
def files
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'singleton'
|
2
1
|
require 'colsole'
|
3
2
|
|
4
3
|
module MisterBin
|
@@ -6,17 +5,12 @@ module MisterBin
|
|
6
5
|
# This singleton class is responsible for generating a text string ready to be used
|
7
6
|
# by Docopt.
|
8
7
|
class DocoptMaker
|
9
|
-
include Singleton
|
10
8
|
include Colsole
|
11
9
|
|
12
10
|
attr_reader :usages, :options, :examples, :params
|
13
11
|
attr_accessor :help, :version
|
14
12
|
|
15
13
|
def initialize
|
16
|
-
reset
|
17
|
-
end
|
18
|
-
|
19
|
-
def reset
|
20
14
|
@usages = []
|
21
15
|
@options = []
|
22
16
|
@params = []
|
data/lib/mister_bin/runner.rb
CHANGED
@@ -40,18 +40,31 @@ module MisterBin
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def show_subs
|
43
|
-
if commands.
|
44
|
-
|
43
|
+
if commands.empty?
|
44
|
+
say "No subcommands found"
|
45
45
|
else
|
46
|
-
|
47
|
-
puts "Commands:"
|
48
|
-
commands.names.each { |command| puts " #{name} #{command}" }
|
49
|
-
say "\n#{footer}" if footer
|
46
|
+
show_subs!
|
50
47
|
end
|
51
48
|
|
52
49
|
return 1
|
53
50
|
end
|
54
51
|
|
52
|
+
def show_subs!
|
53
|
+
longest_key = commands.keys.max_by(&:size).size
|
54
|
+
max_summary_size = terminal_width - longest_key - 6
|
55
|
+
|
56
|
+
say "#{header}\n" if header
|
57
|
+
|
58
|
+
say "Commands:"
|
59
|
+
commands.each do |key, command|
|
60
|
+
summary = command.metadata[:summary] || ''
|
61
|
+
summary = summary[0..max_summary_size].strip
|
62
|
+
say " !bldgrn!#{key.ljust longest_key} !txtrst!#{summary}"
|
63
|
+
end
|
64
|
+
|
65
|
+
say "\n#{footer}" if footer
|
66
|
+
end
|
67
|
+
|
55
68
|
def commands
|
56
69
|
@commands ||= Commands.new name, basedir, isolate: isolate
|
57
70
|
end
|
data/lib/mister_bin/script.rb
CHANGED
@@ -13,14 +13,9 @@ module MisterBin
|
|
13
13
|
@file = file
|
14
14
|
end
|
15
15
|
|
16
|
-
def build_docopt
|
17
|
-
DocoptMaker.instance.reset
|
18
|
-
instance_eval script
|
19
|
-
docopt
|
20
|
-
end
|
21
|
-
|
22
16
|
def execute(argv=[])
|
23
|
-
|
17
|
+
build_docopt
|
18
|
+
args = Docopt.docopt docopt, version: maker.version, argv: argv
|
24
19
|
exitcode = action_block.call args if action_block
|
25
20
|
exitcode.is_a?(Numeric) ? exitcode : 0
|
26
21
|
rescue Docopt::Exit => e
|
@@ -28,34 +23,43 @@ module MisterBin
|
|
28
23
|
1
|
29
24
|
end
|
30
25
|
|
26
|
+
def evaluate
|
27
|
+
instance_eval script
|
28
|
+
metadata
|
29
|
+
end
|
30
|
+
|
31
31
|
def docopt
|
32
|
-
|
32
|
+
maker.docopt
|
33
|
+
end
|
34
|
+
|
35
|
+
def metadata
|
36
|
+
{ summary: help, version: version }
|
33
37
|
end
|
34
38
|
|
35
39
|
# DSL
|
36
40
|
|
37
|
-
def help(text)
|
38
|
-
|
41
|
+
def help(text=nil)
|
42
|
+
text ? maker.help = text : maker.help
|
43
|
+
end
|
44
|
+
|
45
|
+
def version(text=nil)
|
46
|
+
text ? maker.version = text : maker.version
|
39
47
|
end
|
40
48
|
|
41
49
|
def usage(text)
|
42
|
-
|
50
|
+
maker.usages << text
|
43
51
|
end
|
44
52
|
|
45
53
|
def option(flags, text)
|
46
|
-
|
54
|
+
maker.options << [flags, text]
|
47
55
|
end
|
48
56
|
|
49
57
|
def param(param, text)
|
50
|
-
|
58
|
+
maker.params << [param, text]
|
51
59
|
end
|
52
60
|
|
53
61
|
def example(text)
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
def version(text)
|
58
|
-
DocoptMaker.instance.version = text
|
62
|
+
maker.examples << text
|
59
63
|
end
|
60
64
|
|
61
65
|
def action(&block)
|
@@ -64,6 +68,16 @@ module MisterBin
|
|
64
68
|
|
65
69
|
private
|
66
70
|
|
71
|
+
def build_docopt
|
72
|
+
@maker = nil
|
73
|
+
instance_eval script
|
74
|
+
docopt
|
75
|
+
end
|
76
|
+
|
77
|
+
def maker
|
78
|
+
@maker ||= DocoptMaker.new
|
79
|
+
end
|
80
|
+
|
67
81
|
def script
|
68
82
|
@script ||= File.read file
|
69
83
|
end
|
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.2.
|
4
|
+
version: 0.2.1
|
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-
|
11
|
+
date: 2018-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|