75lb / command-line-args

A mature, feature-complete library to parse command-line options.
MIT License
689 stars 106 forks source link

name containing dash (e.g. --num-max) supported? #122

Closed sarnobat closed 2 years ago

sarnobat commented 2 years ago

It's common for long options to contain -. I can't figure out a way to add a name that contains a dash.

I was hoping either _ gets converted to -, or that it's possible to specify a destination variable. I believe python's argparse works this way.

(Good to see a fellow Welshman btw)

75lb commented 2 years ago

Morning! The follow example works fine for me..

import commandLineArgs from 'command-line-args'

const optionDefinitions = [
  { name: 'num-max', type: Number }
]
const options = commandLineArgs(optionDefinitions)
console.log(options)

Usage:

$ node example.mjs --num-max 2
{ 'num-max': 2 }
sarnobat commented 2 years ago

Thanks for the quick reply, I'll try this and follow up here if I still have difficulties.