Class: Shomen::CLI::TomDocCommand
- Defined in:
- lib/shomen/cli/tomdoc.rb
Overview
RDoc command line interface.
Class Method Summary collapse
Instance Method Summary collapse
-
#argf(files) ⇒ Object
ARGF faker.
-
#initialize ⇒ TomDocCommand
constructor
New Shomen TomDoc command line interface.
- #option_main(parser, options) ⇒ Object
- #option_visibility(parser, options) ⇒ Object
- #run(argv) ⇒ Object
Methods inherited from Abstract
#option_debug, #option_force, #option_format, #option_help, #option_source, #option_warn, #parse, #root?
Constructor Details
#initialize ⇒ TomDocCommand
New Shomen TomDoc command line interface.
16 17 |
# File 'lib/shomen/cli/tomdoc.rb', line 16 def initialize end |
Class Method Details
.run(*argv) ⇒ Object
11 12 13 |
# File 'lib/shomen/cli/tomdoc.rb', line 11 def self.run(*argv) new.run(argv) end |
Instance Method Details
#argf(files) ⇒ Object
ARGF faker.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/shomen/cli/tomdoc.rb', line 75 def argf(files) buffer = '' files.select{ |arg| File.exists?(arg) }.each do |file| buffer << File.read(file) end require 'stringio' StringIO.new(buffer) end |
#option_main(parser, options) ⇒ Object
108 109 110 111 112 |
# File 'lib/shomen/cli/tomdoc.rb', line 108 def option_main(parser, ) parser.on('-m', '--main FILE') do |file| [:main] = file end end |
#option_visibility(parser, options) ⇒ Object
101 102 103 104 105 |
# File 'lib/shomen/cli/tomdoc.rb', line 101 def option_visibility(parser, ) parser.on('-v', '--visibility TYPE') do |type| [:visibility] = type end end |
#run(argv) ⇒ Object
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 = parse(argv, :format, :force, :visibility, :main, :source, defaults) if ![: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 # TODO: limit extensions of files files = files.map{ |f| File.directory?(f) ? Dir[File.join(f, '**/*')] : f }.flatten main = [:main] || Dir.glob('{README.*,README}').first visibility = [:visibility].to_s format = [: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() #@options) ignore and pattern tomdoc.generate(argf.read) case format when 'yaml' $stdout.puts(tomdoc.table.to_yaml) else $stdout.puts(tomdoc.table.to_json) end end |