20
21
22
23
24
25
26
27
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
|
# File 'lib/shomen/cli/tomdoc.rb', line 20
def run(argv)
require 'shomen/tomdoc'
defaults = {}
defaults[:format] = 'json'
defaults[:force] = false
defaults[:source] = true
options = parse(argv, :format, :force, :visibility, :main, :source, defaults)
if !options[:force] && !root?
$stderr.puts "Not a project directory. Use --force to override."
exit -1
end
if argv.empty?
if File.exist?('.document')
files = File.read('.document').split("\n")
files = files.reject{ |f| f.strip == '' or f.strip =~ /^\#/ }
files = files.map{ |f| Dir[f] }.flatten
else
files = ['lib']
end
else
files = argv
end
files = files.map{ |f| File.directory?(f) ? Dir[File.join(f, '**/*')] : f }.flatten
main = options[:main] || Dir.glob('{README.*,README}').first
visibility = options[:visibility].to_s
format = options[:format]
case format
when 'json', 'yaml'
else
$stderr.puts "ERROR: Format must be 'yaml` or 'json`."
exit -1
end
argf = argf(files)
tomdoc = TomDoc::Generators::Shomen.new()
tomdoc.generate(argf.read)
case format
when 'yaml'
$stdout.puts(tomdoc.table.to_yaml)
else
$stdout.puts(tomdoc.table.to_json)
end
end
|