Skip to content

Program Setting

Ashish Uttam edited this page Sep 16, 2019 · 1 revision

EasyCli also provides a couple of settings that control the program execution. These settings must be set before calling the constructor of the Program class.

Following is how to update the settings -

#!/usr/bin/env node
const Program = require('@auttam/easycli').Program

// updating program settings
Program.settings({
    mainMethod: "init",
    useColors: false
})

class HelloWorld extends Program {
    init() {
        console.log("init() is main now, & help won't have colors")
    }
}

Program.run(new HelloWorld())

Available Settings with default values

{
    /** name of the main method to call when program is running in no-command mode */
    mainMethod: "main",
    
    /** global rejection handler for 'unhandledRejection' event of the process */
    rejectionHandler: (reason, promise) => { console.error(reason) },
    
    /** index from where minimist should start parsing command line arguments */
    processArgvStartIndex: 2,
    
    /** options for minimist arguments parser, see minimist package for more help  */
    minimistOptions: null,
    
    /** flag to enable program commands */
    /** note: when commands are enabled, mainMethod is not called */
    enableCommands: false,
    
    /** flag to enable global help command  */
    enableHelpCommand: true,

    /** flag to enable global version option --version, -v or --Ver */
    enableVersionOption: true,

    /** flag to enable global help option --help or -h */
    enableHelpOption: true,

    /** flag to show help when no command argument is supplied to the program */
    showHelpOnNoCommand: true,
    
    /** flag to show help on invalid options i.e when value provided is not allowed */
    showHelpOnInvalidOptions: true,
    
    /** flag to prioritize program options, i.e. call 'onProgramOption' even when command has options */
    prioritizeProgramOptions: false,
    
    /** flag to show help on invalid parameter, like required param missing, value provided is not allowed etc. */
    showHelpOnInvalidParams: true,
    
    /** flag to use colors while printing text to console */
    useColors: true,

    /** list of method names to ignore as command methods */
    nonCmdMethods: ['onInvalidCommand', 'onExit', 'onProgramOption'],
    
    /** name of the method that is called when command name not supplied */
    defaultCommandMethod: "defaultCommand",
    
}

Clone this wiki locally