Module: Prmd::CLI::Generate

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

Overview

‘init’ command module. Though this is called, Generate, it is used by the init method for creating new Schema files

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 ‘init’ command.

Examples:

Usage

Prmd::CLI::Generate.execute(argv: ['bread'],
                            output_file: 'schema/schemata/bread.json')

Parameters:

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


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

def self.execute(options = {})
  name = options.fetch(:argv).first
  if Prmd::Utils.blank?(name)
    abort @parser
  else
    write_result Prmd.init(name, options), options
  end
end

.make_parser(options = {}) ⇒ OptionParser

Returns a OptionParser for parsing ‘init’ command options.

Parameters:

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

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/prmd/cli/generate.rb', line 17

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

  OptionParser.new do |opts|
    opts.banner = "#{binname} init [options] <resource name>"
    opts.on('-t', '--template templates', String, 'Use alternate template') do |t|
      yield :template, t
    end
    opts.on('-y', '--yaml', 'Generate YAML') do |y|
      yield :yaml, y
    end
    opts.on('-o', '--output-file FILENAME', String, 'File to write result to') do |n|
      yield :output_file, n
    end
  end
end