Method: Morpheus::Cli::LibraryFormsCommand#list

Defined in:
lib/morpheus/cli/commands/library_forms_command.rb

#list(args) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/morpheus/cli/commands/library_forms_command.rb', line 23

def list(args)
  options = {}
  params = {}
  optparse = Morpheus::Cli::OptionParser.new do|opts|
    opts.banner = subcommand_usage()
    opts.on('-l', '--labels LABEL', String, "Filter by labels, can match any of the values") do |val|
      add_query_parameter(params, 'labels', parse_labels(val))
    end
    opts.on('--all-labels LABEL', String, "Filter by labels, must match all of the values") do |val|
      add_query_parameter(params, 'allLabels', parse_labels(val))
    end
    build_standard_list_options(opts, options)
    opts.footer = "List option forms."
  end
  optparse.parse!(args)
  # verify_args!(args:args, optparse:optparse, count:0)
  if args.count > 0
    options[:phrase] = args.join(" ")
  end
  connect(options)
  params.merge!(parse_list_options(options))
  @option_type_forms_interface.setopts(options)
  if options[:dry_run]
    print_dry_run @option_type_forms_interface.dry.list(params)
    return
  end
  json_response = @option_type_forms_interface.list(params)
  render_response(json_response, options, rest_list_key) do
    option_type_forms = json_response[rest_list_key]
    subtitles = []
    subtitles += parse_list_subtitles(options)
    print_h1 "Morpheus Forms", subtitles, options
    if option_type_forms.empty?
      print cyan,"No forms found.",reset,"\n"
    else
      rows = option_type_forms.collect do |option_type_form|
        {
          id: option_type_form['id'],
          name: option_type_form['name'],
          code: option_type_form['code'],
          labels: option_type_form['labels'],
          description: option_type_form['description'],
        }
      end
        columns = [
        :id,
        :name,
        :code,
        {:labels => {:display_method => lambda {|it| format_list(it[:labels], '', 3) rescue '' }}},
        :description,
      ]
      print cyan
      print as_pretty_table(rows, columns, options)
      print reset
      print_results_pagination(json_response)
    end
    print reset,"\n"
  end
end