Import other modules into monorepo
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
45
src/cli/directive/options/FlagOption.ts
Normal file
45
src/cli/directive/options/FlagOption.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import {CLIOption} from "./CLIOption"
|
||||
|
||||
/**
|
||||
* Non-positional, flag-based CLI option.
|
||||
*/
|
||||
export class FlagOption<T> extends CLIOption<T> {
|
||||
|
||||
constructor(
|
||||
/**
|
||||
* The long-form flag for this option.
|
||||
* @example --path, --create
|
||||
*/
|
||||
public readonly longFlag?: string,
|
||||
/**
|
||||
* The short-form flag for this option.
|
||||
* @example -p, -c
|
||||
*/
|
||||
public readonly shortFlag?: string,
|
||||
/**
|
||||
* Usage message describing this flag.
|
||||
*/
|
||||
public readonly message?: string,
|
||||
/**
|
||||
* Description of the argument required by this flag.
|
||||
* If this is set, the flag will expect a positional argument to follow as a param.
|
||||
*/
|
||||
public readonly argumentDescription?: string
|
||||
) { super() }
|
||||
|
||||
/**
|
||||
* Get the referential name for this option.
|
||||
* Defaults to the long flag (without the '--'). If this cannot
|
||||
* be found, the short flag (without the '-') is used.
|
||||
* @returns {string}
|
||||
*/
|
||||
getArgumentName() {
|
||||
if ( this.longFlag ) {
|
||||
return this.longFlag.replace('--', '')
|
||||
} else if ( this.shortFlag ) {
|
||||
return this.shortFlag.replace('-', '')
|
||||
}
|
||||
|
||||
throw new Error('Missing either a long- or short-flag for FlagOption.')
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user