Module: Belafonte::Help::AppExtensions
- Defined in:
- lib/belafonte/help/app_extensions.rb
Instance Method Summary collapse
- #command_arg ⇒ Object
- #display_args ⇒ Object
- #display_description ⇒ Object
- #display_flags(cmd) ⇒ Object
- #display_title ⇒ Object
- #executable ⇒ Object
- #full_path ⇒ Object
- #has_args? ⇒ Boolean
- #has_flags? ⇒ Boolean
- #has_subcommands? ⇒ Boolean
- #help_flag ⇒ Object
- #non_command_arg_names ⇒ Object
- #non_command_args ⇒ Object
- #root ⇒ Object
- #root? ⇒ Boolean
- #show_command_arg? ⇒ Boolean
- #signature ⇒ Object
- #sorted_commands ⇒ Object
- #sorted_flags ⇒ Object
Instance Method Details
#command_arg ⇒ Object
32 33 34 35 |
# File 'lib/belafonte/help/app_extensions.rb', line 32 def command_arg return '' unless show_command_arg? ' command' end |
#display_args ⇒ Object
46 47 48 49 |
# File 'lib/belafonte/help/app_extensions.rb', line 46 def display_args return '' unless has_args? " #{non_command_arg_names.join(' ')}" end |
#display_description ⇒ Object
22 23 24 |
# File 'lib/belafonte/help/app_extensions.rb', line 22 def display_description description.to_s end |
#display_flags(cmd) ⇒ Object
41 42 43 44 |
# File 'lib/belafonte/help/app_extensions.rb', line 41 def display_flags(cmd) return '' unless has_flags? " [#{cmd} options]" end |
#display_title ⇒ Object
18 19 20 |
# File 'lib/belafonte/help/app_extensions.rb', line 18 def display_title root? ? executable : title end |
#executable ⇒ Object
14 15 16 |
# File 'lib/belafonte/help/app_extensions.rb', line 14 def executable File.basename($0) end |
#full_path ⇒ Object
26 27 28 29 30 |
# File 'lib/belafonte/help/app_extensions.rb', line 26 def full_path return signature unless parent parent.extend(AppExtensions) "#{parent.full_path} #{signature}" end |
#has_args? ⇒ Boolean
69 70 71 |
# File 'lib/belafonte/help/app_extensions.rb', line 69 def has_args? non_command_args.any? end |
#has_flags? ⇒ Boolean
61 62 63 |
# File 'lib/belafonte/help/app_extensions.rb', line 61 def has_flags? configured_switches.any? || .any? end |
#has_subcommands? ⇒ Boolean
73 74 75 |
# File 'lib/belafonte/help/app_extensions.rb', line 73 def has_subcommands? configured_subcommands.any? end |
#help_flag ⇒ Object
77 78 79 |
# File 'lib/belafonte/help/app_extensions.rb', line 77 def help_flag @help_flag ||= Belafonte::Switch.new(name: :help, short: 'h', long: 'help', description: 'Shows this message') end |
#non_command_arg_names ⇒ Object
51 52 53 |
# File 'lib/belafonte/help/app_extensions.rb', line 51 def non_command_arg_names non_command_args.map(&:name).map(&:to_s) end |
#non_command_args ⇒ Object
65 66 67 |
# File 'lib/belafonte/help/app_extensions.rb', line 65 def non_command_args configured_args.reject {|arg| arg.name.to_sym == :command} end |
#root ⇒ Object
4 5 6 7 8 |
# File 'lib/belafonte/help/app_extensions.rb', line 4 def root return self unless parent parent.extend(AppExtensions) parent.root end |
#root? ⇒ Boolean
10 11 12 |
# File 'lib/belafonte/help/app_extensions.rb', line 10 def root? root == self end |
#show_command_arg? ⇒ Boolean
37 38 39 |
# File 'lib/belafonte/help/app_extensions.rb', line 37 def show_command_arg? Belafonte::Help::Generator.target == self && has_subcommands? end |
#signature ⇒ Object
55 56 57 58 59 |
# File 'lib/belafonte/help/app_extensions.rb', line 55 def signature display_title.tap {|cmd| return cmd + display_flags(cmd) + display_args + command_arg } end |
#sorted_commands ⇒ Object
86 87 88 89 |
# File 'lib/belafonte/help/app_extensions.rb', line 86 def sorted_commands configured_subcommands. sort {|left,right| left.name <=> right.name} end |
#sorted_flags ⇒ Object
81 82 83 84 |
# File 'lib/belafonte/help/app_extensions.rb', line 81 def sorted_flags (configured_switches + ). sort {|left,right| left.name <=> right.name} end |