Giter Club home page Giter Club logo

Comments (7)

leejarvis avatar leejarvis commented on May 19, 2024

Thanks for reporting this. I should have some time tomorrow to look into it a little more.

from slop.

leejarvis avatar leejarvis commented on May 19, 2024

How about something like this:

require 'slop'

opts = Slop::Commands.new do
  on :install
end

opts.parse %w(install geronimo)

p opts.arguments #=> ["geronimo"]

from slop.

kyrylo avatar kyrylo commented on May 19, 2024

Looks good, but still there is no way to tell, which command has been triggered:

opts = Slop::Commands.new do
  on :install
  on :list
end

opts.parse %w(install geronimo)

p opts.arguments #=> ["geronimo"]
# Is this an argument of `install` or maybe `list`?

from slop.

leejarvis avatar leejarvis commented on May 19, 2024

I can't see why you would ever care which command was used. I see something like this:

if opts[:install]
  run_installer(opts.arguments)
end

And just pass around opts.arguments to any sub command you need

from slop.

kyrylo avatar kyrylo commented on May 19, 2024

I don't know, maybe I don't understand something, but this if check doesn't work as you showed in your example. opts[:install] always returns a Slop instance, whatever happens.

opts = Slop::Commands.new do
  on :install
  on :list
end

opts.parse %w(install geronimo)

p opts[:install]
#=> #<Slop {:strict=>false, :help=>false, :banner=>nil, :ignore_case=>false, :autocreate=>false, :arguments=>false, :optional_arguments=>false, :multiple_switches=>true, :longest_flag=>0} []>

p opts[:list]
#=> #<Slop {:strict=>false, :help=>false, :banner=>nil, :ignore_case=>false, :autocreate=>false, :arguments=>false, :optional_arguments=>false, :multiple_switches=>true, :longest_flag=>0} []>

P.S.: Also, keep in mind the situation when we want to pass multiple arguments (like we can do it with options: --install geronimo,banzai,huzzah)

from slop.

leejarvis avatar leejarvis commented on May 19, 2024

Yeah you're right. I think temporarily something like this will have to do:

opts = Slop::Commands.new do
  on :install
  on :list
end

opts.parse %w(install geronimo)

if opts.present?(:install)
  # do something with opts.arguments
end

Which I guess is just short for

if ARGV.first == 'install'
  # ...

That is, I think the command interface probably needs an overhaul but I'd rather plan and spend the time getting it right for Slop v4.

from slop.

leejarvis avatar leejarvis commented on May 19, 2024

Closed by #76

from slop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.