Skip to content

Support for required arguments? #45

@rauschma

Description

@rauschma

Would it make sense to support required arguments? For example:

const args = arg({
	'--help':    Boolean,
	'--port':    arg.req(Number),
	'--name':    String,
	'--tag':     arg.req([String]),
});

Alternatively:

const args = arg({
	'--help': Boolean,
	'--path': String,
});

const {
	'--help': printHelp = false,
	'--path': thePath = arg.required('--path', String),
} = args;

arg.required() would print an error message and exit Node.js. Downsides of this approach: Doesn’t handle aliases, redundancy.

If this is out of scope, it would be a good FAQ, because many shell argument parsing libraries support this feature.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions