belafonte 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c8b79a1d44e0ead9355e7daf0091c3b93aac55fe
4
- data.tar.gz: 7aa26f871377c9b8a0a110859500cb65f90f3c30
3
+ metadata.gz: 2f5509c92ec5d0ddd52432d56f34702b797d9240
4
+ data.tar.gz: 2b6399b51a131dda9ad8b6458da6581c4e556c01
5
5
  SHA512:
6
- metadata.gz: 7c5245a9afd12af2cb31ff4d5633afb8233db43ae1f02f9b0612f479b7869de05b144ba2321ce60faa35f12224a0bc88d3db15c52fdc77bb836fb99b918f85ee
7
- data.tar.gz: 992f421cf4b967f43f0a7b6668f90cd333f55f0f948eb1acbbc9f2c200376c1cfe76936d588d6d0cba90455d6d9debefcb2e103f006f90b585a9bef9152c72ef
6
+ metadata.gz: 598b0bd646258d587cc43a5a8d70bcb67d55795b23243080138bf3ebe1a4a7fcfbcd190659421185e43497609eb6678c99a1136a64e413ab6c8a6808c8d20c3c
7
+ data.tar.gz: 1c7c03b1c6da23bd3bb44a3dbd2686660445e60daae8d56078cf6f2bf22fe7b4c3e005f550e7c17a2d56937c859d8afc169d98f17fff0f119f248aa0f8ebdd71
@@ -32,34 +32,56 @@ module Belafonte
32
32
  "#{parent.full_path} #{signature}"
33
33
  end
34
34
 
35
- def signature
36
- cmd = display_title
37
-
38
- cmd += " [#{cmd} options]" if has_flags?
35
+ def command_arg
36
+ if Belafonte::Help::Generator.target == self && has_subcommands?
37
+ ' command'
38
+ else
39
+ ''
40
+ end
41
+ end
39
42
 
40
- if has_args?
41
- cmd += " #{configured_args.map(&:name).map(&:to_s).join(' ')}"
43
+ def display_flags(cmd)
44
+ if has_flags?
45
+ " [#{cmd} options]"
46
+ else
47
+ ''
42
48
  end
49
+ end
43
50
 
44
- if has_subcommands? && @command.nil?
45
- cmd += " command"
51
+ def display_args
52
+ if has_args?
53
+ " #{non_command_args.map(&:name).map(&:to_s).join(' ')}"
54
+ else
55
+ ''
46
56
  end
57
+ end
47
58
 
48
- cmd
59
+ def signature
60
+ display_title.tap {|cmd|
61
+ return cmd + display_flags(cmd) + display_args + command_arg
62
+ }
49
63
  end
50
64
 
51
65
  def has_flags?
52
66
  configured_switches.any? || configured_options.any?
53
67
  end
54
68
 
69
+ def non_command_args
70
+ configured_args.reject {|arg| arg.name.to_sym == :command}
71
+ end
72
+
55
73
  def has_args?
56
- configured_args.reject {|arg| arg.name.to_sym == :command}.any?
74
+ non_command_args.any?
57
75
  end
58
76
 
59
77
  def has_subcommands?
60
78
  configured_subcommands.any?
61
79
  end
62
80
 
81
+ def help_flag
82
+ @help_flag ||= Belafonte::Switch.new(name: :help, short: 'h', long: 'help', description: 'Shows this message')
83
+ end
84
+
63
85
  def sorted_flags
64
86
  (configured_switches + configured_options).sort {|a,b| a.name <=> b.name}
65
87
  end
@@ -6,8 +6,16 @@ require 'belafonte/help/command_extensions'
6
6
  module Belafonte
7
7
  module Help
8
8
  class Generator
9
+ def self.set_target(app)
10
+ @target = app
11
+ end
12
+
13
+ def self.target
14
+ @target
15
+ end
16
+
9
17
  def initialize(app)
10
- @app = app
18
+ self.class.set_target(@app = app)
11
19
  app.extend(AppExtensions)
12
20
  @content = name_section + synopsis + options + commands
13
21
  end
@@ -1,3 +1,3 @@
1
1
  module Belafonte
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: belafonte
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dennis Walters
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-24 00:00:00.000000000 Z
11
+ date: 2015-10-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler