@cyklang/cli 0.8.3 → 0.9.1

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.
@@ -16,7 +16,9 @@ class CronCommand extends commander_1.Command {
16
16
  .addCommand(new CronList('list'))
17
17
  .addCommand(new CronList('l'))
18
18
  .addCommand(new CronAddCmd('add'))
19
- .addCommand(new CronAddCmd('a'));
19
+ .addCommand(new CronAddCmd('a'))
20
+ .addCommand(new CronDeleteCmd('delete'))
21
+ .addCommand(new CronDeleteCmd('d'));
20
22
  }
21
23
  }
22
24
  exports.CronCommand = CronCommand;
@@ -25,8 +27,19 @@ class CronList extends Cmd_1.Cmd {
25
27
  super(name);
26
28
  this.description('List scheduled batches')
27
29
  .action(async (options) => {
30
+ await this.commandList(options);
28
31
  });
29
32
  }
33
+ async commandList(options) {
34
+ try {
35
+ await this.prologue(options);
36
+ const json = await this.dbRemote?.apiServer.get('/api/admin/cron');
37
+ console.log(JSON.stringify(json));
38
+ }
39
+ catch (err) {
40
+ logger.error(err);
41
+ }
42
+ }
30
43
  }
31
44
  class CronAddCmd extends Cmd_1.Cmd {
32
45
  constructor(name) {
@@ -35,9 +48,69 @@ class CronAddCmd extends Cmd_1.Cmd {
35
48
  .option('-s --schedule <schedule>', 'schedule in crontab format')
36
49
  .option('-m --module <module_name>', 'module name')
37
50
  .option('-f --function <function>', 'function called in the module')
38
- .option('-p --param <parameter_name_value>', 'name and value separated by = character')
51
+ .option('-p --params <name_value_pairs>', 'URL encoded form without ? (question mark) ie "p1=val1&p2=val2"')
52
+ .action(async (options) => {
53
+ await this.commandAdd(options);
54
+ });
55
+ }
56
+ /**
57
+ *
58
+ * @param options
59
+ */
60
+ async commandAdd(options) {
61
+ try {
62
+ await this.prologue(options);
63
+ if (!this.dbRemote)
64
+ throw 'dbRemote undefined';
65
+ const payload = {
66
+ schedule: options.schedule,
67
+ module: options.module,
68
+ function: options.function,
69
+ params: options.params
70
+ };
71
+ const response = await this.dbRemote.apiServer.post('/api/admin/cron', payload);
72
+ logger.debug(response);
73
+ }
74
+ catch (err) {
75
+ logger.error(err);
76
+ }
77
+ }
78
+ }
79
+ class CronDeleteCmd extends Cmd_1.Cmd {
80
+ constructor(name) {
81
+ super(name);
82
+ this.description('delete a batch scheduling with cron')
83
+ .option('-i --id <cron_id>', 'id of the cron to delete (mandatory)')
84
+ .option('-s --schedule <schedule>', 'schedule in crontab format')
85
+ .option('-m --module <module_name>', 'module name')
86
+ .option('-f --function <function>', 'function called in the module')
87
+ .option('-p --params <name_value_pairs>', 'URL encoded form without ? (question mark) ie "p1=val1&p2=val2"')
39
88
  .action(async (options) => {
40
- console.log('options', options);
89
+ await this.commandDelete(options);
41
90
  });
42
91
  }
92
+ /**
93
+ *
94
+ * @param options
95
+ */
96
+ async commandDelete(options) {
97
+ try {
98
+ await this.prologue(options);
99
+ if (!this.dbRemote)
100
+ throw 'dbRemote undefined';
101
+ if (!options.id)
102
+ throw 'id is missing';
103
+ const payload = {
104
+ schedule: options.schedule,
105
+ module: options.module,
106
+ function: options.function,
107
+ params: options.params
108
+ };
109
+ const response = await this.dbRemote.apiServer.delete(`/api/admin/cron/${options.id}`, payload);
110
+ logger.debug(response);
111
+ }
112
+ catch (err) {
113
+ logger.error(err);
114
+ }
115
+ }
43
116
  }
package/build/index.js CHANGED
@@ -182,7 +182,7 @@ class StopCommand extends commander_1.Command {
182
182
  */
183
183
  const program = new commander_1.Command();
184
184
  program.name('cyk').description('cyklang CLI')
185
- .version('0.8.3');
185
+ .version('0.9.1');
186
186
  program.addCommand(new StartCommand('start'));
187
187
  program.addCommand(new StopCommand('stop'));
188
188
  program.addCommand(new InstallCommand_1.InstallCommand('install'));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cyklang/cli",
3
- "version": "0.8.3",
3
+ "version": "0.9.1",
4
4
  "description": "cyklang CLI",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -12,6 +12,8 @@ export class CronCommand extends Command {
12
12
  .addCommand(new CronList('l'))
13
13
  .addCommand(new CronAddCmd('add'))
14
14
  .addCommand(new CronAddCmd('a'))
15
+ .addCommand(new CronDeleteCmd('delete'))
16
+ .addCommand(new CronDeleteCmd('d'))
15
17
  }
16
18
  }
17
19
 
@@ -20,9 +22,21 @@ class CronList extends Cmd {
20
22
  super(name)
21
23
  this.description('List scheduled batches')
22
24
  .action(async (options: any) => {
23
-
25
+ await this.commandList(options)
24
26
  })
25
27
  }
28
+
29
+ async commandList(options: any) {
30
+ try {
31
+ await this.prologue(options)
32
+
33
+ const json = await this.dbRemote?.apiServer.get('/api/admin/cron')
34
+ console.log(JSON.stringify(json))
35
+ }
36
+ catch (err) {
37
+ logger.error(err)
38
+ }
39
+ }
26
40
  }
