module Mdtoc::CLI

Public Class Methods

parse(args) click to toggle source
# File lib/mdtoc/cli.rb, line 14
def parse(args)
  parser = OptionParser.new do |parser_|
    parser_.banner = "Usage: #{parser_.program_name} [options] files or directories..."
    parser_.on('-h', '--help', 'Show this message') do
      puts parser_
      exit
    end
    parser_.on('-o', '--output PATH', 'Update a table of contents in the file at PATH')
    parser_.on('-a', '--[no-]append', 'Append to the --output file if a <!-- mdtoc --> tag isn\'t found')
    parser_.on('-c', '--[no-]create', 'Create the --output file if it does not exist')
  end

  options = Options.new
  options.paths = parser.parse(args, into: options)
  if options.paths.empty?
    warn('Specify at least one file or directory to read')
    exit(1)
  end
  options
end