@nu-art/commando 0.204.95 → 0.204.97
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/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { Constructor } from '@nu-art/ts-common';
|
|
2
|
+
import { Constructor, LogLevel } from '@nu-art/ts-common';
|
|
3
3
|
import { LogTypes } from '../types';
|
|
4
4
|
import { BaseCommando } from '../core/BaseCommando';
|
|
5
5
|
export declare class CommandoInteractive extends BaseCommando {
|
|
@@ -68,6 +68,7 @@ export declare class CommandoInteractive extends BaseCommando {
|
|
|
68
68
|
* @returns {this} - The CommandoInteractive instance for method chaining.
|
|
69
69
|
*/
|
|
70
70
|
addLogProcessor(processor: (log: string, std: LogTypes) => boolean): this;
|
|
71
|
+
setLogLevelFilter(processor: (log: string, std: LogTypes) => LogLevel): this;
|
|
71
72
|
/**
|
|
72
73
|
* Removes a log processor from the shell.
|
|
73
74
|
* @param {Function} processor - The log processor function to remove.
|
|
@@ -71,14 +71,14 @@ class CommandoInteractive extends BaseCommando_1.BaseCommando {
|
|
|
71
71
|
*/
|
|
72
72
|
onLog(filter, callback) {
|
|
73
73
|
const regexp = typeof filter === 'string' ? new RegExp(filter) : filter;
|
|
74
|
-
const
|
|
74
|
+
const logFilter = (log) => {
|
|
75
75
|
const match = log.match(regexp);
|
|
76
76
|
if (!match)
|
|
77
77
|
return true;
|
|
78
78
|
callback(match);
|
|
79
79
|
return true;
|
|
80
80
|
};
|
|
81
|
-
this.addLogProcessor(
|
|
81
|
+
this.addLogProcessor(logFilter);
|
|
82
82
|
return this;
|
|
83
83
|
}
|
|
84
84
|
/**
|
|
@@ -154,6 +154,10 @@ class CommandoInteractive extends BaseCommando_1.BaseCommando {
|
|
|
154
154
|
this.shell.addLogProcessor(processor);
|
|
155
155
|
return this;
|
|
156
156
|
}
|
|
157
|
+
setLogLevelFilter(processor) {
|
|
158
|
+
this.shell.setLogLevelFilter(processor);
|
|
159
|
+
return this;
|
|
160
|
+
}
|
|
157
161
|
/**
|
|
158
162
|
* Removes a log processor from the shell.
|
|
159
163
|
* @param {Function} processor - The log processor function to remove.
|
|
@@ -4,13 +4,15 @@
|
|
|
4
4
|
/// <reference types="node" />
|
|
5
5
|
/// <reference types="node" />
|
|
6
6
|
/// <reference types="node" />
|
|
7
|
-
import { Logger } from '@nu-art/ts-common';
|
|
7
|
+
import { Logger, LogLevel } from '@nu-art/ts-common';
|
|
8
8
|
import { LogTypes } from '../types';
|
|
9
|
+
type LogProcessor = (log: string, std: LogTypes) => boolean;
|
|
9
10
|
export declare class InteractiveShell extends Logger {
|
|
10
11
|
private _debug;
|
|
11
12
|
private logProcessors;
|
|
12
13
|
private shell;
|
|
13
14
|
private alive;
|
|
15
|
+
private logLevelFilter;
|
|
14
16
|
/**
|
|
15
17
|
* Constructs an InteractiveShell instance, initializes a detached shell session, and sets up log processors.
|
|
16
18
|
*/
|
|
@@ -47,13 +49,14 @@ export declare class InteractiveShell extends Logger {
|
|
|
47
49
|
* @param {(log: string, std: LogTypes) => boolean} processor - The log processor function.
|
|
48
50
|
* @returns {this} - The InteractiveShell instance for method chaining.
|
|
49
51
|
*/
|
|
50
|
-
addLogProcessor(processor:
|
|
52
|
+
addLogProcessor(processor: LogProcessor): this;
|
|
53
|
+
setLogLevelFilter(logLevelFilter: (log: string, std: LogTypes) => LogLevel): this;
|
|
51
54
|
/**
|
|
52
55
|
* Removes a log processor from handling log messages.
|
|
53
56
|
* @param {(log: string, std: LogTypes) => boolean} processor - The log processor function to remove.
|
|
54
57
|
* @returns {this} - The InteractiveShell instance for method chaining.
|
|
55
58
|
*/
|
|
56
|
-
removeLogProcessor(processor:
|
|
59
|
+
removeLogProcessor(processor: LogProcessor): this;
|
|
57
60
|
/**
|
|
58
61
|
* Sets a unique identifier for the shell session.
|
|
59
62
|
* @param {string} uid - The unique identifier.
|
|
@@ -61,3 +64,4 @@ export declare class InteractiveShell extends Logger {
|
|
|
61
64
|
*/
|
|
62
65
|
setUID(uid: string): this;
|
|
63
66
|
}
|
|
67
|
+
export {};
|
|
@@ -12,6 +12,7 @@ class InteractiveShell extends ts_common_1.Logger {
|
|
|
12
12
|
super();
|
|
13
13
|
this._debug = false;
|
|
14
14
|
this.logProcessors = [];
|
|
15
|
+
this.logLevelFilter = (log, std) => std === 'err' ? ts_common_1.LogLevel.Error : ts_common_1.LogLevel.Info;
|
|
15
16
|
/**
|
|
16
17
|
* Executes a command in the interactive shell.
|
|
17
18
|
* @param {string} command - The command to execute.
|
|
@@ -85,8 +86,10 @@ class InteractiveShell extends ts_common_1.Logger {
|
|
|
85
86
|
const filter = processor(message, std);
|
|
86
87
|
return toPrint && filter;
|
|
87
88
|
}, true);
|
|
88
|
-
if (toPrint)
|
|
89
|
-
this.
|
|
89
|
+
if (toPrint) {
|
|
90
|
+
const logLevel = this.logLevelFilter(message, std);
|
|
91
|
+
this.log(logLevel, false, [message]);
|
|
92
|
+
}
|
|
90
93
|
}
|
|
91
94
|
catch (e) {
|
|
92
95
|
this.logError(e);
|
|
@@ -119,6 +122,10 @@ class InteractiveShell extends ts_common_1.Logger {
|
|
|
119
122
|
this.logProcessors.push(processor);
|
|
120
123
|
return this;
|
|
121
124
|
}
|
|
125
|
+
setLogLevelFilter(logLevelFilter) {
|
|
126
|
+
this.logLevelFilter = logLevelFilter;
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
122
129
|
/**
|
|
123
130
|
* Removes a log processor from handling log messages.
|
|
124
131
|
* @param {(log: string, std: LogTypes) => boolean} processor - The log processor function to remove.
|