Skip to content

Committing not to ever use a description field / maybe reserving some other fields for future use #86

@bakkot

Description

@bakkot

Right now, parseArgs is not going to generate usage text for you. I think that's sensible. But it's an obvious thing to want, so I imagine someone's going to make a library which takes the options specification and generates help text. The way I imagine that working is that it would take exactly the same options config, but each option would additionally have a description field, and possibly others. That is:

let { makeUsage } = require('some-userland-library');
let { parseArgs } = require('util');

let options = {
  foo: {
    type: 'string',
    description: 'A metavariable.',
  },
  bar: {
    type: 'string',
    description: 'A measure of music.',
  },
  help: {
    type: 'boolean',
    description: 'Display this message.',
  },
};

let parsed = parseArgs({ options });

if (parsed.values.help) {
  console.log(makeUsage({ options }));
  process.exit(0);
}

// etc

The thing to note here is that I expect such usage-generating libraries to be passed the same object as parseArgs, because that's by far the most convenient thing for script authors. But it would (in my imagining) also look at some additional keys currently ignored by parseArgs, at the very least description.

If and when such libraries exist and are in common use, that means parseArgs is never going to be able to use any such additional keys for its own purposes - that would be a breaking change, because the script author did not intend parseArgs to read the descriptions. A particularly cautious library author might want to refrain from using extra fields for that reason, though I am sure not everyone will be that cautious, so such libraries will almost certainly exist regardless.

As such, I think it makes sense to decide now if there are any fields like this which parseArgs wants to commit to not using, so that such userland libraries can use those fields without worrying about that breaking parseArgs later.

And, conversely, if there are fields (possibly default?) which parseArgs might want to make use of later, but which a library built on top of parseArgs might start using for their own purposes, it might make sense to reserve those fields somehow - either just in the description of parseArgs, or (more aggressively) by actively throwing if those fields exist.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions