Giter Club home page Giter Club logo

Comments (3)

ndmeiri avatar ndmeiri commented on June 9, 2024

I suppose with_argument('fake_argument') could be called outside of (i.e., after) the subcommand configuration block, but there could still be use cases where the subcommand's argument needs to come before the subcommand's options.

from lino.

tobyclemson avatar tobyclemson commented on June 9, 2024

Hi Naji,

Thanks for raising the issue. I have a few questions on what you'd expect here. Let's say a command uses a structure that has sub and sub-sub commands:

command = Lino::CommandLineBuilder
    .for_command('x')
    .with_subcommand('y')
    .with_subcommand('z')

Today this produces x y z. Now, let's say we allow each of those to have arguments:

command = Lino::CommandLineBuilder
    .for_command('x')
    .with_subcommand('y') do |y|
      y.with_argument('a')
    end
    .with_subcommand('z') do |z|
      z.with_argument('b')
    end

What would you expect the command to end up as? x y a z b?

There's then a risk of misinterpreting arguments as subcommands and vice versa. It's for this reason that most commands expect or at least allow all arguments to come last after flags and options. And it's based on this that arguments is considered a top level method rather than a subcommand method.

Let me know your thoughts,

Thanks,
Toby

from lino.

ndmeiri avatar ndmeiri commented on June 9, 2024

Hi Toby,

Thanks for the prompt reply! That's fair; I hadn't considered that ambiguity.

FWIW, I would expect x y a z b. I would expect that the command (y in this case) would correctly interpret a as an argument if y was indeed expecting it. If y was not expecting argument a and so misinterpreted a as an (invalid) subcommand, I would expect y to emit some error and halt. i.e., I consider it the user's responsibility to build a well-formed command for their use case.

But I do see the drawbacks, and the command I'm trying to use does indeed allow arguments to come last, so I'll close this out!

Thanks!

from lino.

Related Issues (2)

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.