75lb / command-line-usage

A simple, data-driven module for creating a usage guide.
MIT License
208 stars 36 forks source link

Compatibility with command-line-args? #46

Closed mnpenner closed 2 weeks ago

mnpenner commented 2 weeks ago

command-line-args says we can use this lib to show usage.

But the syntaxes seem completely different?

For example, if I try:

async function main(): Promise<number | void> {
    const options = commandLineArgs([
            {name: 'help', alias: 'h', type: Boolean},
        ]
    )

    if(options.help) {
        console.log(commandLineUsage([
            {
                header: 'Options',
                optionList: options,
            }
        ]))

        return 0
    }

    return run(options)
}

It renders like this:

image

Do I really have to define my options twice? Once for each lib using slightly different options?

mnpenner commented 2 weeks ago

Sorry, I'm dumb. Should have been

async function main(): Promise<number | void> {
    const optionsList = [
        {name: 'help', alias: 'h', type: Boolean},
    ]

    const options = commandLineArgs(optionsList)

    if(options.help) {
        console.log(commandLineUsage([
            {
                header: 'Options',
                optionList: optionsList,
            }
        ]))

        return 0
    }

    return run(options)
}