@nu-art/commando 0.204.86 → 0.204.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/basic.d.ts +3 -2
- package/cli/basic.js +15 -15
- package/cli/git.d.ts +18 -17
- package/cli/git.js +43 -22
- package/cli/nvm.d.ts +4 -3
- package/cli/nvm.js +13 -10
- package/cli/pnpm.d.ts +1 -1
- package/cli/pnpm.js +8 -8
- package/cli/programming.d.ts +3 -2
- package/cli/programming.js +19 -19
- package/cli-params/CLIParamsResolver.d.ts +27 -0
- package/{cli/cli-params.js → cli-params/CLIParamsResolver.js} +6 -34
- package/cli-params/consts.d.ts +6 -0
- package/cli-params/consts.js +32 -0
- package/cli-params/types.d.ts +27 -0
- package/cli-params/types.js +2 -0
- package/package.json +1 -1
- package/shell/core/BaseCommando.d.ts +54 -0
- package/shell/core/BaseCommando.js +73 -0
- package/shell/core/CliError.d.ts +15 -0
- package/shell/core/CliError.js +22 -0
- package/shell/core/CommandBuilder.d.ts +52 -0
- package/shell/core/CommandBuilder.js +78 -0
- package/shell/core/class-merger.d.ts +20 -0
- package/{core → shell/core}/class-merger.js +16 -0
- package/shell/index.d.ts +2 -0
- package/shell/index.js +18 -0
- package/shell/interactive/CommandoInteractive.d.ts +83 -0
- package/shell/interactive/CommandoInteractive.js +180 -0
- package/shell/interactive/InteractiveShell.d.ts +63 -0
- package/shell/interactive/InteractiveShell.js +139 -0
- package/shell/simple/Commando.d.ts +17 -0
- package/shell/simple/Commando.js +51 -0
- package/shell/simple/SimpleShell.d.ts +23 -0
- package/shell/simple/SimpleShell.js +48 -0
- package/shell/types.d.ts +3 -0
- package/shell/types.js +2 -0
- package/cli/cli-params.d.ts +0 -56
- package/core/CliError.d.ts +0 -6
- package/core/CliError.js +0 -12
- package/core/class-merger.d.ts +0 -5
- package/core/cli.d.ts +0 -147
- package/core/cli.js +0 -404
- package/test-scripts/test-params.d.ts +0 -1
- package/test-scripts/test-params.js +0 -43
- /package/{core → shell}/tools.d.ts +0 -0
- /package/{core → shell}/tools.js +0 -0
package/core/cli.d.ts
DELETED
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
/// <reference types="node" />
|
|
3
|
-
/// <reference types="mocha" />
|
|
4
|
-
/// <reference types="node" />
|
|
5
|
-
/// <reference types="node" />
|
|
6
|
-
/// <reference types="node" />
|
|
7
|
-
/// <reference types="node" />
|
|
8
|
-
import { ExecOptions } from 'child_process';
|
|
9
|
-
import { AsyncVoidFunction, Constructor, Logger } from '@nu-art/ts-common';
|
|
10
|
-
export type CliBlock<Cli extends CliWrapper> = (cli: Cli) => void;
|
|
11
|
-
export type CliOptions = ExecOptions & {
|
|
12
|
-
encoding: BufferEncoding | string | null;
|
|
13
|
-
};
|
|
14
|
-
/**
|
|
15
|
-
* Type definition for options used in Cli class.
|
|
16
|
-
*/
|
|
17
|
-
type Options = {
|
|
18
|
-
newlineDelimiter: string;
|
|
19
|
-
indentation: number;
|
|
20
|
-
};
|
|
21
|
-
export declare class BaseCLI extends Logger {
|
|
22
|
-
protected stderrValidator: ((stdout: string) => boolean);
|
|
23
|
-
protected stdoutProcessors: ((stdout: string) => void)[];
|
|
24
|
-
protected stderrProcessors: ((stdout: string) => void)[];
|
|
25
|
-
protected commands: string[];
|
|
26
|
-
private indentation;
|
|
27
|
-
protected _debug: boolean;
|
|
28
|
-
protected option: Options;
|
|
29
|
-
protected uid: string;
|
|
30
|
-
/**
|
|
31
|
-
* Constructs a CLI instance with given options.
|
|
32
|
-
* @param {Options} options - Configuration options for the CLI instance.
|
|
33
|
-
*/
|
|
34
|
-
constructor(options?: Partial<Options>);
|
|
35
|
-
protected getIndentation: () => string;
|
|
36
|
-
readonly indentIn: () => void;
|
|
37
|
-
readonly indentOut: () => void;
|
|
38
|
-
debug(debug?: boolean): boolean;
|
|
39
|
-
/**
|
|
40
|
-
* Appends a command or a Cli instance to the command list with proper indentation.
|
|
41
|
-
* @param {string} command - The command or Cli instance to append.
|
|
42
|
-
* @returns {this} - The Cli instance for method chaining.
|
|
43
|
-
*/
|
|
44
|
-
readonly append: (command: string) => this;
|
|
45
|
-
setUID(uuid: string): void;
|
|
46
|
-
setStdErrorValidator(processor: (stderr: string) => boolean): void;
|
|
47
|
-
addStdoutProcessor(processor: (stdout: string) => void): void;
|
|
48
|
-
addStderrProcessor(processor: (stderr: string) => void): void;
|
|
49
|
-
removeStdoutProcessor(processor: (stdout: string) => void): void;
|
|
50
|
-
removeStderrProcessor(processor: (stderr: string) => void): void;
|
|
51
|
-
}
|
|
52
|
-
export declare class CliInteractive extends BaseCLI {
|
|
53
|
-
private shell;
|
|
54
|
-
private alive;
|
|
55
|
-
constructor();
|
|
56
|
-
execute: () => Promise<void>;
|
|
57
|
-
endInteractive: (cb?: AsyncVoidFunction) => void;
|
|
58
|
-
kill: (signal?: NodeJS.Signals | number) => boolean;
|
|
59
|
-
gracefullyKill: (pid?: number) => Promise<void>;
|
|
60
|
-
}
|
|
61
|
-
export declare class Cli extends BaseCLI {
|
|
62
|
-
private cliOptions;
|
|
63
|
-
/**
|
|
64
|
-
* Executes the accumulated commands in the command list.
|
|
65
|
-
* @returns {Promise<string>} A promise that resolves with the standard output of the executed command.
|
|
66
|
-
*/
|
|
67
|
-
execute: () => Promise<{
|
|
68
|
-
stdout: string;
|
|
69
|
-
stderr: string;
|
|
70
|
-
}>;
|
|
71
|
-
/**
|
|
72
|
-
* Appends an empty line to the script for readability.
|
|
73
|
-
* @returns {this} - The Cli instance for method chaining.
|
|
74
|
-
*/
|
|
75
|
-
emptyLine(): this;
|
|
76
|
-
setShell(shell: string): void;
|
|
77
|
-
setOptions(options: Partial<CliOptions>): void;
|
|
78
|
-
}
|
|
79
|
-
export declare class CliWrapper {
|
|
80
|
-
cli: Cli;
|
|
81
|
-
}
|
|
82
|
-
export declare class Commando {
|
|
83
|
-
cli: Cli;
|
|
84
|
-
static create<T extends Constructor<CliWrapper>[]>(...plugins: T): Commando & import("./class-merger").MergeTypes<T>;
|
|
85
|
-
setShell: (shell: string) => this;
|
|
86
|
-
setOptions: (options: ExecOptions) => this;
|
|
87
|
-
debug: (debug?: boolean) => this;
|
|
88
|
-
append: (command: string) => this;
|
|
89
|
-
setUID: (uid: string) => this;
|
|
90
|
-
execute: () => Promise<{
|
|
91
|
-
stdout: string;
|
|
92
|
-
stderr: string;
|
|
93
|
-
}>;
|
|
94
|
-
/**
|
|
95
|
-
* Executes a given file.
|
|
96
|
-
* @param {string} filePath - The path to the file to execute.
|
|
97
|
-
* @param {string} [interpreter] - Optional. The interpreter to use for executing the file (e.g., "python", "bash").
|
|
98
|
-
* If not provided, the file is executed directly.
|
|
99
|
-
*
|
|
100
|
-
* @returns {Cli} - The script execution output.
|
|
101
|
-
*/
|
|
102
|
-
executeFile: (filePath: string, interpreter?: string) => Promise<{
|
|
103
|
-
stdout: string;
|
|
104
|
-
stderr: string;
|
|
105
|
-
}>;
|
|
106
|
-
executeRemoteFile: (pathToFile: string, interpreter: string) => Promise<{
|
|
107
|
-
stdout: string;
|
|
108
|
-
stderr: string;
|
|
109
|
-
}>;
|
|
110
|
-
addStdoutProcessor: (processor: (stdout: string) => void) => this;
|
|
111
|
-
addStderrProcessor: (processor: (stderr: string) => void) => this;
|
|
112
|
-
removeStdoutProcessor: (processor: (stdout: string) => void) => this;
|
|
113
|
-
removeStderrProcessor: (processor: (stderr: string) => void) => this;
|
|
114
|
-
setStdErrorValidator: (processor: (stderr: string) => boolean) => this;
|
|
115
|
-
private constructor();
|
|
116
|
-
}
|
|
117
|
-
export declare class CommandoInteractive {
|
|
118
|
-
cli: CliInteractive;
|
|
119
|
-
static create<T extends Constructor<CliWrapper>[]>(...plugins: T): CommandoInteractive & Commando & import("./class-merger").MergeTypes<T>;
|
|
120
|
-
addStdoutProcessor: (processor: (stdout: string) => void) => this;
|
|
121
|
-
addStderrProcessor: (processor: (stderr: string) => void) => this;
|
|
122
|
-
removeStdoutProcessor: (processor: (stdout: string) => void) => this;
|
|
123
|
-
removeStderrProcessor: (processor: (stderr: string) => void) => this;
|
|
124
|
-
setStdErrorValidator: (processor: (stderr: string) => boolean) => this;
|
|
125
|
-
setUID: (uid: string) => this;
|
|
126
|
-
close: (cb?: AsyncVoidFunction) => this;
|
|
127
|
-
kill: (signal?: NodeJS.Signals | number) => boolean;
|
|
128
|
-
gracefullyKill: (pid?: number) => Promise<void>;
|
|
129
|
-
}
|
|
130
|
-
type CommandoCLIListener_Callback = (stdout: string) => void;
|
|
131
|
-
export declare class CommandoCLIListener {
|
|
132
|
-
private cb;
|
|
133
|
-
protected filter?: RegExp;
|
|
134
|
-
constructor(callback: CommandoCLIListener_Callback, filter?: string | RegExp);
|
|
135
|
-
private _process;
|
|
136
|
-
private stdoutPassesFilter;
|
|
137
|
-
listen: <T extends Commando | CommandoInteractive>(commando: T) => T;
|
|
138
|
-
protected process(stdout: string): void;
|
|
139
|
-
}
|
|
140
|
-
export declare class CommandoCLIKeyValueListener extends CommandoCLIListener {
|
|
141
|
-
private value;
|
|
142
|
-
constructor(pattern: string | RegExp);
|
|
143
|
-
private setValue;
|
|
144
|
-
protected process(stdout: string): void;
|
|
145
|
-
getValue: () => string | undefined;
|
|
146
|
-
}
|
|
147
|
-
export {};
|
package/core/cli.js
DELETED
|
@@ -1,404 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandoCLIKeyValueListener = exports.CommandoCLIListener = exports.CommandoInteractive = exports.Commando = exports.CliWrapper = exports.Cli = exports.CliInteractive = exports.BaseCLI = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
const class_merger_1 = require("./class-merger");
|
|
6
|
-
const CliError_1 = require("./CliError");
|
|
7
|
-
const ts_common_1 = require("@nu-art/ts-common");
|
|
8
|
-
const node_child_process_1 = require("node:child_process");
|
|
9
|
-
/**
|
|
10
|
-
* Default options for Cli class instances.
|
|
11
|
-
*/
|
|
12
|
-
const defaultOptions = {
|
|
13
|
-
newlineDelimiter: '\n',
|
|
14
|
-
indentation: 2,
|
|
15
|
-
};
|
|
16
|
-
class BaseCLI extends ts_common_1.Logger {
|
|
17
|
-
/**
|
|
18
|
-
* Constructs a CLI instance with given options.
|
|
19
|
-
* @param {Options} options - Configuration options for the CLI instance.
|
|
20
|
-
*/
|
|
21
|
-
constructor(options = defaultOptions) {
|
|
22
|
-
super();
|
|
23
|
-
this.stderrValidator = () => true;
|
|
24
|
-
this.stdoutProcessors = [];
|
|
25
|
-
this.stderrProcessors = [];
|
|
26
|
-
this.commands = [];
|
|
27
|
-
this.indentation = 0;
|
|
28
|
-
this._debug = true;
|
|
29
|
-
this.uid = (0, ts_common_1.generateHex)((8));
|
|
30
|
-
this.getIndentation = () => {
|
|
31
|
-
return ' '.repeat(this.option.indentation * this.indentation);
|
|
32
|
-
};
|
|
33
|
-
this.indentIn = () => {
|
|
34
|
-
this.indentation++;
|
|
35
|
-
};
|
|
36
|
-
this.indentOut = () => {
|
|
37
|
-
this.indentation++;
|
|
38
|
-
};
|
|
39
|
-
/**
|
|
40
|
-
* Appends a command or a Cli instance to the command list with proper indentation.
|
|
41
|
-
* @param {string} command - The command or Cli instance to append.
|
|
42
|
-
* @returns {this} - The Cli instance for method chaining.
|
|
43
|
-
*/
|
|
44
|
-
this.append = (command) => {
|
|
45
|
-
this.commands.push(`${this.getIndentation()}${command}`);
|
|
46
|
-
return this;
|
|
47
|
-
};
|
|
48
|
-
this.setMinLevel(ts_common_1.LogLevel.Verbose);
|
|
49
|
-
this.option = options;
|
|
50
|
-
}
|
|
51
|
-
debug(debug) {
|
|
52
|
-
this._debug = debug !== null && debug !== void 0 ? debug : !this._debug;
|
|
53
|
-
return this._debug;
|
|
54
|
-
}
|
|
55
|
-
setUID(uuid) {
|
|
56
|
-
this.setTag(uuid);
|
|
57
|
-
}
|
|
58
|
-
setStdErrorValidator(processor) {
|
|
59
|
-
this.stderrValidator = processor;
|
|
60
|
-
}
|
|
61
|
-
addStdoutProcessor(processor) {
|
|
62
|
-
this.stdoutProcessors.push(processor);
|
|
63
|
-
}
|
|
64
|
-
addStderrProcessor(processor) {
|
|
65
|
-
this.stderrProcessors.push(processor);
|
|
66
|
-
}
|
|
67
|
-
removeStdoutProcessor(processor) {
|
|
68
|
-
(0, ts_common_1.removeItemFromArray)(this.stdoutProcessors, processor);
|
|
69
|
-
}
|
|
70
|
-
removeStderrProcessor(processor) {
|
|
71
|
-
(0, ts_common_1.removeItemFromArray)(this.stderrProcessors, processor);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.BaseCLI = BaseCLI;
|
|
75
|
-
class CliInteractive extends BaseCLI {
|
|
76
|
-
constructor() {
|
|
77
|
-
var _a, _b;
|
|
78
|
-
super();
|
|
79
|
-
this.execute = async () => {
|
|
80
|
-
var _a;
|
|
81
|
-
const command = this.commands.join(this.option.newlineDelimiter);
|
|
82
|
-
if (this._debug)
|
|
83
|
-
this.logDebug(`executing: `, `"""\n${command}\n"""`);
|
|
84
|
-
(_a = this.shell.stdin) === null || _a === void 0 ? void 0 : _a.write(command + this.option.newlineDelimiter, 'utf-8', (err) => {
|
|
85
|
-
if (err)
|
|
86
|
-
this.logError(`error`, err);
|
|
87
|
-
});
|
|
88
|
-
this.commands = [];
|
|
89
|
-
};
|
|
90
|
-
this.endInteractive = (cb) => {
|
|
91
|
-
var _a;
|
|
92
|
-
(_a = this.shell.stdin) === null || _a === void 0 ? void 0 : _a.end(cb);
|
|
93
|
-
};
|
|
94
|
-
this.kill = (signal) => {
|
|
95
|
-
return this.shell.kill(signal);
|
|
96
|
-
};
|
|
97
|
-
this.gracefullyKill = async (pid) => {
|
|
98
|
-
// if the shell is already dead no need to wait for kill
|
|
99
|
-
if (!this.alive)
|
|
100
|
-
return;
|
|
101
|
-
return new Promise((resolve, reject) => {
|
|
102
|
-
this.shell.on('exit', async (code, signal) => {
|
|
103
|
-
this.alive = false;
|
|
104
|
-
resolve();
|
|
105
|
-
});
|
|
106
|
-
if (pid) {
|
|
107
|
-
process.kill(pid, 'SIGINT');
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
this.shell.kill('SIGINT');
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
this.shell = (0, node_child_process_1.spawn)('/bin/bash', {
|
|
115
|
-
detached: true,
|
|
116
|
-
shell: true
|
|
117
|
-
});
|
|
118
|
-
//set alive
|
|
119
|
-
this.alive = true;
|
|
120
|
-
// Handle shell output (stdout)
|
|
121
|
-
const printer = (data) => {
|
|
122
|
-
const message = data.toString().trim();
|
|
123
|
-
if (!message.length)
|
|
124
|
-
return;
|
|
125
|
-
try {
|
|
126
|
-
if (!this.stderrValidator(message))
|
|
127
|
-
this.stdoutProcessors.forEach(processor => processor(message));
|
|
128
|
-
else
|
|
129
|
-
this.stderrProcessors.forEach(processor => processor(message));
|
|
130
|
-
this.logInfo(`${message}`);
|
|
131
|
-
}
|
|
132
|
-
catch (e) {
|
|
133
|
-
this.logError(e);
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
(_a = this.shell.stdout) === null || _a === void 0 ? void 0 : _a.on('data', printer);
|
|
137
|
-
(_b = this.shell.stderr) === null || _b === void 0 ? void 0 : _b.on('data', printer);
|
|
138
|
-
// Handle shell errors (stderr)
|
|
139
|
-
this.shell.on('data', printer);
|
|
140
|
-
// Handle shell exit
|
|
141
|
-
this.shell.on('close', (code) => {
|
|
142
|
-
this.alive = false;
|
|
143
|
-
this.logInfo(`child process exited with code ${code}`);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
exports.CliInteractive = CliInteractive;
|
|
148
|
-
class Cli extends BaseCLI {
|
|
149
|
-
constructor() {
|
|
150
|
-
super(...arguments);
|
|
151
|
-
this.cliOptions = { shell: '/bin/bash' };
|
|
152
|
-
/**
|
|
153
|
-
* Executes the accumulated commands in the command list.
|
|
154
|
-
* @returns {Promise<string>} A promise that resolves with the standard output of the executed command.
|
|
155
|
-
*/
|
|
156
|
-
this.execute = async () => {
|
|
157
|
-
const command = this.commands.join(this.option.newlineDelimiter);
|
|
158
|
-
if (this._debug)
|
|
159
|
-
this.logDebug(`executing: `, `"""\n${command}\n"""`);
|
|
160
|
-
return new Promise((resolve, reject) => {
|
|
161
|
-
(0, child_process_1.exec)(command, this.cliOptions, (error, stdout, stderr) => {
|
|
162
|
-
this.commands = [];
|
|
163
|
-
if (error) {
|
|
164
|
-
reject(new CliError_1.CliError(`executing:\n${command}\n`, stdout, stderr, error));
|
|
165
|
-
}
|
|
166
|
-
const errorLogs = stderr.split('\n');
|
|
167
|
-
const { filteredIn, filteredOut } = (0, ts_common_1.filterInOut)(errorLogs, this.stderrValidator);
|
|
168
|
-
stderr = filteredIn.join('\n').trim();
|
|
169
|
-
if (stderr && stderr.length > 0)
|
|
170
|
-
reject(stderr);
|
|
171
|
-
const stdErrToOut = filteredOut.join('\n').trim();
|
|
172
|
-
if (stdErrToOut && stdErrToOut.length > 0)
|
|
173
|
-
stdout += `from stderr: \n${stdErrToOut}`;
|
|
174
|
-
if (stdout) {
|
|
175
|
-
this.stdoutProcessors.forEach(processor => processor(stdout));
|
|
176
|
-
this.logInfo(stdout);
|
|
177
|
-
}
|
|
178
|
-
if (stderr) {
|
|
179
|
-
this.stderrProcessors.forEach(processor => processor(stdout));
|
|
180
|
-
this.logError(stderr);
|
|
181
|
-
}
|
|
182
|
-
resolve({ stdout, stderr });
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
/**
|
|
188
|
-
* Appends an empty line to the script for readability.
|
|
189
|
-
* @returns {this} - The Cli instance for method chaining.
|
|
190
|
-
*/
|
|
191
|
-
emptyLine() {
|
|
192
|
-
this.append('');
|
|
193
|
-
return this;
|
|
194
|
-
}
|
|
195
|
-
setShell(shell) {
|
|
196
|
-
(this.cliOptions || (this.cliOptions = {})).shell = shell;
|
|
197
|
-
}
|
|
198
|
-
setOptions(options) {
|
|
199
|
-
this.cliOptions = options;
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
exports.Cli = Cli;
|
|
203
|
-
class CliWrapper {
|
|
204
|
-
}
|
|
205
|
-
exports.CliWrapper = CliWrapper;
|
|
206
|
-
class Commando {
|
|
207
|
-
static create(...plugins) {
|
|
208
|
-
const _commando = (0, class_merger_1.CreateMergedInstance)(...plugins);
|
|
209
|
-
const commando = _commando;
|
|
210
|
-
const cli = new Cli();
|
|
211
|
-
cli.setMinLevel(ts_common_1.LogLevel.Verbose);
|
|
212
|
-
commando.cli = cli;
|
|
213
|
-
commando.execute = () => commando.cli.execute();
|
|
214
|
-
commando.debug = (debug) => {
|
|
215
|
-
commando.cli.debug(debug);
|
|
216
|
-
return commando;
|
|
217
|
-
};
|
|
218
|
-
commando.setOptions = (options) => {
|
|
219
|
-
commando.cli.setOptions(options);
|
|
220
|
-
return commando;
|
|
221
|
-
};
|
|
222
|
-
commando.setShell = (shell) => {
|
|
223
|
-
commando.cli.setShell(shell);
|
|
224
|
-
return commando;
|
|
225
|
-
};
|
|
226
|
-
commando.executeFile = (filePath, interpreter) => {
|
|
227
|
-
let command = filePath;
|
|
228
|
-
// If an interpreter is provided, prefix the command with it.
|
|
229
|
-
if (interpreter) {
|
|
230
|
-
command = `${interpreter} ${filePath}`;
|
|
231
|
-
}
|
|
232
|
-
return new Cli().append(command).execute();
|
|
233
|
-
};
|
|
234
|
-
commando.executeRemoteFile = (pathToFile, interpreter) => {
|
|
235
|
-
return new Cli().append(`curl -o- "${pathToFile}" | ${interpreter}`).execute();
|
|
236
|
-
};
|
|
237
|
-
commando.append = (command) => {
|
|
238
|
-
commando.cli.append(command);
|
|
239
|
-
return commando;
|
|
240
|
-
};
|
|
241
|
-
commando.setUID = (uid) => {
|
|
242
|
-
commando.cli.setUID(uid);
|
|
243
|
-
return commando;
|
|
244
|
-
};
|
|
245
|
-
commando.addStdoutProcessor = (processor) => {
|
|
246
|
-
cli.addStdoutProcessor(processor);
|
|
247
|
-
return commando;
|
|
248
|
-
};
|
|
249
|
-
commando.addStderrProcessor = (processor) => {
|
|
250
|
-
cli.addStderrProcessor(processor);
|
|
251
|
-
return commando;
|
|
252
|
-
};
|
|
253
|
-
commando.removeStdoutProcessor = (processor) => {
|
|
254
|
-
cli.removeStdoutProcessor(processor);
|
|
255
|
-
return commando;
|
|
256
|
-
};
|
|
257
|
-
commando.removeStderrProcessor = (processor) => {
|
|
258
|
-
cli.removeStderrProcessor(processor);
|
|
259
|
-
return commando;
|
|
260
|
-
};
|
|
261
|
-
commando.setStdErrorValidator = (processor) => {
|
|
262
|
-
cli.setStdErrorValidator(processor);
|
|
263
|
-
return commando;
|
|
264
|
-
};
|
|
265
|
-
return commando;
|
|
266
|
-
}
|
|
267
|
-
constructor() {
|
|
268
|
-
this.setShell = (shell) => this;
|
|
269
|
-
this.setOptions = (options) => this;
|
|
270
|
-
this.debug = (debug) => this;
|
|
271
|
-
this.append = (command) => this;
|
|
272
|
-
this.setUID = (uid) => this;
|
|
273
|
-
this.execute = async () => ({ stdout: '', stderr: '', }); // placeholder
|
|
274
|
-
/**
|
|
275
|
-
* Executes a given file.
|
|
276
|
-
* @param {string} filePath - The path to the file to execute.
|
|
277
|
-
* @param {string} [interpreter] - Optional. The interpreter to use for executing the file (e.g., "python", "bash").
|
|
278
|
-
* If not provided, the file is executed directly.
|
|
279
|
-
*
|
|
280
|
-
* @returns {Cli} - The script execution output.
|
|
281
|
-
*/
|
|
282
|
-
this.executeFile = async (filePath, interpreter) => ({ stdout: '', stderr: '', });
|
|
283
|
-
this.executeRemoteFile = async (pathToFile, interpreter) => ({ stdout: '', stderr: '', });
|
|
284
|
-
this.addStdoutProcessor = (processor) => this;
|
|
285
|
-
this.addStderrProcessor = (processor) => this;
|
|
286
|
-
this.removeStdoutProcessor = (processor) => this;
|
|
287
|
-
this.removeStderrProcessor = (processor) => this;
|
|
288
|
-
this.setStdErrorValidator = (processor) => this;
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
exports.Commando = Commando;
|
|
292
|
-
class CommandoInteractive {
|
|
293
|
-
constructor() {
|
|
294
|
-
this.addStdoutProcessor = (processor) => this;
|
|
295
|
-
this.addStderrProcessor = (processor) => this;
|
|
296
|
-
this.removeStdoutProcessor = (processor) => this;
|
|
297
|
-
this.removeStderrProcessor = (processor) => this;
|
|
298
|
-
this.setStdErrorValidator = (processor) => this;
|
|
299
|
-
this.setUID = (uid) => this;
|
|
300
|
-
this.close = (cb) => this;
|
|
301
|
-
this.kill = (signal) => true;
|
|
302
|
-
this.gracefullyKill = (pid) => {
|
|
303
|
-
return new Promise(resolve => resolve());
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
static create(...plugins) {
|
|
307
|
-
const _commando = Commando.create(...plugins);
|
|
308
|
-
const commando = _commando;
|
|
309
|
-
const cli = new CliInteractive();
|
|
310
|
-
cli.setMinLevel(ts_common_1.LogLevel.Verbose);
|
|
311
|
-
commando.cli = cli;
|
|
312
|
-
commando.setUID = (uid) => {
|
|
313
|
-
commando.cli.setUID(uid);
|
|
314
|
-
return commando;
|
|
315
|
-
};
|
|
316
|
-
commando.close = (cb) => {
|
|
317
|
-
commando.cli.endInteractive(cb);
|
|
318
|
-
return commando;
|
|
319
|
-
};
|
|
320
|
-
commando.kill = (signal) => {
|
|
321
|
-
return commando.cli.kill(signal);
|
|
322
|
-
};
|
|
323
|
-
commando.gracefullyKill = async (pid) => {
|
|
324
|
-
await commando.cli.gracefullyKill(pid);
|
|
325
|
-
};
|
|
326
|
-
commando.addStdoutProcessor = (processor) => {
|
|
327
|
-
cli.addStdoutProcessor(processor);
|
|
328
|
-
return commando;
|
|
329
|
-
};
|
|
330
|
-
commando.addStderrProcessor = (processor) => {
|
|
331
|
-
cli.addStderrProcessor(processor);
|
|
332
|
-
return commando;
|
|
333
|
-
};
|
|
334
|
-
commando.removeStdoutProcessor = (processor) => {
|
|
335
|
-
cli.removeStdoutProcessor(processor);
|
|
336
|
-
return commando;
|
|
337
|
-
};
|
|
338
|
-
commando.removeStderrProcessor = (processor) => {
|
|
339
|
-
cli.removeStderrProcessor(processor);
|
|
340
|
-
return commando;
|
|
341
|
-
};
|
|
342
|
-
commando.setStdErrorValidator = (processor) => {
|
|
343
|
-
cli.setStdErrorValidator(processor);
|
|
344
|
-
return commando;
|
|
345
|
-
};
|
|
346
|
-
return commando;
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
exports.CommandoInteractive = CommandoInteractive;
|
|
350
|
-
class CommandoCLIListener {
|
|
351
|
-
constructor(callback, filter) {
|
|
352
|
-
this.stdoutPassesFilter = (stdout) => {
|
|
353
|
-
if (!this.filter)
|
|
354
|
-
return true;
|
|
355
|
-
return this.filter.test(stdout);
|
|
356
|
-
};
|
|
357
|
-
//######################### Functions #########################
|
|
358
|
-
this.listen = (commando) => {
|
|
359
|
-
const process = this._process.bind(this);
|
|
360
|
-
commando.addStdoutProcessor(process);
|
|
361
|
-
commando.addStderrProcessor(process);
|
|
362
|
-
return commando;
|
|
363
|
-
};
|
|
364
|
-
this.cb = callback;
|
|
365
|
-
if (!filter)
|
|
366
|
-
return;
|
|
367
|
-
if (typeof filter === 'string')
|
|
368
|
-
this.filter = new RegExp(filter);
|
|
369
|
-
else
|
|
370
|
-
this.filter = filter;
|
|
371
|
-
}
|
|
372
|
-
//######################### Inner Logic #########################
|
|
373
|
-
_process(stdout) {
|
|
374
|
-
if (!this.stdoutPassesFilter(stdout))
|
|
375
|
-
return;
|
|
376
|
-
this.process(stdout);
|
|
377
|
-
}
|
|
378
|
-
process(stdout) {
|
|
379
|
-
this.cb(stdout);
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
exports.CommandoCLIListener = CommandoCLIListener;
|
|
383
|
-
class CommandoCLIKeyValueListener extends CommandoCLIListener {
|
|
384
|
-
constructor(pattern) {
|
|
385
|
-
const filter = typeof pattern === 'string' ? new RegExp(pattern) : pattern;
|
|
386
|
-
super(ts_common_1.voidFunction, filter);
|
|
387
|
-
//######################### Inner Logic #########################
|
|
388
|
-
this.setValue = (value) => {
|
|
389
|
-
this.value = value;
|
|
390
|
-
};
|
|
391
|
-
this.getValue = () => this.value;
|
|
392
|
-
}
|
|
393
|
-
//######################### Functions #########################
|
|
394
|
-
process(stdout) {
|
|
395
|
-
var _a;
|
|
396
|
-
const pattern = this.filter;
|
|
397
|
-
if (!pattern)
|
|
398
|
-
throw new ts_common_1.ThisShouldNotHappenException('Class does not have a pattern, but it should have been initialized with one');
|
|
399
|
-
const value = (_a = stdout.match(pattern)) === null || _a === void 0 ? void 0 : _a[1];
|
|
400
|
-
if (value)
|
|
401
|
-
this.setValue(value);
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
exports.CommandoCLIKeyValueListener = CommandoCLIKeyValueListener;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const cli_params_1 = require("../cli/cli-params");
|
|
4
|
-
const testParam1 = {
|
|
5
|
-
keys: ['--test1', '-t1'],
|
|
6
|
-
keyName: 'test1',
|
|
7
|
-
type: 'string',
|
|
8
|
-
description: '',
|
|
9
|
-
defaultValue: 'psulet'
|
|
10
|
-
};
|
|
11
|
-
const testParam2 = {
|
|
12
|
-
keys: ['--test2'],
|
|
13
|
-
keyName: 'test2',
|
|
14
|
-
type: 'string[]',
|
|
15
|
-
description: ''
|
|
16
|
-
};
|
|
17
|
-
const testParam3 = {
|
|
18
|
-
keys: ['--test3'],
|
|
19
|
-
keyName: 'test3',
|
|
20
|
-
type: 'number',
|
|
21
|
-
description: ''
|
|
22
|
-
};
|
|
23
|
-
const testParam4 = {
|
|
24
|
-
keys: ['--test4'],
|
|
25
|
-
keyName: 'test4',
|
|
26
|
-
type: 'number[]',
|
|
27
|
-
description: ''
|
|
28
|
-
};
|
|
29
|
-
const testParam5 = {
|
|
30
|
-
keys: ['--test5'],
|
|
31
|
-
keyName: 'test5',
|
|
32
|
-
type: 'boolean',
|
|
33
|
-
description: ''
|
|
34
|
-
};
|
|
35
|
-
const testParam6 = {
|
|
36
|
-
keys: ['--test6'],
|
|
37
|
-
keyName: 'test6',
|
|
38
|
-
type: 'boolean[]',
|
|
39
|
-
description: ''
|
|
40
|
-
};
|
|
41
|
-
const params = [testParam1, testParam2, testParam3, testParam4, testParam5, testParam6];
|
|
42
|
-
const MyAppParamResolver = new cli_params_1.CLIParams_Resolver(params);
|
|
43
|
-
console.log(MyAppParamResolver.resolveParamValue());
|
|
File without changes
|
/package/{core → shell}/tools.js
RENAMED
|
File without changes
|