Simple command line parser for node
npm install @hutechtechnical/excepturi-tempore-nihil-cupiditateSimple command line parser for node
npm install @hutechtechnical/excepturi-tempore-nihil-cupiditate
#### Initialization
const clp = require("@hutechtechnical/excepturi-tempore-nihil-cupiditate");
const parser = new clp.ClParser({
offset:
optionPrefix:
caseSensitive:
});
#### Properties
parser.offset Number, default: 2
parser.optionPrefix String, "/", "-", or "--", default: "/"
parser.parameterCount Number of parameters (readonly, no options or switches)
parser.options Array of objects [{ option<1>: value }, ..., { option
Does not follow the caseSensitive option.
parser.parameters Array (readonly, no options or switches)
parser.switches Array of strings [ switch<1>, ..., switch
Does not follow the caseSensitive option.
#### Methods
parser.option(name) Get the value of the named option
parser.parameter(index) Get the command line parameter indicated by index
parser.switch(name) Returns boolean value that indicates whether the named switch exist
#### Initialization
const clp = require("@hutechtechnical/excepturi-tempore-nihil-cupiditate");
clp.setPreferences({
offset:
optionPrefix:
caseSensitive:
});
#### Functions
parser.getOption(name) Returns the value of the named option.
parser.getOptions() Returns an array of option objects
[{ option<1>: value }, ..., { option
Does not follow the caseSensitive option.
parser.getParameter(index) Returns the command line parameter indicated by index.
parser.getParameterCount() Returns the number of parameters (no options or switches).
parser.getParameters() Returns parameters as array (no options or switches).
parser.isSwitch(name) Returns a boolean value that indicates whether the named switch exist.
parser.getSwitches() Return an array of strings [ switch<1>, ..., switch
Does not follow the caseSensitive option.
const clp = require("@hutechtechnical/excepturi-tempore-nihil-cupiditate");
const parser = new clp.ClParser({ offset: 2 });
console.log(parser.option("command")) -> "copy"
console.log(parser.options) -> [{ command: "copy", tries:"3" }]
console.log(parser.parameterCount) -> 2
console.log(parser.parameters) -> ["source.txt","target.txt"]
console.log(parser.parameter(0)) -> "source.txt"
console.log(parser.parameter(1)) -> "target 42.txt"
console.log(parser.switch("silent")) -> true
console.log(parser.switches) -> ["silent","i"]