Giter Club home page Giter Club logo

bossy's Introduction

@hapi/bossy

Command line options parser.

bossy is part of the hapi ecosystem and was designed to work seamlessly with the hapi web framework and its other components (but works great on its own or with other frameworks). If you are using a different web framework and find this module useful, check out hapi – they work even better together.

Visit the hapi.dev Developer Portal for tutorials, documentation, and support

Useful resources

bossy's People

Contributors

arb avatar cjihrig avatar danielb2 avatar devinivy avatar fampinheiro avatar geek avatar hofan41 avatar hueniverse avatar jarrodyellets avatar jaw187 avatar kanongil avatar lloydbenson avatar marsup avatar nargonath avatar nwhitmont avatar sericaia avatar smikes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bossy's Issues

Issue with node spawn

It seems child_process.spawn has its own way to provide arguments that's somehow different from the shell. If i provide as arguments ['-t 95'], bossy gets the array as it is, and not ['-t', '95'] as it would expect, so I get a missing value error in return. Happened to me from gulp-lab if it matters.

Help option Error Result

Currently, if you invoke the command line asking for help (ex: "-h") you MUST satisfy all the required arguments or you will get an error object back instead of a parsed object. While the net result is the same, it seems a little backwards. You should be able to pass in "-h".

We could either attach h to the resultant Error object or add an extra option to the type definition of help to add some special treatment for help type definitions.

The goal is to make testing this easier

if (args instanceof Error) {
  console.error('there was an error');
  return;
}

if (args.h) {
  console.log('you asked for help');
  return;
}

In order to get to the args.h block, you have to supply ALL the required arguments.

Thoughts?

Support multiple values for an option

Hi,
I would like to begin working on hapijs/lab#285 and in order to support this feature, it is necessary for bossy to somehow parse multiple values in for a given option. I am not quite sure what the appropriate pattern for this might be, either a comma separated list:

--reporter lcov,clover,html

Or whether they should be specified multiple times but added to an array

--reporter lcov --reporter clover --reporter html

I would definitely also like to try implementing this feature in bossy myself, so any guidance on enabling this behavior (or if there is another pattern you would like to suggest) I am all ears.

Thank you!

Slice

On these lines here we are slicing off the first two arguments which makes sense when working with process.argv, but if you are overriding that with your own arguments array, we shouldn't do that. Currently, users would have to pad their argument array by two.

Shortname doesn't work with a single dash

Bossy.usage() gives an incorrect way of calling alias shortname when greater than 1 character.

Given:

./sample.js

const definition = {
    options: {
        description: 'options',
        alias: 'o'
    },
    organization: {
        description: 'orgs',
        alias: 'org' // this should console log usage as --org not -org
    }
};

const args = Bossy.parse(definition);

console.log(
    Bossy.usage(definition)
);

console.log(args);

The following happens:

node sample
Options:                           

  -o, --options           options
  -org, --organization    orgs

{
  options: undefined,
  o: undefined,
  organization: undefined,
  org: undefined
}
node sample -org test
Options:                           

  -o, --options           options
  -org, --organization    orgs

Error: Invalid option: options missing value
    at Object.internals.formatError (project/node_modules/@hapi/bossy/lib/index.js:344:12)
    at Object.exports.parse (project/node_modules/@hapi/bossy/lib/index.js:73:43)
    at Object.<anonymous> (project/bin/sample:20:20)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  data: null,
  isBoom: true,
  isServer: true,
  output: {
    statusCode: 500,
    payload: {
      statusCode: 500,
      error: 'Internal Server Error',
      message: 'An internal server error occurred'
    },
    headers: {}
  }
}

But this works:

node sample --org test
Options:                           

  -o, --options           options
  -org, --organization    orgs

{ organization: 'test', options: undefined, o: undefined, org: 'test' }

Don't require short form

The documentation says:

The definition object should be structured with each object key representing the short form of an available command line argument.

However sometimes it's not easy to find a letter for the long form when the letter is already in use for an other option. Or sometimes I just don't want to allow short form for verbosity.

At the moment if I don't specify the short form, then usage information is wrong (-something instead of --something):

const definition = {
  help: {
    description: 'Show help',
    alias: 'h',
    type: 'boolean'
  },
  something: {
    description: 'Do something',
    type: 'boolean'
  }
};
Options:                 

  -h, --help    Show help
  -something    Do something

Another good example is lab. The definition in lab doesn't even follow what is in the documentation (use short form for definition object keys):

https://github.com/hapijs/lab/blob/master/lib/cli.js#L129

I think it would make more sense to use the long form as object keys.

Housekeeping

I see two open milestones, each with code changes committed to master... What's going on?

Unable to parse values that begin with -

For example:

lab --pattern -test

Here is a failed test case to demonstrate the issue:

    it('is able to parse a string that begins with -', (done) => {

        const line = '-a -test';
        const definition = {
            a: {
                type: 'string'
            }
        };

        const argv = parse(line, definition);
        expect(argv).to.deep.equal({ a: '-test'});

        done();
    });

Original issue: hapijs/lab#483

Action required: Greenkeeper could not be activated 🚨

🚨 You need to enable Continuous Integration on Greenkeeper branches of this repository. 🚨

To enable Greenkeeper, you need to make sure that a commit status is reported on all branches. This is required by Greenkeeper because it uses your CI build statuses to figure out when to notify you about breaking changes.

Since we didn’t receive a CI status on the greenkeeper/initial branch, it’s possible that you don’t have CI set up yet.
We recommend using:

If you have already set up a CI for this repository, you might need to check how it’s configured. Make sure it is set to run on all new branches. If you don’t want it to run on absolutely every branch, you can whitelist branches starting with greenkeeper/.

Once you have installed and configured CI on this repository correctly, you’ll need to re-trigger Greenkeeper’s initial pull request. To do this, please click the 'fix repo' button on account.greenkeeper.io.

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.