Class: Xmindoc::Command

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Command

Returns a new instance of Command.



62
63
64
65
66
67
68
69
# File 'lib/xmindoc.rb', line 62

def initialize(argv)
  @argv = argv
  @option = { }
  @option[:format_from] = 'html' # fixed
  @option[:format_to] = 'markdown' # default
  @option[:file_input] = '' # XMind file (.xmind)
  @option[:file_output] = '' # [option]
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



60
61
62
# File 'lib/xmindoc.rb', line 60

def argv
  @argv
end

#optionObject (readonly)

Returns the value of attribute option.



60
61
62
# File 'lib/xmindoc.rb', line 60

def option
  @option
end

Instance Method Details

#parseObject

Parse command line options



72
73
74
75
76
77
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
134
135
136
137
138
# File 'lib/xmindoc.rb', line 72

def parse()
  # Option Parser of optparse
  opt = OptionParser.new
  script_name = File.basename($0)
  opt.banner = "Usage: #{script_name} [options] input.xmind"

  #
  # Option Settings
  #

  # Output
  opt.on('-o FILE','--output FILE','Output Filename') {|v| @option[:file_output] = v }

  # Format(Output)
  output_formats_short = %w(markdown org html latex rst plain)
  output_formats_long = %w(native json html html5 html+lhs html5+lhs s5 slidy slideous dzslides docbook opendocument latex latex+lhs beamer beamer+lhs context texinfo man markdown markdown+lhs plain rst rst+lhs mediawiki textile rtf org asciidoc odt docx epub)
  str_output_formats = "Output formats: " + output_formats_short.join(', ') + ", ... \n\t\t\t\t\t(for other formats: see \"pandoc --help\")"

  opt.on('-t FORMAT','--to=FORMAT',str_output_formats) {|v| @option[:format_to] = v }
  opt.on('-w FORMAT','--write=FORMAT',str_output_formats) {|v| @option[:format_to] = v }

  # Other options for Pandoc
  str_pandoc_options = "Pandoc options (Use double quotes like \"--atx-headers\")\n\t\t\t\t\t(for other options: see \"pandoc --help\")"
  opt.on('--pandoc-options=OPTIONS',str_pandoc_options) {|v| @option[:pandoc_options] = v }

  # Help
  opt.on( '-h', '--help', 'Display this screen' ) do
    puts opt
    exit
  end


  # Do parsing
  begin
    pp @argv if DEBUG
    opt.permute!(@argv)
  rescue => e
    # Catch exception when an option is wrong
    puts opt
    abort(e)
  end

  ## Check whether ARGV is null
  if @argv.length == 0
    # Show help
    puts opt
    exit
  end

  print "argv: " if DEBUG
  pp @argv if DEBUG

  @option[:file_input] = @argv.pop

  ## Check whether the filename ends with ".xmind"
  if not (@option[:file_input] =~ /^.*\.xmind$/)
    puts opt
    abort("ERROR: filename should end with \".xmind\"")
  end

  # Check format
  if not output_formats_long.include?(@option[:format_to])
    puts opt
    abort("ERROR: wrong output format: "+ @option[:format_to])
  end

end