Code Monkey home page Code Monkey logo

Comments (9)

dthree avatar dthree commented on August 27, 2024

You mean in addition to vorpal.parse? I suppose I could literally map it to minimist if that helps.

from vorpal.

Downchuck avatar Downchuck commented on August 27, 2024

That's the idea, you'd map to minimist by default, with an optional second argument that'd run commander.js parse -- which would use your vorpal command list to return an object. Both are meant to be maps over to minimist/commander just in case it's needed.

Related to using this: on vorpal.parse -- how do I detect whether or not a command was found? Is there a default callback, like parse(argv, notFoundFn)?

from vorpal.

dthree avatar dthree commented on August 27, 2024

It is meant to do exactly what you app does if you run it first. So it would technically display the help command.

Check out the .catch command (it's new, maybe I didn't document it yet): here's an example I pulled out of wat, which im working on:

  vorpal
    .catch('[commands...]')
    .option('-d, --detail', 'View detailed markdown on item.')
    .option('-i, --install', 'View installation instructions.')
    .autocompletion(function (text, iteration, cb) {
      const self = this;
      const index = parent.clerk.indexer.index();
      let result = util.autocomplete(text, iteration, index, function (word, options) {
        const res = self.match(word, options);
        return res;
      });
      if (_.isArray(result)) {
        result.sort();
      }
      cb(undefined, result);
    })
    .action(function (args, cb) {
      const self = this;

      args = args || {};
      args.options = args.options || {};

      // Handle humans.
      if (String(args.commands[0]).toLowerCase() === 'wat') {
        args.commands.shift();
      }

       // ...

      cb();
    });

Catch basically is called if you don't match on any other command, so it overrides help as the default function if no command is met. By adding in a [variadicArg...], you can pretty much do anything you want.

from vorpal.

dthree avatar dthree commented on August 27, 2024

On the parse, I think im gonna do this:

var args = vorpal.parse(process.argv, { use: 'minimist' });
var args = vorpal.parse(process.argv, { use: 'commander' });

from vorpal.

Downchuck avatar Downchuck commented on August 27, 2024

I like it.

from vorpal.

dthree avatar dthree commented on August 27, 2024

:)

Does the catch thing make sense?

from vorpal.

Downchuck avatar Downchuck commented on August 27, 2024

Yes, it makes sense, does just what I want.

from vorpal.

dthree avatar dthree commented on August 27, 2024

Perfect.

from vorpal.

dthree avatar dthree commented on August 27, 2024

@Downchuck Added this. Coming out in a release today.

from vorpal.

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.