Class: Shomen::CLI::YARDCommand

Inherits:
Abstract
  • Object
show all
Defined in:
lib/shomen/cli/yard.rb

Overview

YARD command line interface.

Unlike the RDoc command, this passes ARGV on to YARD’s actual CLI interface, so all YARD commandline options are supported, albeit some options have no baring on the generation of a Shomen model).

The yard command provides a utility to generate a Shomen doc file using YARD’s .yardoc cache.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#option_debug, #option_force, #option_format, #option_help, #option_source, #option_warn, #parse, #root?

Constructor Details

#initializeYARDCommand

New Shomen YARD command line interface.



24
25
# File 'lib/shomen/cli/yard.rb', line 24

def initialize
end

Class Method Details

.run(*argv) ⇒ Object



19
20
21
# File 'lib/shomen/cli/yard.rb', line 19

def self.run(*argv)
  new.run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



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
# File 'lib/shomen/cli/yard.rb', line 28

def run(argv)
  require 'shomen/yard'

  force = argv.delete('--force')

  if !(force or root?)
    $stderr.puts "ERROR: Not a project directory. Use --force to override."
    exit -1
  end

  # TODO: support -y/--yaml or -j/--json ?

  format = (
    if i = argv.index('--format') || argv.index('-f')
      argv[i+1]
      argv.delete_at(i)
      argv.delete_at(i)
    else
      'json'
    end
  )

  case format
  when 'json', 'yaml'
  else
    $stderr.puts "ERROR: Format must be 'yaml` or 'json`."
    exit -1
  end

  argv.unshift('-n')  # do not generate yard documentation
  argv.unshift('-q')  # supress yard's usual output

  YARD::Registry.clear  # clear the registry in memory to remove any previous runs

  yard = YARD::CLI::Yardoc.new
  yard.run(*argv)

  files    = yard.options[:files].map(&:filename) + yard.files
  database = yard.options[:db]

  options = {}
  options[:format] = format
  options[:files]  = files
  options[:db]     = database

  #options = parse(argv, :yaml, :clear, :db, :yardopts, :force, defaults)

  yard = Shomen::YardAdaptor.new(options)
  yard.generate

  case format
  when 'yaml'
    $stdout.puts(yard.table.to_yaml)
  else
    $stdout.puts(yard.table.to_json)
  end
end