Class: BitClust::Subcommands::UpdateCommand

Inherits:
BitClust::Subcommand show all
Defined in:
lib/bitclust/subcommands/update_command.rb

Instance Method Summary collapse

Methods inherited from BitClust::Subcommand

#align_progress_bar_title, #error, #help, #needs_database?, #option_error, #srcdir_root

Constructor Details

#initializeUpdateCommand

Returns a new instance of UpdateCommand.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/bitclust/subcommands/update_command.rb', line 16

def initialize
  super
  @root = nil
  @markdowntree = nil
  @library = nil
  @parser.banner = "Usage: #{File.basename($0, '.*')} update [<file>...]"
  @parser.on('--stdlibtree=ROOT', 'Process stdlib source directory tree.') {|path|
    @root = path
  }
  @parser.on('--markdowntree=ROOT', 'Process Markdown source directory tree.') {|path|
    @markdowntree = path
  }
  @parser.on('--library-name=NAME', 'Use NAME for library name in file mode.') {|name|
    @library = name
  }
end

Instance Method Details

#exec(argv, options) ⇒ Object



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
# File 'lib/bitclust/subcommands/update_command.rb', line 40

def exec(argv, options)
  super
  if @markdowntree
    # ネイティブ md パース(M3)。source には md が入り、描画は
    # MDCompiler(GFM)が選択される。ブリッジは検証用に温存
    # (BITCLUST_MD_BRIDGE=1 で旧経路)
    if ENV['BITCLUST_MD_BRIDGE'] == '1'
      argv = @db.is_a?(FunctionDatabase) ? prepare_capi_markdowntree
                                         : (prepare_markdowntree; argv)
    else
      @db.transaction {
        @db.update_by_markdowntree(@markdowntree || raise)
      }
      return
    end
  end
  @db.transaction {
    if @root
      db = @db
      db.is_a?(MethodDatabase) or raise
      db.update_by_stdlibtree(@root || raise)
    end
    argv.each do |path|
      @db.update_by_file path, @library || guess_library_name(path)
    end
  }
  remap_source_locations if @markdowntree
ensure
  FileUtils.remove_entry(@bridge_dir) if @bridge_dir
end

#parse(argv) ⇒ Object



33
34
35
36
37
38
# File 'lib/bitclust/subcommands/update_command.rb', line 33

def parse(argv)
  super
  if not @root and not @markdowntree and argv.empty?
    error "no input file given"
  end
end