Method: Morpheus::Cli::LibraryOptionListsCommand#list

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

#list(args) ⇒ Object



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
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/morpheus/cli/commands/library_option_lists_command.rb', line 26

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 lists."
  end
  optparse.parse!(args)
  # verify_args!(args:args, optparse:optparse, count:0)
  if args.count > 0
    options[:phrase] = args.join(" ")
  end
  connect(options)
  begin
    
    params.merge!(parse_list_options(options))
    @option_type_lists_interface.setopts(options)
    if options[:dry_run]
      print_dry_run @option_type_lists_interface.dry.list(params)
      return
    end

    json_response = @option_type_lists_interface.list(params)
    render_result = render_with_format(json_response, options, 'optionTypeLists')
    return 0 if render_result

    option_type_lists = json_response['optionTypeLists']
    subtitles = []
    subtitles += parse_list_subtitles(options)
    print_h1 "Morpheus Option Lists", subtitles, options
    if option_type_lists.empty?
      print cyan,"No option lists found.",reset,"\n"
    else
      rows = option_type_lists.collect do |option_type_list|
        {
          id: option_type_list['id'],
          name: option_type_list['name'],
          labels: option_type_list['labels'],
          description: option_type_list['description'],
          type: ((option_type_list['type'] == 'api') ? "#{option_type_list['type']} (#{option_type_list['apiType']})" : option_type_list['type'])
        }
      end
        columns = [
        :id,
        :name,
        {:labels => {:display_method => lambda {|it| format_list(it[:labels], '', 3) rescue '' }}},
        :description,
        :type
      ]
      print cyan
      print as_pretty_table(rows, columns, options)
      print reset
      print_results_pagination(json_response)
    end
    print reset,"\n"
    return 0
  rescue RestClient::Exception => e
    print_rest_exception(e, options)
    exit 1
  end
end