Sha256: 237b79992408befe2c2f282d0e37d31fbfb31021d39ab95bbe0f868f1f7a2dad

Contents?: true

Size: 1 KB

Versions: 1

Compression:

Stored size: 1 KB

Contents

require "abbrev"

module Groundwork
  def self.parse_options opts=ARGV
    global_opts = Trollop::options(opts) do
      banner <<-STR
Usage:
       groundwork [global_options] command [command_options]
Currently, the only implemented command is "generate", which generates a recipe for the current directory
Options are:
STR
      version "0.0.2"
      stop_on_unknown
    end

    cmd=short_for(opts.shift)

    return({ :options=>global_opts,
             :command=>cmd,
             :remainder=>opts
           })
  end

  def self.short_for cmd_start, all_commands=["generate"]
    return cmd_start unless cmd_start
    return cmd_start if all_commands.index(cmd_start)

    completions = all_commands.abbrev(cmd_start)
    if completions[cmd_start]
      completions[cmd_start]
    elsif completions.values.uniq.empty?
      raise RuntimeError.new("Unknown command \"#{cmd_start}\".")
    else
      raise RuntimeError.new("\"#{cmd_start}\" is ambiguous. Which did you mean:\n\t"+cmd_poss.join("\n\t"))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
groundwork-0.0.2 lib/options.rb