Class: Args

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

Class Method Summary collapse

Class Method Details

.parse(args) ⇒ Object

Return a structure describing the options.



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/lapack.rb', line 172

def self.parse(args)
  # The options specified on the command line will be collected in *options*.
  # We set default values here.
  options = OpenStruct.new
  options.command
  opt_parser = OptionParser.new do |opts|
    opts.banner = "Usage: lapack [command] [command_args]..."

    opts.separator ""
    opts.separator "Commands:"
    opts.separator "\t add [reponame] -- add repository. Currently supported: ctan"
    opts.separator "\t update [reponame] -- update repository index."
    opts.separator "\t install [reponame] [package]... [to_dir] -- install packages from repository to specified directory. If no directory specified use current working dir"
    opts.separator "\t remove [reponame] [package]... -- remove packages from local cache"
    opts.separator ""
    opts.separator "Specific options:"

    # No argument, shows at tail.  This will print an options summary.
    # Try it and see!
    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end

    # Another typical switch to print the version.
    opts.on_tail("--version", "Show version") do
      puts Version.join('.')
      exit
    end
  end

  opt_parser.parse!(args)
  options
end