-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
Description
Support a method named usePackageJson. When it's called, commander use will use the nearest package.json file, and use its name, version and description filds as commander's name, version and description.
const program = new Command();
program.usePackageJson(import.meta.url, {name: true, version:true, descrition: true});
// Equivalent to:
const packageJson = getProjectPackageJson();
const program = new Command();
program.name(packageJson.name).version(packageJson.name).description(packageJson.description);Why?
- Name and version are commonly used. Almost every cli tool need them. Commander is expected to simplify it.
- Using
import packageJson from '../package.json'seems not a good prectice for developers. I think the source code should not rely on a json config outside of the source code base. For example,package.jsonis in the root, while thecli.jsis in<root>/srcdirectory. the code insidesrcrely a config outside ofsrc. It seems break the edge.
jonmckee, ForkKILLET and jdmarshall