@unitybase/base/options

Parse a command line options & environment variables and create a configuration object.

 const cmdLineOpt = require('cmd/options')
 const argv = require('cmd/argv')

 let paramsDescription = cmdLineOpt.describe('cmd/generateDDL',
  'Check database structure for application domain. ' +
  'Generate DDL (both create and alter) if need and optionally run it'
 ).add(
    argv.establishConnectionFromCmdLineAttributes._cmdLineParams
 ).add({
   short: 'm',  long: 'models', param: 'modelsList', defaultValue: '*',
   help: 'Comma separated model names for DDL generation. If -e specified this options is ignored'
 }).add({
   short: 'e',  long: 'entities', param: 'entitiesList', defaultValue: '*',
   help: 'Comma separated entity names list for DDL generation'
 }).add({
   short: 'out',  long: 'out', param: 'outputPath', defaultValue: process.cwd(),
   help: 'Folder to output generated DDLs (one file per connection)'
 }).add({
   short: 'autorun',  long: 'autorun', defaultValue: false,
   help: 'execute DDL statement after generation. BE CAREFUL! DO NOT USE ON PRODUCTION'
 })
 let passedOptions = paramsDescription.parseVerbose({}, true)
Author:
  • pavel.mash

Classes

Options

Methods

describe(commandName, commandDescriptionopt, cliopt)Options static

Create a new options definition.
Arguments:
  1. commandName (String)  Name of a command then executed from a command line
  2. [commandDescription] (String)  Command description for help (-help switch)
  3. [cli] (String)  Command line interpretator
Example
const cmdLineOpt = require('cmd/options')
 let paramsDescription = cmdLineOpt.describe('cmd/createStore',
   'Create internal store structure (folders) for specifies FileSystem store'
 ).add({
   short: 'cfg',  long: 'cfg', param: 'serverConfig', defaultValue: 'ubConfig.json',
   help: 'Server config'
 }).add({
   short: 'store',  long: 'store', param: 'storesList', defaultValue: '*',
   help: 'Comma separated blob stores list'
 })
 let options = paramsDescription.parseVerbose({}, true);

switchIndex(switchName)Number static

Determines whether a switchName was passed as a command-line argument to the application Switch may be specified in the following ways on the command line: -switchName or /switchName
Arguments:
  1. switchName

switchValue(switchName)String|undefined static

Determines whether a switchName was passed as a command-line argument to the application and have VALUE Switch values may be specified in the following ways on the command line: -switchName Value or /switchName Value
Arguments:
  1. switchName

Type Definitions

Option

Properties:
Name Type Attributes Default Description
short String

a short option name

long String

a long option name. This name are used in parse result

param String <optional>

if parameter has a value - help string for a parameter name -short param

defaultValue * <optional>

a default value for a property. For a string properties what allow empty value set it to *

searchInEnv Boolean <optional>
false

if property do not passed as a cmd line switch then perform search of UB_+long.toUpperCase() in environment variables

help String

a help string for a usage() call