Module: Prmd::CLI::Doc

Extended by:
Base
Defined in:
lib/prmd/cli/doc.rb

Overview

‘doc’ command module.

Class Method Summary collapse

Methods included from Base

execute, make_parser, noop_execute, parse_options, run

Class Method Details

.execute(options = {}) ⇒ void

This method returns an undefined value.

Executes the ‘doc’ command.

Examples:

Usage

Prmd::CLI::Doc.execute(argv: ['schema/api.json'],
                       output_file: 'schema/api.md')

Parameters:

  • options (Hash<Symbol, Object>) (defaults to: {})


59
60
61
62
63
64
65
66
# File 'lib/prmd/cli/doc.rb', line 59

def self.execute(options = {})
  filename = options.fetch(:argv).first
  template = File.expand_path('templates', File.dirname(__FILE__))
  _, data = try_read(filename)
  schema = Prmd::Schema.new(data)
  opts = options.merge(template: template)
  write_result Prmd.render(schema, opts), options
end

.make_parser(options = {}) ⇒ OptionParser

Returns a OptionParser for parsing ‘doc’ command options.

Parameters:

  • options (Hash<Symbol, Object>) (defaults to: {})

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/prmd/cli/doc.rb', line 15

def self.make_parser(options = {})
  binname = options.fetch(:bin, 'prmd')

  OptionParser.new do |opts|
    opts.banner = "#{binname} doc [options] <combined schema>"
    opts.on('-s', '--settings FILENAME', String, 'Config file to use') do |s|
      settings = Prmd.load_schema_file(s) || {}
      options = HashHelpers.deep_symbolize_keys(settings)
      yield :settings, options
    end
    opts.on('-c', '--content-type application/json', String, 'Content-Type header') do |c|
      yield :content_type, c
    end
    opts.on('-o', '--output-file FILENAME', String, 'File to write result to') do |n|
      yield :output_file, n
    end
    opts.on('-p', '--prepend header,overview', Array, 'Prepend files to output') do |p|
      yield :prepend, p
    end
  end
end

.set_option(options, key, value) ⇒ void

This method returns an undefined value.

Overwritten to support :settings merging.

Parameters:

  • options (Hash<Symbol, Object>)
  • key (Symbol)
  • value (Object)

See Also:

  • Base#set_option


43
44
45
46
47
48
49
# File 'lib/prmd/cli/doc.rb', line 43

def self.set_option(options, key, value)
  if key == :settings
    options.replace(value.merge(options))
  else
    super
  end
end