leejarvis / slop

Simple Lightweight Option Parsing - ✨ new contributors welcome ✨

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

support positional arguments

fawaf opened this issue · comments

e.g.

ruby foo.rb test

Could you elaborate on what's broken here? Your example doesn't really help too much. Thanks!

sorry. this is more of a feature enhancement. i don't believe there is a way to extract out the "test" argument since this gem does not support positional arguments instead of regular "-" or "--" arguments.

% ruby foo.rb test
(do something with argument "test")
hello my name is "test"
%

Slop::Result has an arguments methods which returns the arguments sans parsed options. It looks like this:

#!/usr/bin/env ruby

require "slop"

opts = Slop.parse do |o|
  o.string "--name"
end

# ruby foo.rb test --name lee example
p opts.arguments #=> ["test", "example"]

So, in your case you could simply do opts.arguments.first

Hope that helps!