@moostjs/event-cli 0.2.9 → 0.2.10

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/dist/index.cjs CHANGED
@@ -98,6 +98,18 @@ class MoostCli {
98
98
  }
99
99
  }
100
100
 
101
+ const banner = () => `[${"@moostjs/event-cli"}][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
102
+
103
+ /* istanbul ignore file */
104
+ function logError(error) {
105
+ console.error('' + '' + banner() + error + '');
106
+ }
107
+
108
+ function panic(error) {
109
+ logError(error);
110
+ return new Error(error);
111
+ }
112
+
101
113
  /**
102
114
  * Get Cli Flag
103
115
  * @decorator
@@ -114,6 +126,25 @@ function Flag(name) {
114
126
  */
115
127
  function Flags() {
116
128
  return moost.Resolve(() => eventCli.useFlags(), 'flags');
129
+ }
130
+ function CliParam(keys, descr) {
131
+ return moost.Resolve(() => {
132
+ const flags = eventCli.useFlags();
133
+ const names = [keys].flat();
134
+ const vals = [];
135
+ for (const name of names) {
136
+ if (flags[name]) {
137
+ vals.push(flags[name]);
138
+ }
139
+ }
140
+ if (vals.length > 1) {
141
+ throw panic(`Options ${names.map(n => n.length === 1 ? '-' + n : '--' + n).join(' and ')} are synonyms. Please use only one of them.`);
142
+ }
143
+ if (vals.length === 0) {
144
+ return false;
145
+ }
146
+ return vals[0];
147
+ });
117
148
  }
118
149
 
119
150
  function Cli(path) {
@@ -121,6 +152,7 @@ function Cli(path) {
121
152
  }
122
153
 
123
154
  exports.Cli = Cli;
155
+ exports.CliParam = CliParam;
124
156
  exports.Flag = Flag;
125
157
  exports.Flags = Flags;
126
158
  exports.MoostCli = MoostCli;
package/dist/index.d.ts CHANGED
@@ -5,20 +5,22 @@ import { WooksCli } from '@wooksjs/event-cli';
5
5
 
6
6
  export declare function Cli(path?: string): MethodDecorator;
7
7
 
8
+ export declare function CliParam(keys: string | [string, string], descr: string): ParameterDecorator & PropertyDecorator;
9
+
8
10
  /**
9
11
  * Get Cli Flag
10
12
  * @decorator
11
13
  * @param name - flag name
12
14
  * @paramType string
13
15
  */
14
- export declare function Flag(name: string): ParameterDecorator;
16
+ export declare function Flag(name: string): ParameterDecorator & PropertyDecorator;
15
17
 
16
18
  /**
17
19
  * Get Cli Flags
18
20
  * @decorator
19
21
  * @paramType object
20
22
  */
21
- export declare function Flags(): ParameterDecorator;
23
+ export declare function Flags(): ParameterDecorator & PropertyDecorator;
22
24
 
23
25
  export declare class MoostCli implements TMoostAdapter<TCliHandlerMeta> {
24
26
  protected cliApp: WooksCli;
package/dist/index.mjs CHANGED
@@ -96,6 +96,18 @@ class MoostCli {
96
96
  }
97
97
  }
98
98
 
99
+ const banner = () => `[${"@moostjs/event-cli"}][${new Date().toISOString().replace('T', ' ').replace(/\.\d{3}z$/i, '')}] `;
100
+
101
+ /* istanbul ignore file */
102
+ function logError(error) {
103
+ console.error('' + '' + banner() + error + '');
104
+ }
105
+
106
+ function panic(error) {
107
+ logError(error);
108
+ return new Error(error);
109
+ }
110
+
99
111
  /**
100
112
  * Get Cli Flag
101
113
  * @decorator
@@ -112,10 +124,29 @@ function Flag(name) {
112
124
  */
113
125
  function Flags() {
114
126
  return Resolve(() => useFlags(), 'flags');
127
+ }
128
+ function CliParam(keys, descr) {
129
+ return Resolve(() => {
130
+ const flags = useFlags();
131
+ const names = [keys].flat();
132
+ const vals = [];
133
+ for (const name of names) {
134
+ if (flags[name]) {
135
+ vals.push(flags[name]);
136
+ }
137
+ }
138
+ if (vals.length > 1) {
139
+ throw panic(`Options ${names.map(n => n.length === 1 ? '-' + n : '--' + n).join(' and ')} are synonyms. Please use only one of them.`);
140
+ }
141
+ if (vals.length === 0) {
142
+ return false;
143
+ }
144
+ return vals[0];
145
+ });
115
146
  }
116
147
 
117
148
  function Cli(path) {
118
149
  return getMoostMate().decorate('handlers', { path, type: 'CLI' }, true);
119
150
  }
120
151
 
121
- export { Cli, Flag, Flags, MoostCli };
152
+ export { Cli, CliParam, Flag, Flags, MoostCli };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moostjs/event-cli",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "@moostjs/event-cli",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
@@ -28,11 +28,11 @@
28
28
  },
29
29
  "homepage": "https://github.com/moostjs/moostjs/tree/main/packages/event-cli#readme",
30
30
  "peerDependencies": {
31
- "moost": "0.2.9",
32
- "wooks": "^0.2.5",
33
- "@wooksjs/event-core": "^0.2.5"
31
+ "moost": "0.2.10",
32
+ "wooks": "^0.2.6",
33
+ "@wooksjs/event-core": "^0.2.6"
34
34
  },
35
35
  "dependencies": {
36
- "@wooksjs/event-cli": "^0.2.5"
36
+ "@wooksjs/event-cli": "^0.2.6"
37
37
  }
38
38
  }