[UTIL] Added a utility to print the list of APIs based on the JSON filenames
This commit is contained in:
parent
11db906004
commit
3a359a1f2a
|
@ -1,2 +1,3 @@
|
|||
require File.expand_path('./thor/generate_api')
|
||||
require File.expand_path('./thor/generate_source')
|
||||
require File.expand_path('./thor/lister')
|
||||
|
|
|
@ -0,0 +1,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
|
Loading…
Reference in New Issue