Class: Shomen::Yard::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/shomen-yard/command.rb

Overview

The YARD command line tool provides a utility to generate a Shomen documentation file using YARD’s .yardoc cache.

Examples:

$ shomen-yard --readme README.md lib - [A-Z]*.*

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*argv) ⇒ Command

Initialize new command.

argv - Command line arguments. [Array]

Returns CLI instance.



33
34
35
36
37
# File 'lib/shomen-yard/command.rb', line 33

def initialize(*argv)
  @options = {}

  parse(argv)
end

Instance Attribute Details

#optionsObject (readonly)

Command line options.



26
27
28
# File 'lib/shomen-yard/command.rb', line 26

def options
  @options
end

Class Method Details

.run(*argv) ⇒ Object

Public: Shortcut for ‘CLI.new(*argv).run`.

Returns nothing.



21
22
23
# File 'lib/shomen-yard/command.rb', line 21

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

Instance Method Details

#force?Boolean

Is ‘$FORCE` set?

Returns true or false.

Returns:

  • (Boolean)


138
139
140
# File 'lib/shomen-yard/command.rb', line 138

def force?
  !!$FORCE
end

#parse(argv) ⇒ Object

Parse command line arguments.

argv - List of command line arguments. [Array]

Returns list of arguments. [Array]



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/shomen-yard/command.rb', line 53

def parse(argv)
  if i = argv.index('-')
    @documents = argv[i+1..-1]
    argv = argv[0...i]
  end

  parser = OptionParser.new

  parser_options(parser)

  parser.parse!(argv)

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

  @scripts = argv
end

#parser_options(parser) ⇒ Object

Define command line options.

parser - Instance of OptionParser.

Returns nothing.



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/shomen-yard/command.rb', line 78

def parser_options(parser)
  #parser.on('-Y', '--yard', 'use YARD for parsing') do
  #  options[:engine] = :yard
  #end
  #parser.on('-R', '--rdoc', 'use RDoc for parsing') do
  #  options[:engine] = :rdoc
  #end

  parser.on('-j', '--json', 'output JSON instead of YAML (default)') do
    options[:format] = :json
  end
  parser.on('-y', '--yaml', 'output YAML instead of JSON') do
    options[:format] = :yaml
  end

  parser.on('-d', '--db DIR', 'documentation store directory (deafult is `.rdoc` or `.yardoc`)') do |dir|
    options[:store] = dir
  end
  parser.on('-c', '--use-cache', 'do not regenerate docs, use pre-existing cache') do
    options[:use_cache] = true
  end

  parser.on('-s', '--source', 'include full source in script documentation') do
    options[:source] = true
  end
  parser.on('-w', '--webcvs URI', 'prefix link to source code') do |uri|
    options[:webcvs] = uri
  end
  parser.on('-r', '--readme FILE', 'which file to use as main') do |file|
    options[:readme] = file
  end

  #parser.on('--save', 'save options for future use') do |markup|
  #  options[:save] = true
  #end

  # TODO: shouldn't this be in .yardopts?
  parser.on('--markup TYPE', 'markup type used for comments (rdoc, md, tomdoc)') do |markup|
    options[:markup] = markup.to_sym
  end

  parser.on('-F', '--force') do
    $FORCE = true
  end

  parser.on_tail('--debug', 'run with $DEBUG set to true') do
    $DEBUG = true
  end
  parser.on_tail('--warn', 'run with $VERBOSE set to true') do
    $VERBOSE = true
  end

  parser.on_tail('--help', 'see this help message') do
    puts parser; exit -1
  end
end

#root?Boolean

Is this a project directory?

Returns true or false.

Returns:

  • (Boolean)


145
146
147
148
149
150
151
152
153
154
# File 'lib/shomen-yard/command.rb', line 145

def root?
  root = false
  root = true if File.exist?('.ruby')
  root = true if File.exist?('.yardoc')
  root = true if File.exist?('.rdoc')
  root = true if File.exist?('.git')
  root = true if File.exist?('.hg')
  root = true if File.exist?('_darcs')
  root
end

#runObject

Public: Run command.

Returns nothing.



42
43
44
45
# File 'lib/shomen-yard/command.rb', line 42

def run
  generator = Generator.new(options)
  $stdout.puts generator
end