Method: CommandParser#help

Defined in:
lib/mkit/client/command_parser.rb

#help(cause: nil, cmd: nil) ⇒ Object



204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/mkit/client/command_parser.rb', line 204

def help(cause: nil, cmd: nil)
  msg = ''
  if cause.nil?
    my_cmd = cmd
  else
    msg += "MKIt: #{cause.message}\n"
    my_cmd = cause.command
  end
  if my_cmd.nil?
    msg += "\nUsage: mkit <command> [options]\n\n"
    msg += "Micro k8s on Ruby - a simple tool to mimic a (very) minimalistic k8 cluster\n\n"
    msg += "Commands:\n\n"
    dict.each do |c|
      msg += format_cmd_help_msg(c)
    end
    msg += "\n"
    msg += "Run ' mkit help <command>' for specific command information.\n\n"
  else
    # todo mkit help profile set
    msg += format("\nUsage: mkit %s %s\n\n", my_cmd[:cmd], my_cmd[:usage].nil? ? '' : my_cmd[:usage].join(' '))
    msg += format("%s\n", my_cmd[:help])
    if !my_cmd[:options].nil? || !my_cmd[:args].nil?
      msg += "\nOptions:\n"
      # command
      unless my_cmd[:options].nil?
        my_cmd[:options].each  do |c|
          msg += format_cmd_help_msg(c)
        end
      end
      # args
      unless my_cmd[:args].nil?
        # values only first
        cmd_args = my_cmd[:args].select{ |arg| (arg[:type].nil? || arg[:type].to_sym == :value) && !arg[:help].nil?}
        cmd_args.each do |arg|
          msg += format_arg_help_msg(arg)
        end
        cmd_args = my_cmd[:args].select{ |arg| !arg[:type].nil? && (arg[:type].to_sym == :option || arg[:type].to_sym == :flag)}
        cmd_args.each  do |arg|
          msg += format_arg_help_msg(arg)
        end
      end
    end
    msg += "\n"
  end
  puts msg
  exit 1
end