27
41
 
28
42
  class CronAddCmd extends Cmd {
@@ -32,9 +46,71 @@ class CronAddCmd extends Cmd {
32
46
  .option('-s --schedule <schedule>', 'schedule in crontab format')
33
47
  .option('-m --module <module_name>', 'module name')
34
48
  .option('-f --function <function>', 'function called in the module')
35
- .option('-p --param <parameter_name_value>', 'name and value separated by = character')
49
+ .option('-p --params <name_value_pairs>', 'URL encoded form without ? (question mark) ie "p1=val1&p2=val2"')
50
+ .action(async (options: any) => {
51
+ await this.commandAdd(options)
52
+ })
53
+ }
54
+ /**
55
+ *
56
+ * @param options
57
+ */
58
+ async commandAdd(options: any) {
59
+ try {
60
+
61
+ await this.prologue(options)
62
+ if (! this.dbRemote) throw 'dbRemote undefined'
63
+ const payload: any = {
64
+ schedule: options.schedule,
65
+ module: options.module,
66
+ function: options.function,
67
+ params: options.params
68
+ }
69
+ const response = await this.dbRemote.apiServer.post('/api/admin/cron', payload)
70
+ logger.debug(response)
71
+ }
72
+ catch (err) {
73
+ logger.error(err)
74
+ }
75
+ }
76
+
77
+ }
78
+
79
+ class CronDeleteCmd extends Cmd {
80
+ constructor(name: string) {
81
+ super(name)
82
+ this.description('delete a batch scheduling with cron')
83
+ .option('-i --id <cron_id>', 'id of the cron to delete (mandatory)')
84
+ .option('-s --schedule <schedule>', 'schedule in crontab format')
85
+ .option('-m --module <module_name>', 'module name')
86
+ .option('-f --function <function>', 'function called in the module')
87
+ .option('-p --params <name_value_pairs>', 'URL encoded form without ? (question mark) ie "p1=val1&p2=val2"')
36
88
  .action(async (options: any) => {
37
- console.log('options', options)
89
+
90
+ await this.commandDelete(options)
38
91
  })
39
92
  }
93
+ /**
94
+ *
95
+ * @param options
96
+ */
97
+ async commandDelete(options: any) {
98
+ try {
99
+
100
+ await this.prologue(options)
101
+ if (! this.dbRemote) throw 'dbRemote undefined'
102
+ if (! options.id) throw 'id is missing'
103
+ const payload: any = {
104
+ schedule: options.schedule,
105
+ module: options.module,
106
+ function: options.function,
107
+ params: options.params
108
+ }
109
+ const response = await this.dbRemote.apiServer.delete(`/api/admin/cron/${options.id}`, payload)
110
+ logger.debug(response)
111
+ }
112
+ catch (err) {
113
+ logger.error(err)
114
+ }
115
+ }
40
116
  }
package/src/index.ts CHANGED
@@ -176,7 +176,7 @@ class StopCommand extends Command {
176
176
  */
177
177
  const program = new Command()
178
178
  program.name('cyk').description('cyklang CLI')
179
- .version('0.8.3')
179
+ .version('0.9.1')
180
180
  program.addCommand(new StartCommand('start'))
181
181
  program.addCommand(new StopCommand('stop'))
182
182
  program.addCommand(new InstallCommand('install'))