File: lister.rb

package info (click to toggle)
elasticsearch 1.0.3%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 37,220 kB
  • sloc: java: 365,486; xml: 1,258; sh: 714; python: 505; ruby: 354; perl: 134; makefile: 41
file content (41 lines) | stat: -rw-r--r-- 1,023 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# encoding: UTF-8

require 'thor'

require 'pathname'

module Elasticsearch

  module API

    class Lister < Thor
      namespace 'api'

      desc "list <PATH DIRECTORY WITH JSON SPEC FILES>", "List all the REST API endpoints from the JSON specification"
      method_option :verbose,  type: :boolean, default: false, desc: 'Output more information'
      method_option :format,   default: 'text', desc: 'Output format (text, json)'
      def list(directory)
        input = Pathname(directory).join('*.json')
        apis = Dir[input.to_s].map do |f|
          File.basename(f, '.json')
        end.sort

        if options[:verbose]
          say_status 'Count', apis.size
          say '▬'*terminal_width
        end

        case options[:format]
          when 'text'
            apis.each { |a| puts "* #{a}" }
          when 'json'
            puts apis.inspect
          else
            puts "[!] ERROR: Unknown output format '#{options[:format]}'"
            exit(1)
        end
      end
    end

  end
end