This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
AbstractHelpGeneratorFactory.ts
142 lines (130 loc) · 4.89 KB
/
AbstractHelpGeneratorFactory.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright Contributors to the Zowe Project.
*
*/
import { AbstractHelpGenerator } from "./AbstractHelpGenerator";
import { IHelpGeneratorFactoryParms } from "../doc/IHelpGeneratorFactoryParms";
import { IHelpGeneratorFactory } from "../doc/IHelpGeneratorFactory";
import { isNullOrUndefined } from "util";
import { IHelpGeneratorParms } from "../doc/IHelpGeneratorParms";
import { IHelpGenerator } from "../doc/IHelpGenerator";
import { ImperativeExpect } from "../../../../expect";
/**
* The abstract help generator factory class - implemented normally by imperative to provide the help generator
* object that should be used for your CLI.
* @export
* @abstract
* @class AbstractHelpGeneratorFactory
*/
export abstract class AbstractHelpGeneratorFactory implements IHelpGeneratorFactory {
/**
* The root command name of your CLI
* @private
* @type {string}
* @memberof AbstractHelpGeneratorFactory
*/
private mRootCommandName: string;
/**
* The primary highlight color - for terminal/console coloring
* @private
* @type {string}
* @memberof AbstractHelpGeneratorFactory
*/
private mPrimaryHighlightColor: string;
/**
* True to produce markdown instead of the "normal" help text
* @private
* @type {boolean}
* @memberof AbstractHelpGeneratorFactory
*/
private mProduceMarkdown: boolean;
/**
* The input parameters to the factory.
* @private
* @type {IHelpGeneratorFactoryParms}
* @memberof AbstractHelpGeneratorFactory
*/
private mParms: IHelpGeneratorFactoryParms;
/**
* Creates an instance of AbstractHelpGeneratorFactory.
* @param {IHelpGeneratorFactoryParms} parms - Control parameters and inforamtion required to build help generators
* @memberof AbstractHelpGeneratorFactory
*/
constructor(parms: IHelpGeneratorFactoryParms) {
const err: string = "Help Generator Factory Creation Error:";
ImperativeExpect.toNotBeNullOrUndefined(parms, `${err} No input parameters were supplied.`);
ImperativeExpect.keysToBeDefined(parms, ["rootCommandName"], `${err} No root command name was supplied.`);
this.mParms = parms;
this.mRootCommandName = parms.rootCommandName;
// TODO - what is the default color for imperative?
this.mPrimaryHighlightColor = parms.primaryHighlightColor || "yellow";
this.mProduceMarkdown = isNullOrUndefined(parms.produceMarkdown) ? false : parms.produceMarkdown;
}
/**
* Verifies the input parameters and returns the help generator instance for the command.
* @param {IHelpGeneratorParms} parms - The input parameters - see interface for details.
* @returns {IHelpGenerator}
* @memberof AbstractHelpGeneratorFactory
*/
public getHelpGenerator(parms: IHelpGeneratorParms): IHelpGenerator {
const err: string = "Get Help Generator Parameter Error:";
ImperativeExpect.toNotBeNullOrUndefined(parms, `${err} No parameters were supplied.`);
ImperativeExpect.keysToBeDefined(parms, ["commandDefinition"], `${err} No command definition was supplied.`);
ImperativeExpect.keysToBeDefined(parms, ["fullCommandTree"], `${err} The full command tree was not supplied.`);
return this.getGenerator(parms);
}
/**
* Implement to return your specific help generator instance.
* @abstract
* @param {IHelpGeneratorParms} parms
* @returns {IHelpGenerator} - The help generator for the command.
* @memberof AbstractHelpGeneratorFactory
*/
protected abstract getGenerator(parms: IHelpGeneratorParms): IHelpGenerator;
/**
* Accessor of the root command nae.
* @readonly
* @protected
* @type {string}
* @memberof AbstractHelpGeneratorFactory
*/
protected get rootCommandName(): string {
return this.mRootCommandName;
}
/**
* Accessor for the primary highlight color
* @readonly
* @protected
* @type {string}
* @memberof AbstractHelpGeneratorFactory
*/
protected get primaryHighlightColor(): string {
return this.mPrimaryHighlightColor;
}
/**
* Accessor for the produce markdown flag
* @readonly
* @protected
* @type {boolean}
* @memberof AbstractHelpGeneratorFactory
*/
protected get produceMarkdown(): boolean {
return this.mProduceMarkdown;
}
/**
* Accessor for the full list of parameters
* @readonly
* @protected
* @type {IHelpGeneratorFactoryParms}
* @memberof AbstractHelpGeneratorFactory
*/
protected get factoryParameters(): IHelpGeneratorFactoryParms {
return this.mParms;
}
}