mister_bin 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a2ff2144e3c182ac75eee0201e1fb2c709d070174b3f1d6d3474b4fc2996f2d
4
- data.tar.gz: 342666c56d570caa2c791ebf9e3fb259b35c6a94f5c348c6cec168ef381d8c86
3
+ metadata.gz: dda05692e69025b3954d900c2a4165182edfdbce33d57966c69ad5ad41a207b7
4
+ data.tar.gz: 75b901c5d0d99755caf324270e77a5dee2b20aa1e0dc6740434622ad514c9d52
5
5
  SHA512:
6
- metadata.gz: 276954e4955705da9a9eed20b1fe803cf702603b35141ebc096cee16537b3adf39b6aec29abeaa36ac0b10e084b7cf998ccd067bc9aca90cb50bef21edf91484
7
- data.tar.gz: b9ee0f5d12e13da32eef957066071b6bafaba92a9edc59ddd7d6f73a83c1b9e9be9406ae7d9664958ee6037d77710480a46daf923c4be6fb76563bce64363551
6
+ metadata.gz: 1ae92daf8a5617295a8a68f423e7f2c4b84aa1a6014e524b6a9b0fc922a7f13621d6f42e408e0dc5e34871690a51a80514b2ff400efa2517aebda748d6ee402a
7
+ data.tar.gz: feb0cd9a946998acd8bc5255330e037712a1c58ca500648127860a28bff6a0682d3326fa3bf9f603b03b9d541c0fa76434c5284c5b14fad82502752bc59a8af9
@@ -7,17 +7,13 @@ module MisterBin
7
7
 
8
8
  attr_reader :args
9
9
 
10
- def initialize(args)
10
+ def initialize(args = nil)
11
11
  @args = args
12
12
  end
13
13
 
14
14
  class << self
15
- def description
16
- maker.summary || maker.help || ''
17
- end
18
-
19
15
  def execute(argv=[])
20
- args = Docopt.docopt docopt, version: maker.version, argv: argv
16
+ args = Docopt.docopt docopt, version: meta.version, argv: argv
21
17
  instance = new args
22
18
  target = find_target_command instance, args
23
19
  exitcode = instance.send target
@@ -31,50 +27,50 @@ module MisterBin
31
27
  # DSL
32
28
 
33
29
  def summary(text)
34
- maker.summary = text
30
+ meta.summary = text
35
31
  end
36
32
 
37
33
  def help(text)
38
- maker.help = text
34
+ meta.help = text
39
35
  end
40
36
 
41
37
  def version(text)
42
- maker.version = text
38
+ meta.version = text
43
39
  end
44
40
 
45
41
  def usage(text)
46
- maker.usages << text
42
+ meta.usages << text
47
43
  end
48
44
 
49
45
  def option(flags, text)
50
- maker.options << [flags, text]
46
+ meta.options << [flags, text]
51
47
  end
52
48
 
53
49
  def command(name, text)
54
50
  target_commands << name.to_sym
55
- maker.commands << [name, text]
51
+ meta.commands << [name, text]
56
52
  end
57
53
 
58
54
  def param(param, text)
59
- maker.params << [param, text]
55
+ meta.params << [param, text]
60
56
  end
61
57
 
62
58
  def example(text)
63
- maker.examples << text
59
+ meta.examples << text
64
60
  end
65
61
 
66
62
  def environment(name, value)
67
- maker.env_vars << [name, value]
63
+ meta.env_vars << [name, value]
68
64
  end
69
65
 
70
- protected
71
-
72
- def maker
73
- @maker ||= DocoptMaker.new
66
+ def meta
67
+ @meta ||= CommandMeta.new
74
68
  end
75
69
 
70
+ protected
71
+
76
72
  def docopt
77
- maker.docopt
73
+ meta.docopt
78
74
  end
79
75
 
80
76
  private
@@ -92,6 +88,5 @@ module MisterBin
92
88
  end
93
89
 
94
90
  end
95
-
96
91
  end
97
92
  end
@@ -2,9 +2,9 @@ require 'colsole'
2
2
 
3
3
  module MisterBin
4
4
 
5
- # This singleton class is responsible for generating a text string ready to be used
6
- # by Docopt.
7
- class DocoptMaker
5
+ # This class is responsible for holding all the meta data for a command and
6
+ # for generating a text string ready to be used by Docopt.
7
+ class CommandMeta
8
8
  include Colsole
9
9
 
10
10
  attr_reader :usages, :options, :examples, :params, :commands, :env_vars
@@ -27,7 +27,15 @@ module MisterBin
27
27
  options_string, params_string, env_string, examples_string].compact.join "\n"
28
28
  end
29
29
 
30
- private
30
+ def description
31
+ summary || help || ''
32
+ end
33
+
34
+ def long_description
35
+ summary && help ? "#{summary}\n\n#{help}" : description
36
+ end
37
+
38
+ private
31
39
 
32
40
  def summary_string
33
41
  summary ? word_wrap(summary) + "\n" : nil
@@ -97,5 +105,6 @@ module MisterBin
97
105
 
98
106
  result.join "\n"
99
107
  end
108
+
100
109
  end
101
- end
110
+ end
@@ -27,7 +27,9 @@ module MisterBin
27
27
  handler.execute argv
28
28
  elsif argv.empty?
29
29
  show_subs
30
- elsif argv == ['--version'] and version
30
+ elsif argv == ['--help'] or argv == ['-h']
31
+ show_help
32
+ elsif version and (argv == ['--version'] or argv == ['-v'])
31
33
  puts version
32
34
  return 1
33
35
  else
@@ -75,7 +77,7 @@ module MisterBin
75
77
 
76
78
  say "Commands:"
77
79
  commands.each do |key, command|
78
- summary = command.description
80
+ summary = command.meta.description
79
81
  summary = summary[0..max_summary_size].strip
80
82
  say " !bldgrn!#{key.ljust longest_key} !txtrst!#{summary}"
81
83
  end
@@ -83,5 +85,28 @@ module MisterBin
83
85
  say "\n#{footer}" if footer
84
86
  end
85
87
 
88
+ def show_help
89
+ if commands.empty?
90
+ say "No subcommands found"
91
+ else
92
+ show_help!
93
+ end
94
+
95
+ return 1
96
+ end
97
+
98
+ def show_help!
99
+ say "#{header}\n" if header
100
+
101
+ commands.each do |key, command|
102
+ say "!bldgrn!#{key}"
103
+ say word_wrap " #{command.meta.long_description}"
104
+ say ""
105
+ end
106
+
107
+ say "#{footer}" if footer
108
+ end
109
+
110
+
86
111
  end
87
112
  end
@@ -1,3 +1,3 @@
1
1
  module MisterBin
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.1"
3
3
  end
data/lib/mister_bin.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'mister_bin/command'
2
- require 'mister_bin/docopt_maker'
2
+ require 'mister_bin/command_meta'
3
3
  require 'mister_bin/runner'
4
4
 
5
5
  require 'byebug' if ENV['BYEBUG']
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.6.0
4
+ version: 0.6.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-12-13 00:00:00.000000000 Z
11
+ date: 2018-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -47,7 +47,7 @@ files:
47
47
  - README.md
48
48
  - lib/mister_bin.rb
49
49
  - lib/mister_bin/command.rb
50
- - lib/mister_bin/docopt_maker.rb
50
+ - lib/mister_bin/command_meta.rb
51
51
  - lib/mister_bin/runner.rb
52
52
  - lib/mister_bin/version.rb
53
53
  homepage: https://github.com/dannyben/mister_bin