Class: BiocGem::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/bioc_gem/parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = nil) ⇒ Parser

Returns a new instance of Parser.



8
9
10
11
12
13
# File 'lib/bioc_gem/parser.rb', line 8

def initialize(args = nil)
  @comand = nil

  @options = Options.new
  parse_options(args) if args
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/bioc_gem/parser.rb', line 6

def command
  @command
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/bioc_gem/parser.rb', line 6

def options
  @options
end

Instance Method Details

#parse!(args = ARGV) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/bioc_gem/parser.rb', line 15

def parse!(args = ARGV)
  @command = args.shift&.to_sym
  if [:new].include?(command)
    public_send("parse_options_#{command}", args)
  else
    warn "Unknown command #{command}"
    nil
  end
end

#parse_options_new(args) ⇒ Object



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
73
74
# File 'lib/bioc_gem/parser.rb', line 25

def parse_options_new(args)
  opt_parser = OptionParser.new do |parser|
    parser.banner = "Usage: biocgem new [options]"

    parser.on("-o", "--output [DIR]", "Output directory") do |dir|
      options.output_directory = dir
    end
    parser.on("-n", "--bioc_package_name VAL", "e.g. org.Hs.eg.db") do |n|
      options.bioc_package_name = n
    end
    parser.on("-s", "--bioc_sqlite_database_name VAL", "e.g. org.Hs.eg.sqlite") do |db|
      options.bioc_sqlite_database_name = db
    end
    parser.on("--gem_icon [VAL]", "e.g. :family:") do |icon|
      options.gem_icon = icon
    end
    parser.on("--gem_constant_name [VAL]", "e.g. OrgHsEgDb") do |c|
      options.gem_constant_name = c
    end
    parser.on("--gem_require_name [VAL]", "e.g. org_hs_eg_db") do |rname|
      options.gem_require_name = rname
    end
    parser.on("-m", "--bioc_package_md5sum [VAL]", "check md5sum") do |md5|
      options.bioc_package_md5sum = md5
    end
    parser.on("--bioc_package_sha256sum [VAL]", "check sha256sum") do |sha256|
      options.bioc_package_sha256sum = sha256
    end
    parser.on("--bioc_version [VAL]", "e.g. 3.14") do |bv|
      options.bioc_version = bv
    end
    parser.on("-v", "--bioc_package_version VAL", "e.g. 3.14.0") do |v|
      options.bioc_package_version = v
    end
  end

  opt_parser.parse!(args)

  options.gem_icon ||= ":notes:"
  options.gem_constant_name ||= \
    options.bioc_package_name
           .split(".").map(&:capitalize).join
  options.gem_require_name.nil?
  options.gem_require_name ||= \
    options.bioc_package_name
           .split(".").map(&:downcase).join("_")
  options.bioc_version ||= "release"

  options
end