Giter Club home page Giter Club logo

Comments (4)

c4spar avatar c4spar commented on June 23, 2024

Hi @oganexon,

You can use the .stopEarly() method as descriped in the readme to pass unkown options to your command. If enabled, all options, starting from the first none option argument, will be passed as arguments to the action handler.

Literal arguments won't be passed to the action handler atm, but this feature is in progress.

from deno-cliffy.

oganexon avatar oganexon commented on June 23, 2024

Great, almost there
If i follow the example I can do:

$ deno run https://deno.land/x/cliffy/examples/command/stop-early.ts -d warning server -p 80
options: { debugLevel: "warning" }
script: server
args: [ "-p", "80" ]

But how can I do:

$ deno run https://deno.land/x/cliffy/examples/command/stop-early.ts --foo warning server -p 80

from deno-cliffy.

c4spar avatar c4spar commented on June 23, 2024

This is not possible with .stopEarly(), because .stopEarly() needs to know which options belongs to the command and which to the arguments. You need an argument to separate these options.

In your example, --foo will be interpreted as option from the stop-early.ts command and warning server -p 80 will be passed as arguments because warning is the first none option argument.

There is also another method called .useRawArgs(). If you call this method, all options are interpreted as arguments. But this will also disable the handling of all build in options like --help and --version.

from deno-cliffy.

oganexon avatar oganexon commented on June 23, 2024

Perfect, I managed to have help and get the args

export class RunCommand extends DefaultCommand {
  public constructor() {
    super();

    this.description(desc)
    .useRawArgs()
    .action((_, ...args) => {
      if (["-h", "--help", "help"].includes(args[0])) {
        Deno.stdout.writeSync(new TextEncoder().encode( this.getHelpCommand().getHelp() ) );
        Deno.exit()
      }
      console.log(args)
    });
  }
}

from deno-cliffy.

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.