@reventlessdev/reventless-aws 3.0.0-alpha.355 → 3.0.0-alpha.356

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,6 +16,7 @@ import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
16
16
  import * as Lambda$PulumiAws from "@reventlessdev/rescript-pulumi-aws/src/Lambda/Lambda.res.mjs";
17
17
  import * as Primitive_object from "@rescript/runtime/lib/es6/Primitive_object.js";
18
18
  import * as Primitive_option from "@rescript/runtime/lib/es6/Primitive_option.js";
19
+ import * as CliArgs$Reventless from "@reventlessdev/reventless-spec/src/CliArgs.res.mjs";
19
20
  import * as ClientSsm from "@aws-sdk/client-ssm";
20
21
  import * as ClientSts from "@aws-sdk/client-sts";
21
22
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
@@ -30,131 +31,68 @@ import * as IndexJs from "@pulumi/pulumi/automation/index.js";
30
31
  let defaultStack = "dev";
31
32
 
32
33
  function parseArgs(argv) {
33
- let acc = {
34
- TAG: "Ok",
35
- _0: {
34
+ return Stdlib_Result.flatMap(CliArgs$Reventless.parse([
35
+ "manifest",
36
+ "stack"
37
+ ], undefined, undefined, undefined, argv), a => {
38
+ let help = CliArgs$Reventless.help(a);
39
+ let args_manifest = CliArgs$Reventless.string(a, "manifest");
40
+ let args_stack = Stdlib_Option.getOr(CliArgs$Reventless.string(a, "stack"), defaultStack);
41
+ let args = {
36
42
  command: undefined,
37
- manifest: undefined,
38
- stack: defaultStack,
39
- help: false
43
+ manifest: args_manifest,
44
+ stack: args_stack,
45
+ help: help
46
+ };
47
+ let positionals = CliArgs$Reventless.positionals(a);
48
+ let match = positionals[0];
49
+ let match$1 = positionals[1];
50
+ if (match$1 !== undefined) {
51
+ return CliArgs$Reventless.extra(match$1);
40
52
  }
41
- };
42
- let i = 0;
43
- let count = argv.length;
44
- while (i < count) {
45
- let flag = argv[i];
46
- let value = argv[i + 1 | 0];
47
- let match = acc;
48
- let exit = 0;
49
- if (match.TAG === "Ok") {
50
- let a = match._0;
51
- let exit$1 = 0;
52
- switch (flag) {
53
- case "--manifest" :
54
- if (value !== undefined) {
55
- acc = {
56
- TAG: "Ok",
57
- _0: {
58
- command: a.command,
59
- manifest: value,
60
- stack: a.stack,
61
- help: a.help
62
- }
63
- };
64
- i = i + 2 | 0;
65
- } else {
66
- exit = 1;
67
- }
68
- break;
69
- case "--stack" :
70
- if (value !== undefined) {
71
- acc = {
72
- TAG: "Ok",
73
- _0: {
74
- command: a.command,
75
- manifest: a.manifest,
76
- stack: value,
77
- help: a.help
78
- }
79
- };
80
- i = i + 2 | 0;
81
- } else {
82
- exit = 1;
83
- }
84
- break;
85
- case "--help" :
86
- case "-h" :
87
- exit$1 = 2;
88
- break;
89
- case "down" :
90
- if (a.command === undefined) {
91
- acc = {
92
- TAG: "Ok",
93
- _0: {
94
- command: "Down",
95
- manifest: a.manifest,
96
- stack: a.stack,
97
- help: a.help
98
- }
99
- };
100
- i = i + 1 | 0;
101
- } else {
102
- exit$1 = 3;
103
- }
104
- break;
105
- case "up" :
106
- if (a.command === undefined) {
107
- acc = {
108
- TAG: "Ok",
109
- _0: {
110
- command: "Up",
111
- manifest: a.manifest,
112
- stack: a.stack,
113
- help: a.help
114
- }
115
- };
116
- i = i + 1 | 0;
117
- } else {
118
- exit$1 = 3;
119
- }
120
- break;
121
- default:
122
- exit$1 = 3;
123
- }
124
- switch (exit$1) {
125
- case 2 :
126
- acc = {
127
- TAG: "Ok",
128
- _0: {
129
- command: a.command,
130
- manifest: a.manifest,
131
- stack: a.stack,
132
- help: true
133
- }
134
- };
135
- i = i + 1 | 0;
136
- break;
137
- case 3 :
138
- acc = {
139
- TAG: "Error",
140
- _0: `unknown argument "` + flag + `"`
141
- };
142
- break;
53
+ if (match === undefined) {
54
+ if (help) {
55
+ return {
56
+ TAG: "Ok",
57
+ _0: args
58
+ };
59
+ } else {
60
+ return {
61
+ TAG: "Error",
62
+ _0: "say `up` or `down`"
63
+ };
143
64
  }
144
- } else {
145
- i = count;
146
65
  }
147
- if (exit === 1) {
148
- acc = {
149
- TAG: "Error",
150
- _0: flag + ` needs a value`
151
- };
66
+ switch (match) {
67
+ case "down" :
68
+ return {
69
+ TAG: "Ok",
70
+ _0: {
71
+ command: "Down",
72
+ manifest: args_manifest,
73
+ stack: args_stack,
74
+ help: help
75
+ }
76
+ };
77
+ case "up" :
78
+ return {
79
+ TAG: "Ok",
80
+ _0: {
81
+ command: "Up",
82
+ manifest: args_manifest,
83
+ stack: args_stack,
84
+ help: help
85
+ }
86
+ };
87
+ default:
88
+ return CliArgs$Reventless.extra(match);
152
89
  }
153
- };
154
- return acc;
90
+ });
155
91
  }
156
92
 
157
93
  let usage = `
94
+ Usage: deploy-app up|down [--manifest <path>] [--stack <name>]
95
+
158
96
  Deploy an app to AWS, or remove it again.
159
97
 
160
98
  deploy-app up Deploy the platform and every plugin, bake the component
@@ -907,32 +845,20 @@ async function down(manifest, stack) {
907
845
  };
908
846
  }
909
847
 
910
- async function run() {
911
- let e = parseArgs(process.argv.slice(2, process.argv.length));
848
+ async function run(param) {
849
+ let stack = param.stack;
850
+ let command = param.command;
851
+ let e = DeployManifest$ReventlessAws.load(Stdlib_Option.getOr(param.manifest, DeployManifest$ReventlessAws.defaultFile));
912
852
  if (e.TAG !== "Ok") {
913
853
  return e;
914
854
  }
915
- let args = e._0;
916
- let command = args.command;
917
- if (args.help) {
918
- console.log(usage);
919
- return {
920
- TAG: "Ok",
921
- _0: undefined
922
- };
923
- }
924
855
  if (command === undefined) {
925
856
  return {
926
857
  TAG: "Error",
927
- _0: "say `up` or `down` (--help for more)"
858
+ _0: "say `up` or `down`"
928
859
  };
929
860
  }
930
- let stack = args.stack;
931
- let e$1 = DeployManifest$ReventlessAws.load(Stdlib_Option.getOr(args.manifest, DeployManifest$ReventlessAws.defaultFile));
932
- if (e$1.TAG !== "Ok") {
933
- return e$1;
934
- }
935
- let manifest = e$1._0;
861
+ let manifest = e._0;
936
862
  if (command === "Up") {
937
863
  return await up(manifest, stack);
938
864
  } else {
@@ -940,21 +866,29 @@ async function run() {
940
866
  }
941
867
  }
942
868
 
943
- async function main() {
944
- let message;
945
- try {
946
- message = await run();
947
- } catch (raw_exn) {
948
- let exn = Primitive_exceptions.internalToException(raw_exn);
949
- console.error(`deploy-app: ` + Util_AwsError$ReventlessAws.describe(exn));
869
+ let cli = {
870
+ bin: "deploy-app",
871
+ usage: usage,
872
+ parse: parseArgs
873
+ };
874
+
875
+ function main() {
876
+ return CliArgs$Reventless.run(cli, undefined, undefined, async args => {
877
+ let message;
878
+ try {
879
+ message = await run(args);
880
+ } catch (raw_exn) {
881
+ let exn = Primitive_exceptions.internalToException(raw_exn);
882
+ console.error(`deploy-app: ` + Util_AwsError$ReventlessAws.describe(exn));
883
+ process.exit(1);
884
+ return;
885
+ }
886
+ if (message.TAG === "Ok") {
887
+ return;
888
+ }
889
+ console.error(`deploy-app: ` + message._0);
950
890
  process.exit(1);
951
- return;
952
- }
953
- if (message.TAG === "Ok") {
954
- return;
955
- }
956
- console.error(`deploy-app: ` + message._0);
957
- process.exit(1);
891
+ });
958
892
  }
959
893
 
960
894
  let Automation;
@@ -1010,6 +944,7 @@ export {
1010
944
  up,
1011
945
  down,
1012
946
  run,
947
+ cli,
1013
948
  main,
1014
949
  }
1015
950
  /* yaml Not a pure module */
@@ -54,36 +54,19 @@ type args = {
54
54
  [ProvisionAdmin.parseArgs] gives, which lands harder here: a typo'd
55
55
  `--provider-id` would fall through to the environment and create the whole cast
56
56
  in a *different pool* than the operator named. */
57
- let parseArgs = (argv: array<string>): result<args, string> => {
58
- let acc = ref(Ok({providerId: None, stack: None, file: None, help: false}))
59
- let i = ref(0)
60
- let count = argv->Array.length
61
- while i.contents < count {
62
- let flag = argv->Array.getUnsafe(i.contents)
63
- let value = argv->Array.get(i.contents + 1)
64
- switch (acc.contents, flag, value) {
65
- | (Error(_), _, _) => i := count
66
- | (Ok(a), "--provider-id", Some(v)) =>
67
- acc := Ok({...a, providerId: Some(v)})
68
- i := i.contents + 2
69
- | (Ok(a), "--stack", Some(v)) =>
70
- acc := Ok({...a, stack: Some(v)})
71
- i := i.contents + 2
72
- | (Ok(a), "--file", Some(v)) =>
73
- acc := Ok({...a, file: Some(v)})
74
- i := i.contents + 2
75
- | (Ok(a), "--help", _) | (Ok(a), "-h", _) =>
76
- acc := Ok({...a, help: true})
77
- i := i.contents + 1
78
- | (Ok(_), "--provider-id", None) | (Ok(_), "--file", None) | (Ok(_), "--stack", None) =>
79
- acc := Error(`${flag} needs a value`)
80
- | (Ok(_), unknown, _) => acc := Error(`unknown argument "${unknown}"`)
81
- }
82
- }
83
- acc.contents
84
- }
57
+ let parseArgs = (argv: array<string>): result<args, string> =>
58
+ Reventless.CliArgs.parse(~strings=["provider-id", "stack", "file"], argv)
59
+ ->Result.flatMap(Reventless.CliArgs.noPositionals)
60
+ ->Result.map(a => {
61
+ providerId: a->Reventless.CliArgs.string("provider-id"),
62
+ stack: a->Reventless.CliArgs.string("stack"),
63
+ file: a->Reventless.CliArgs.string("file"),
64
+ help: a->Reventless.CliArgs.help,
65
+ })
85
66
 
86
67
  let usage = `
68
+ Usage: provision-accounts [--provider-id <id>] [--stack <name>] [--file <path>]
69
+
87
70
  Turn a declared cast of accounts into working sign-ins.
88
71
 
89
72
  --provider-id <id> The identity provider to create the accounts in. Usually
@@ -291,48 +274,44 @@ let provision = async (
291
274
  }
292
275
  }
293
276
 
294
- let run = async (): result<unit, string> =>
295
- // argv[0] is node, argv[1] this script.
296
- switch parseArgs(NodeProcess.argv->Array.slice(~start=2, ~end=NodeProcess.argv->Array.length)) {
277
+ let run = async (args: args): result<unit, string> =>
278
+ switch Manifest.locate(~given=?args.file, ()) {
297
279
  | Error(_) as e => e
298
- | Ok(args) if args.help =>
299
- Console.log(usage)
300
- Ok()
301
- | Ok(args) =>
302
- switch Manifest.locate(~given=?args.file, ()) {
303
- | Error(_) as e => e
304
- | Ok(located) =>
305
- let file = located->Manifest.pathOf
306
- switch located {
307
- | SeededFrom(_, template) => Console.log(`manifest ${file} (new, copied from ${template})`)
308
- | Declared(_) => ()
309
- }
310
- switch ProvisionProvider.resolve(~given=args.providerId, ~stack=args.stack) {
311
- | Error(message) =>
312
- Error(`${message}. To fill in the manifest without creating anything, run prepare-accounts`)
313
- | Ok((providerId, source)) =>
314
- Console.log(`provider ${providerId} (from ${source->ProvisionProvider.describe})`)
315
- await provision(~file, ~providerId)
316
- }
280
+ | Ok(located) =>
281
+ let file = located->Manifest.pathOf
282
+ switch located {
283
+ | SeededFrom(_, template) => Console.log(`manifest ${file} (new, copied from ${template})`)
284
+ | Declared(_) => ()
285
+ }
286
+ switch ProvisionProvider.resolve(~given=args.providerId, ~stack=args.stack) {
287
+ | Error(message) =>
288
+ Error(`${message}. To fill in the manifest without creating anything, run prepare-accounts`)
289
+ | Ok((providerId, source)) =>
290
+ Console.log(`provider ${providerId} (from ${source->ProvisionProvider.describe})`)
291
+ await provision(~file, ~providerId)
317
292
  }
318
293
  }
319
294
 
295
+ let cli: Reventless.CliArgs.cli<args> = {bin: "provision-accounts", usage, parse: parseArgs}
296
+
320
297
  /**
321
298
  🚨 **Catches thrown exceptions, not only `Error` results** — the reason
322
299
  [ProvisionAdmin.main] gives. Without it an SDK failure escapes an async function
323
300
  nothing awaits and Node reports `UnhandledPromiseRejection ... "#<Object>"`,
324
301
  naming neither the call that failed nor why.
325
302
  */
326
- let main = async () =>
327
- switch await run() {
328
- | Ok() => ()
329
- | Error(message) =>
330
- Console.error(`provision-accounts: ${message}`)
331
- NodeProcess.exit(1)
332
- | exception exn =>
333
- Console.error(`provision-accounts: ${Util_AwsError.describe(exn)}`)
334
- NodeProcess.exit(1)
335
- }
303
+ let main = () =>
304
+ Reventless.CliArgs.run(cli, async args =>
305
+ switch await run(args) {
306
+ | Ok() => ()
307
+ | Error(message) =>
308
+ Console.error(`provision-accounts: ${message}`)
309
+ NodeProcess.exit(1)
310
+ | exception exn =>
311
+ Console.error(`provision-accounts: ${Util_AwsError.describe(exn)}`)
312
+ NodeProcess.exit(1)
313
+ }
314
+ )
336
315
 
337
316
  // 🚨 **No top-level call.** `../run-provision-accounts.mjs` invokes [main]; this
338
317
  // module only defines it. A module that ran itself on import could not be
@@ -1,5 +1,7 @@
1
1
  // Generated by ReScript, PLEASE EDIT WITH CARE
2
2
 
3
+ import * as Stdlib_Result from "@rescript/runtime/lib/es6/Stdlib_Result.js";
4
+ import * as CliArgs$Reventless from "@reventlessdev/reventless-spec/src/CliArgs.res.mjs";
3
5
  import * as Primitive_exceptions from "@rescript/runtime/lib/es6/Primitive_exceptions.js";
4
6
  import * as AccountsManifest$Reventless from "@reventlessdev/reventless-spec/src/types/AccountsManifest.res.mjs";
5
7
  import * as Util_AwsError$ReventlessAws from "../src/util/Util_AwsError.res.mjs";
@@ -7,110 +9,21 @@ import * as ProvisionCognito$ReventlessAws from "./ProvisionCognito.res.mjs";
7
9
  import * as ProvisionProvider$ReventlessAws from "./ProvisionProvider.res.mjs";
8
10
 
9
11
  function parseArgs(argv) {
10
- let acc = {
11
- TAG: "Ok",
12
- _0: {
13
- providerId: undefined,
14
- stack: undefined,
15
- file: undefined,
16
- help: false
17
- }
18
- };
19
- let i = 0;
20
- let count = argv.length;
21
- while (i < count) {
22
- let flag = argv[i];
23
- let value = argv[i + 1 | 0];
24
- let match = acc;
25
- let exit = 0;
26
- if (match.TAG === "Ok") {
27
- let a = match._0;
28
- let exit$1 = 0;
29
- switch (flag) {
30
- case "--file" :
31
- if (value !== undefined) {
32
- acc = {
33
- TAG: "Ok",
34
- _0: {
35
- providerId: a.providerId,
36
- stack: a.stack,
37
- file: value,
38
- help: a.help
39
- }
40
- };
41
- i = i + 2 | 0;
42
- } else {
43
- exit = 1;
44
- }
45
- break;
46
- case "--provider-id" :
47
- if (value !== undefined) {
48
- acc = {
49
- TAG: "Ok",
50
- _0: {
51
- providerId: value,
52
- stack: a.stack,
53
- file: a.file,
54
- help: a.help
55
- }
56
- };
57
- i = i + 2 | 0;
58
- } else {
59
- exit = 1;
60
- }
61
- break;
62
- case "--stack" :
63
- if (value !== undefined) {
64
- acc = {
65
- TAG: "Ok",
66
- _0: {
67
- providerId: a.providerId,
68
- stack: value,
69
- file: a.file,
70
- help: a.help
71
- }
72
- };
73
- i = i + 2 | 0;
74
- } else {
75
- exit = 1;
76
- }
77
- break;
78
- case "--help" :
79
- case "-h" :
80
- exit$1 = 2;
81
- break;
82
- default:
83
- acc = {
84
- TAG: "Error",
85
- _0: `unknown argument "` + flag + `"`
86
- };
87
- }
88
- if (exit$1 === 2) {
89
- acc = {
90
- TAG: "Ok",
91
- _0: {
92
- providerId: a.providerId,
93
- stack: a.stack,
94
- file: a.file,
95
- help: true
96
- }
97
- };
98
- i = i + 1 | 0;
99
- }
100
- } else {
101
- i = count;
102
- }
103
- if (exit === 1) {
104
- acc = {
105
- TAG: "Error",
106
- _0: flag + ` needs a value`
107
- };
108
- }
109
- };
110
- return acc;
12
+ return Stdlib_Result.map(Stdlib_Result.flatMap(CliArgs$Reventless.parse([
13
+ "provider-id",
14
+ "stack",
15
+ "file"
16
+ ], undefined, undefined, undefined, argv), CliArgs$Reventless.noPositionals), a => ({
17
+ providerId: CliArgs$Reventless.string(a, "provider-id"),
18
+ stack: CliArgs$Reventless.string(a, "stack"),
19
+ file: CliArgs$Reventless.string(a, "file"),
20
+ help: CliArgs$Reventless.help(a)
21
+ }));
111
22
  }
112
23
 
113
24
  let usage = `
25
+ Usage: provision-accounts [--provider-id <id>] [--stack <name>] [--file <path>]
26
+
114
27
  Turn a declared cast of accounts into working sign-ins.
115
28
 
116
29
  --provider-id <id> The identity provider to create the accounts in. Usually
@@ -277,24 +190,12 @@ async function provision(file, providerId, checkPoolOpt) {
277
190
  };
278
191
  }
279
192
 
280
- async function run() {
281
- let e = parseArgs(process.argv.slice(2, process.argv.length));
193
+ async function run(args) {
194
+ let e = AccountsManifest$Reventless.locate(args.file, undefined);
282
195
  if (e.TAG !== "Ok") {
283
196
  return e;
284
197
  }
285
- let args = e._0;
286
- if (args.help) {
287
- console.log(usage);
288
- return {
289
- TAG: "Ok",
290
- _0: undefined
291
- };
292
- }
293
- let e$1 = AccountsManifest$Reventless.locate(args.file, undefined);
294
- if (e$1.TAG !== "Ok") {
295
- return e$1;
296
- }
297
- let located = e$1._0;
198
+ let located = e._0;
298
199
  let file = AccountsManifest$Reventless.pathOf(located);
299
200
  if (located.TAG !== "Declared") {
300
201
  console.log(`manifest ` + file + ` (new, copied from ` + located._1 + `)`);
@@ -312,21 +213,29 @@ async function run() {
312
213
  return await provision(file, providerId, undefined);
313
214
  }
314
215
 
315
- async function main() {
316
- let message;
317
- try {
318
- message = await run();
319
- } catch (raw_exn) {
320
- let exn = Primitive_exceptions.internalToException(raw_exn);
321
- console.error(`provision-accounts: ` + Util_AwsError$ReventlessAws.describe(exn));
216
+ let cli = {
217
+ bin: "provision-accounts",
218
+ usage: usage,
219
+ parse: parseArgs
220
+ };
221
+
222
+ function main() {
223
+ return CliArgs$Reventless.run(cli, undefined, undefined, async args => {
224
+ let message;
225
+ try {
226
+ message = await run(args);
227
+ } catch (raw_exn) {
228
+ let exn = Primitive_exceptions.internalToException(raw_exn);
229
+ console.error(`provision-accounts: ` + Util_AwsError$ReventlessAws.describe(exn));
230
+ process.exit(1);
231
+ return;
232
+ }
233
+ if (message.TAG === "Ok") {
234
+ return;
235
+ }
236
+ console.error(`provision-accounts: ` + message._0);
322
237
  process.exit(1);
323
- return;
324
- }
325
- if (message.TAG === "Ok") {
326
- return;
327
- }
328
- console.error(`provision-accounts: ` + message._0);
329
- process.exit(1);
238
+ });
330
239
  }
331
240
 
332
241
  let Cognito;
@@ -346,6 +255,7 @@ export {
346
255
  manifestNote,
347
256
  provision,
348
257
  run,
258
+ cli,
349
259
  main,
350
260
  }
351
- /* AccountsManifest-Reventless Not a pure module */
261
+ /* CliArgs-Reventless Not a pure module */