@toa.io/cli 0.2.0-dev.3 → 0.2.1-dev.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.
Files changed (39) hide show
  1. package/package.json +9 -3
  2. package/readme.md +114 -0
  3. package/src/commands/build.js +23 -0
  4. package/src/commands/compose.js +8 -7
  5. package/src/commands/conceal.js +21 -0
  6. package/src/commands/configure.js +43 -0
  7. package/src/commands/deploy.js +20 -6
  8. package/src/commands/export/deployment.js +27 -0
  9. package/src/commands/export/images.js +23 -0
  10. package/src/commands/export/manifest.js +25 -0
  11. package/src/commands/export.js +9 -0
  12. package/src/commands/id.js +7 -0
  13. package/src/commands/invoke.js +2 -1
  14. package/src/commands/replay.js +19 -0
  15. package/src/commands/reveal.js +15 -0
  16. package/src/commands/serve.js +19 -0
  17. package/src/handlers/.configure/subcommands.js +15 -0
  18. package/src/handlers/build.js +14 -0
  19. package/src/handlers/compose.js +1 -4
  20. package/src/handlers/conceal.js +11 -0
  21. package/src/handlers/configure.js +46 -0
  22. package/src/handlers/deploy.js +20 -6
  23. package/src/handlers/export/deployment.js +20 -0
  24. package/src/handlers/export/images.js +16 -0
  25. package/src/handlers/export/manifest.js +19 -0
  26. package/src/handlers/id.js +11 -0
  27. package/src/handlers/invoke.js +12 -8
  28. package/src/handlers/replay.js +35 -0
  29. package/src/handlers/reveal.js +17 -0
  30. package/src/handlers/serve.js +28 -0
  31. package/src/program.js +6 -5
  32. package/src/util/args.js +1 -1
  33. package/src/util/find.js +37 -9
  34. package/types/deploy.d.ts +10 -0
  35. package/LICENSE +0 -22
  36. package/src/commands/deploy/export.js +0 -22
  37. package/src/commands/manifest.js +0 -18
  38. package/src/handlers/deploy/export.js +0 -16
  39. package/src/handlers/manifest.js +0 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toa.io/cli",
3
- "version": "0.2.0-dev.3+8334154",
3
+ "version": "0.2.1-dev.1",
4
4
  "description": "Toa CLI",
5
5
  "author": "temich <tema.gurtovoy@gmail.com>",
6
6
  "homepage": "https://github.com/toa-io/toa#readme",
@@ -19,8 +19,14 @@
19
19
  "test": "echo \"Error: run tests from root\" && exit 1"
20
20
  },
21
21
  "dependencies": {
22
+ "@toa.io/console": "*",
23
+ "@toa.io/generic": "*",
24
+ "@toa.io/kubernetes": "*",
25
+ "@toa.io/norm": "*",
26
+ "@toa.io/runtime": "*",
27
+ "@toa.io/yaml": "*",
22
28
  "find-up": "5.0.0",
23
- "yargs": "17.2.1"
29
+ "yargs": "17.6.2"
24
30
  },
25
- "gitHead": "8334154c1b8a8268ad90adfb15b43a876459014f"
31
+ "gitHead": "2be07592325b2e4dc823e81d882a4e50bf50de24"
26
32
  }
package/readme.md ADDED
@@ -0,0 +1,114 @@
1
+ # Toa Command Line Interface
2
+
3
+ ## Development
4
+
5
+ ### configure
6
+
7
+ Outputs shell commands to manipulate local environment variables, thus must be piped
8
+ with `source /dev/stdin` to apply.
9
+
10
+ <dl>
11
+ <dt><code>toa configure &lt;key&gt; [value]</code></dt>
12
+ <dd>
13
+ Set Configuration Object key. Nested keys are addressed with dot notation.
14
+
15
+ <code>--path</code> path to component (default <code>.</code>)<br/>
16
+ <code>--reset</code> clear <code>key</code><br/>
17
+
18
+ #### Examples
19
+
20
+ It is assumed you are in the component's directory, use `--path` otherwise.
21
+
22
+ ```shell
23
+ # set new value
24
+ $ toa configure foo 'new value' | source /dev/stdin
25
+ ```
26
+
27
+ ```shell
28
+ # clear key
29
+ $ toa configure bar.baz --reset | source /dev/stdin
30
+ ```
31
+
32
+ </dd>
33
+ <dt><code>toa configure reset</code></dt>
34
+ <dd>Remove Configuration Object.</dd>
35
+ <dt><code>toa configure print</code></dt>
36
+ <dd>Output Configuration Object as YAML.
37
+
38
+ <code>--json</code> as JSON
39
+ </dd>
40
+ </dl>
41
+
42
+ ### replay
43
+
44
+ [Replay](/extensions/sampling/docs/replay.md) samples. Reports in [TAP](https://testanything.org)
45
+ format.
46
+
47
+ <dl>
48
+ <dt><code>toa replay [paths...]</code></dt>
49
+ <dd>
50
+ <code>paths</code> path(s) to component(s) or a context (default <code>.</code>)<br/>
51
+
52
+ #### Examples
53
+
54
+ ```shell
55
+ $ toa replay
56
+ $ toa replay ./path/to/component
57
+ $ toa replay ./components/a ./components/b
58
+ $ toa replay ./components/*
59
+ $ toa replay ./path/to/context
60
+ ```
61
+
62
+ If path is a context directory (containing `context.toa.yaml` file), samples for components within
63
+ the context will be found and replayed sequentially.
64
+
65
+ </dd>
66
+ </dl>
67
+
68
+ ## Exporting
69
+
70
+ ### export manifest
71
+
72
+ <dl>
73
+ <dt><code>toa export manifest</code></dt>
74
+ <dd>Print normalized manifest.
75
+
76
+ <code>--path</code> path to component (default <code>.</code>)<br/>
77
+ <code>--error</code> print errors only<br/>
78
+ </dd>
79
+ </dl>
80
+
81
+ ## Deployment
82
+
83
+ > Deployment commands use current `kubectl` context.
84
+
85
+ ### deploy
86
+
87
+ <dl>
88
+ <dt><code>toa deploy [environment]</code></dt>
89
+ <dd>Deploy context.</dd>
90
+ </dl>
91
+
92
+ ### conceal
93
+
94
+ <dl>
95
+ <dt>
96
+ <code>toa conceal</code>
97
+ <img src="https://img.shields.io/badge/Not_Implemented-red" alt="Not Implemented"/>
98
+ </dt>
99
+ <dd>Deploy new declared secrets.
100
+
101
+ <code>--reset</code> don't skip already deployed</dd>
102
+
103
+ <dt><code>toa conceal &lt;secret&gt; &lt;key&gt; &lt;value&gt;</code></dt>
104
+ <dd>Deploy a <code>key</code> with a <code>value</code> to a <code>secret</code>.</dd>
105
+ </dl>
106
+
107
+ ### reveal
108
+
109
+ <dl>
110
+ <dt>
111
+ <code>toa reveal &lt;secret&gt;</code>
112
+ </dt>
113
+ <dd>Print keys and values of a secret.</dd>
114
+ </dl>
@@ -0,0 +1,23 @@
1
+ 'use strict'
2
+
3
+ const { build } = require('../handlers/build')
4
+
5
+ const builder = (yargs) => {
6
+ yargs
7
+ .positional('environment', {
8
+ type: 'string',
9
+ desc: 'Deployment environment'
10
+ })
11
+ .option('path', {
12
+ alias: 'p',
13
+ group: 'Command options:',
14
+ type: 'string',
15
+ desc: 'Path to context',
16
+ default: '.'
17
+ })
18
+ }
19
+
20
+ exports.command = 'build [environment]'
21
+ exports.desc = 'Build and push docker images'
22
+ exports.builder = builder
23
+ exports.handler = build
@@ -1,3 +1,5 @@
1
+ // noinspection JSCheckFunctionSignatures
2
+
1
3
  'use strict'
2
4
 
3
5
  const { compose } = require('../handlers/compose')
@@ -6,7 +8,7 @@ const builder = (yargs) => {
6
8
  yargs
7
9
  .positional('paths', {
8
10
  type: 'string',
9
- desc: 'Path to package',
11
+ desc: 'Paths to components',
10
12
  default: '.'
11
13
  })
12
14
  .array('paths')
@@ -17,15 +19,14 @@ const builder = (yargs) => {
17
19
  })
18
20
  .array('bindings')
19
21
  .example([
20
- ['$0 compose ./component', 'Path to component package'],
21
- ['$0 compose ./first ./second', 'Paths enumeration'],
22
- ['$0 compose ./components/**/', 'Glob pattern'],
23
- ['$0 compose ./a/**/ ./b/**/', 'Glob patterns enumeration']
22
+ ['$0 compose ./component'],
23
+ ['$0 compose ./first ./second'],
24
+ ['$0 compose ./components/**/'],
25
+ ['$0 compose ./a/**/ ./b/**/']
24
26
  ])
25
- .strictCommands()
26
27
  }
27
28
 
28
29
  exports.command = 'compose [paths...]'
29
- exports.desc = 'Start composition'
30
+ exports.desc = 'Run composition'
30
31
  exports.builder = builder
31
32
  exports.handler = compose
@@ -0,0 +1,21 @@
1
+ 'use strict'
2
+
3
+ const { conceal } = require('../handlers/conceal')
4
+
5
+ const builder = (yargs) => {
6
+ yargs
7
+ .positional('secret', {
8
+ type: 'string'
9
+ })
10
+ .positional('key', {
11
+ type: 'string'
12
+ })
13
+ .positional('value', {
14
+ type: 'string'
15
+ })
16
+ }
17
+
18
+ exports.command = 'conceal <secret> <key> <value>'
19
+ exports.desc = 'Deploy a key with a value to a secret'
20
+ exports.builder = builder
21
+ exports.handler = conceal
@@ -0,0 +1,43 @@
1
+ 'use strict'
2
+
3
+ const { configure } = require('../handlers/configure')
4
+
5
+ const builder = (yargs) => {
6
+ yargs
7
+ .positional('key', {
8
+ type: 'string',
9
+ desc: 'Configuration Object key'
10
+ })
11
+ .positional('value', {
12
+ type: 'string',
13
+ desc: 'Key value'
14
+ })
15
+ .option('path', {
16
+ alias: 'p',
17
+ group: 'Command options:',
18
+ describe: 'Path to component',
19
+ type: 'string',
20
+ default: '.'
21
+ })
22
+ .option('reset', {
23
+ group: 'Command options:',
24
+ type: 'boolean',
25
+ desc: 'Remove Configuration Object key'
26
+ })
27
+ .option('json', {
28
+ group: 'Command options:',
29
+ type: 'boolean',
30
+ desc: 'Print as JSON'
31
+ })
32
+ .example([
33
+ ['$0 configure myKey \'new value\' | source /dev/stdin'],
34
+ ['$0 configure myObject.myKey --reset | source /dev/stdin'],
35
+ ['$0 configure reset | source /dev/stdin'],
36
+ ['$0 configure print --json']
37
+ ])
38
+ }
39
+
40
+ exports.command = 'configure [key] [value]'
41
+ exports.desc = 'Output shell command to update local environment Configuration Object'
42
+ exports.builder = builder
43
+ exports.handler = configure
@@ -4,24 +4,38 @@ const { deploy } = require('../handlers/deploy')
4
4
 
5
5
  const builder = (yargs) => {
6
6
  yargs
7
- .positional('path', {
7
+ .positional('environment', {
8
+ type: 'string',
9
+ desc: 'Deployment environment'
10
+ })
11
+ .option('path', {
12
+ alias: 'p',
13
+ group: 'Command options:',
8
14
  type: 'string',
9
15
  desc: 'Path to context',
10
16
  default: '.'
11
17
  })
12
18
  .option('dry', {
19
+ alias: 'd',
20
+ group: 'Command options:',
13
21
  boolean: true,
14
22
  desc: 'Dry run'
15
23
  })
16
- .option('no-wait', {
24
+ .option('namespace', {
25
+ alias: 'n',
26
+ group: 'Command options:',
27
+ type: 'string',
28
+ desc: 'Target namespace'
29
+ })
30
+ .option('wait', {
31
+ alias: 'w',
32
+ group: 'Command options:',
17
33
  boolean: true,
18
- desc: 'Disable waiting for deployment ready state'
34
+ desc: 'Wait for deployment ready state'
19
35
  })
20
- .usage('Usage: toa deploy /path/to/context')
21
- .commandDir('./deploy')
22
36
  }
23
37
 
24
- exports.command = 'deploy [path]'
38
+ exports.command = 'deploy [environment]'
25
39
  exports.desc = 'Deploy context'
26
40
  exports.builder = builder
27
41
  exports.handler = deploy
@@ -0,0 +1,27 @@
1
+ 'use strict'
2
+
3
+ const { dump } = require('../../handlers/export/deployment')
4
+
5
+ const builder = (yargs) => {
6
+ yargs
7
+ .positional('target', {
8
+ type: 'string',
9
+ desc: 'Export target path'
10
+ })
11
+ .positional('environment', {
12
+ type: 'string',
13
+ desc: 'Deployment environment'
14
+ })
15
+ .option('path', {
16
+ alias: 'p',
17
+ group: 'Command options:',
18
+ type: 'string',
19
+ desc: 'Path to context',
20
+ default: '.'
21
+ })
22
+ }
23
+
24
+ exports.command = ['deployment <target> [environment]', 'dep']
25
+ exports.desc = 'Export context deployment'
26
+ exports.builder = builder
27
+ exports.handler = dump
@@ -0,0 +1,23 @@
1
+ 'use strict'
2
+
3
+ const { prepare } = require('../../handlers/export/images')
4
+
5
+ const builder = (yargs) => {
6
+ yargs
7
+ .positional('target', {
8
+ type: 'string',
9
+ desc: 'Export target path'
10
+ })
11
+ .option('path', {
12
+ alias: 'p',
13
+ group: 'Command options:',
14
+ type: 'string',
15
+ desc: 'Path to context',
16
+ default: '.'
17
+ })
18
+ }
19
+
20
+ exports.command = ['images [target]', 'imgs']
21
+ exports.desc = 'Export docker image sources'
22
+ exports.builder = builder
23
+ exports.handler = prepare
@@ -0,0 +1,25 @@
1
+ 'use strict'
2
+
3
+ const { manifest } = require('../../handlers/export/manifest')
4
+
5
+ const builder = (yargs) => {
6
+ yargs
7
+ .option('error', {
8
+ alias: 'e',
9
+ group: 'Command options:',
10
+ type: 'boolean',
11
+ desc: 'Print errors only'
12
+ })
13
+ .option('path', {
14
+ alias: 'p',
15
+ group: 'Command options:',
16
+ type: 'string',
17
+ desc: 'Path to component',
18
+ default: '.'
19
+ })
20
+ }
21
+
22
+ exports.command = ['manifest', 'man']
23
+ exports.desc = 'Print manifest'
24
+ exports.builder = builder
25
+ exports.handler = manifest
@@ -0,0 +1,9 @@
1
+ 'use strict'
2
+
3
+ const builder = (yargs) => yargs
4
+ .commandDir('./export')
5
+ .demandCommand()
6
+
7
+ exports.command = 'export <artifact>'
8
+ exports.desc = 'Export internal artifacts'
9
+ exports.builder = builder
@@ -0,0 +1,7 @@
1
+ 'use strict'
2
+
3
+ const { id } = require('../handlers/id')
4
+
5
+ exports.command = 'id'
6
+ exports.desc = false
7
+ exports.handler = id
@@ -10,9 +10,10 @@ const builder = (yargs) => {
10
10
  })
11
11
  .positional('request', {
12
12
  type: 'string',
13
- desc: 'Request YAML'
13
+ desc: 'Request object (yaml)'
14
14
  })
15
15
  .option('path', {
16
+ alias: 'p',
16
17
  group: 'Command options:',
17
18
  type: 'string',
18
19
  describe: 'Path to component',
@@ -0,0 +1,19 @@
1
+ // noinspection JSCheckFunctionSignatures
2
+
3
+ 'use strict'
4
+
5
+ const { replay } = require('../handlers/replay')
6
+
7
+ const builder = (yargs) => {
8
+ yargs
9
+ .positional('paths', {
10
+ type: 'string',
11
+ desc: 'Paths to components or context',
12
+ default: '.'
13
+ })
14
+ }
15
+
16
+ exports.command = 'replay [paths...]'
17
+ exports.desc = 'Replay samples'
18
+ exports.builder = builder
19
+ exports.handler = replay
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+
3
+ const { reveal } = require('../handlers/reveal')
4
+
5
+ const builder = (yargs) => {
6
+ yargs
7
+ .positional('secret', {
8
+ type: 'string'
9
+ })
10
+ }
11
+
12
+ exports.command = 'reveal <secret>'
13
+ exports.desc = 'Print keys and values of a secret'
14
+ exports.builder = builder
15
+ exports.handler = reveal
@@ -0,0 +1,19 @@
1
+ 'use strict'
2
+
3
+ const { serve } = require('../handlers/serve')
4
+
5
+ const builder = (yargs) => {
6
+ yargs
7
+ .positional('path', {
8
+ alias: 'p',
9
+ group: 'Command options:',
10
+ type: 'string',
11
+ desc: 'Path to package',
12
+ default: '.'
13
+ })
14
+ }
15
+
16
+ exports.command = 'serve [path]'
17
+ exports.desc = 'Run service'
18
+ exports.builder = builder
19
+ exports.handler = serve
@@ -0,0 +1,15 @@
1
+ 'use strict'
2
+
3
+ const { dump } = require('@toa.io/yaml')
4
+
5
+ const reset = (provider) => console.log('unset ' + provider.key)
6
+
7
+ const print = async (provider, argv) => {
8
+ await provider.connect()
9
+
10
+ const formatter = argv.json ? JSON.stringify : dump
11
+
12
+ console.log(formatter(provider.object))
13
+ }
14
+
15
+ exports.subcommands = { print, reset }
@@ -0,0 +1,14 @@
1
+ 'use strict'
2
+
3
+ const boot = require('@toa.io/boot')
4
+
5
+ const { context: find } = require('../util/find')
6
+
7
+ const build = async (argv) => {
8
+ const path = find(argv.path)
9
+ const operator = await boot.deployment(path, argv.environment)
10
+
11
+ await operator.build()
12
+ }
13
+
14
+ exports.build = build
@@ -2,13 +2,10 @@
2
2
 
3
3
  const boot = require('@toa.io/boot')
4
4
 
5
- const { manifest: find } = require('../util/find')
5
+ const { components: find } = require('../util/find')
6
6
 
7
7
  async function compose (argv) {
8
8
  const paths = find(argv.paths)
9
-
10
- if (paths === undefined) throw new Error(`No components found in ${argv.paths}`)
11
-
12
9
  const composition = await boot.composition(paths, argv)
13
10
 
14
11
  await composition.connect()
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ const { secrets } = require('@toa.io/kubernetes')
4
+
5
+ const conceal = async (argv) => {
6
+ const { secret, key, value } = argv
7
+
8
+ await secrets.store(secret, { [key]: value })
9
+ }
10
+
11
+ exports.conceal = conceal
@@ -0,0 +1,46 @@
1
+ 'use strict'
2
+
3
+ const boot = require('@toa.io/boot')
4
+
5
+ const { Factory } = require('@toa.io/extensions.configuration')
6
+
7
+ const { subcommands } = require('./.configure/subcommands')
8
+ const { components: find } = require('../util/find')
9
+
10
+ async function configure (argv) {
11
+ const path = find(argv.path)
12
+ const manifest = await boot.manifest(path)
13
+ const factory = new Factory()
14
+ const provider = factory.provider(manifest)
15
+
16
+ if (argv.value === undefined && subcommands[argv.key] !== undefined) {
17
+ await subcommands[argv.key](provider, argv)
18
+
19
+ return
20
+ }
21
+
22
+ await provider.connect()
23
+
24
+ let key = argv.key
25
+ let value = argv.value
26
+
27
+ // :(
28
+ if (key !== undefined) {
29
+ if (value === undefined && key.includes('=')) [key, value] = key.split('=')
30
+
31
+ if (value === undefined) {
32
+ if (argv.reset !== true) throw new Error('Key value expected')
33
+ else provider.unset(key)
34
+ } else provider.set(key, value)
35
+ }
36
+
37
+ let command
38
+ const exported = provider.export()
39
+
40
+ if (exported === undefined) command = `unset ${provider.key}`
41
+ else command = `export ${provider.key}=` + exported
42
+
43
+ console.log(command)
44
+ }
45
+
46
+ exports.configure = configure
@@ -4,16 +4,30 @@ const boot = require('@toa.io/boot')
4
4
 
5
5
  const { context: find } = require('../util/find')
6
6
 
7
+ /**
8
+ * @param {toa.cli.deploy.Arguments} argv
9
+ * @returns {Promise<void>}
10
+ */
7
11
  const deploy = async (argv) => {
8
12
  const path = find(argv.path)
9
- const deployment = await boot.deployment(path)
13
+ const operator = await boot.deployment(path, argv.environment)
10
14
 
11
- const options = {
12
- wait: argv['no-wait'] !== true,
13
- dry: argv.dry === true
14
- }
15
+ if (argv.dry === true) {
16
+ const options = {}
17
+
18
+ if (argv.namespace !== undefined) options.namespace = argv.namespace
19
+
20
+ const output = await operator.template(options)
15
21
 
16
- await deployment.install(options)
22
+ console.log(output)
23
+ } else {
24
+ const options = {}
25
+
26
+ if (argv.namespace !== undefined) options.namespace = argv.namespace
27
+ if (argv.wait === true) options.wait = true
28
+
29
+ await operator.install(options)
30
+ }
17
31
  }
18
32
 
19
33
  exports.deploy = deploy
@@ -0,0 +1,20 @@
1
+ 'use strict'
2
+
3
+ const boot = require('@toa.io/boot')
4
+ const { console } = require('@toa.io/console')
5
+
6
+ const { context: find } = require('../../util/find')
7
+
8
+ /**
9
+ * @param {{ path: string, target: string, environment?: string }} argv
10
+ * @returns {Promise<void>}
11
+ */
12
+ const dump = async (argv) => {
13
+ const context = find(argv.path)
14
+ const operator = await boot.deployment(context, argv.environment)
15
+ const path = await operator.export(argv.target)
16
+
17
+ console.log(path)
18
+ }
19
+
20
+ exports.dump = dump
@@ -0,0 +1,16 @@
1
+ 'use strict'
2
+
3
+ const boot = require('@toa.io/boot')
4
+ const { console } = require('@toa.io/console')
5
+
6
+ const { context: find } = require('../../util/find')
7
+
8
+ const prepare = async (argv) => {
9
+ const context = find(argv.path)
10
+ const operator = await boot.deployment(context)
11
+ const path = await operator.prepare(argv.target)
12
+
13
+ console.log(path)
14
+ }
15
+
16
+ exports.prepare = prepare
@@ -0,0 +1,19 @@
1
+ 'use strict'
2
+
3
+ const { component } = require('@toa.io/norm')
4
+ const { dump } = require('@toa.io/yaml')
5
+ const { console } = require('@toa.io/console')
6
+
7
+ const { components: find } = require('../../util/find')
8
+
9
+ const print = async (argv) => {
10
+ const path = find(argv.path)
11
+
12
+ if (path === undefined) throw new Error(`No component found in ${argv.path}`)
13
+
14
+ const manifest = await component(path)
15
+
16
+ if (argv.error !== true) console.log(dump(manifest))
17
+ }
18
+
19
+ exports.manifest = print
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ const { newid } = require('@toa.io/generic')
4
+
5
+ const id = () => {
6
+ const id = newid()
7
+
8
+ console.log(id)
9
+ }
10
+
11
+ exports.id = id
@@ -1,26 +1,30 @@
1
1
  'use strict'
2
2
 
3
3
  const boot = require('@toa.io/boot')
4
- const { yaml } = require('@toa.io/gears')
5
- const { manifest: find } = require('../util/find')
4
+ const yaml = require('@toa.io/yaml')
5
+ const { components: find } = require('../util/find')
6
6
 
7
7
  async function invoke (argv) {
8
8
  const path = find(argv.path)
9
- const request = yaml.parse(argv.request)
9
+ const request = argv.request ? yaml.parse(argv.request) : {}
10
10
 
11
- const composition = await boot.composition([path], { bindings: null })
11
+ const composition = await boot.composition([path])
12
12
  await composition.connect()
13
13
 
14
14
  const manifest = await boot.manifest(path)
15
15
  const remote = await boot.remote(manifest.locator, manifest)
16
16
  await remote.connect()
17
17
 
18
- const reply = await remote.invoke(argv.operation, request)
18
+ let reply
19
19
 
20
- await remote.disconnect()
21
- await composition.disconnect()
20
+ try {
21
+ reply = await remote.invoke(argv.operation, request)
22
+ } finally {
23
+ await remote.disconnect()
24
+ await composition.disconnect()
25
+ }
22
26
 
23
- console.dir(reply)
27
+ if (reply !== undefined) console.log(reply)
24
28
  }
25
29
 
26
30
  exports.invoke = invoke
@@ -0,0 +1,35 @@
1
+ 'use strict'
2
+
3
+ const find = require('../util/find')
4
+
5
+ async function replay (argv) {
6
+ // prevent loading userland which is intended for local use only
7
+ const { context, components } = require('@toa.io/userland/samples')
8
+
9
+ /** @type {boolean} */
10
+ let ok
11
+
12
+ const paths = find.components(argv.paths, true)
13
+
14
+ if (paths !== null) {
15
+ ok = await components(paths)
16
+ } else {
17
+ // no components found, checking context
18
+ const path = find.context(argv.paths[0], true)
19
+
20
+ if (path === null) throw new Error('Neither components nor context found in ' + argv.paths.join(','))
21
+
22
+ ok = await context(path)
23
+ }
24
+
25
+ const message = (ok ? GREEN + 'PASSED' : RED + 'FAILED') + RESET
26
+
27
+ // print after tap's output
28
+ process.on('beforeExit', () => console.log(message))
29
+ }
30
+
31
+ const GREEN = '\x1b[32m'
32
+ const RED = '\x1b[31m'
33
+ const RESET = '\x1b[0m'
34
+
35
+ exports.replay = replay
@@ -0,0 +1,17 @@
1
+ 'use strict'
2
+
3
+ const { secrets } = require('@toa.io/kubernetes')
4
+ const { remap, decode } = require('@toa.io/generic')
5
+
6
+ const reveal = async (argv) => {
7
+ const secret = await secrets.get(argv.secret)
8
+ const values = remap(secret.data, decode)
9
+
10
+ for (const [key, value] of Object.entries(values)) {
11
+ const line = `${key}: ${value}`
12
+
13
+ console.log(line)
14
+ }
15
+ }
16
+
17
+ exports.reveal = reveal
@@ -0,0 +1,28 @@
1
+ 'use strict'
2
+
3
+ const boot = require('@toa.io/boot')
4
+ const { shortcuts } = require('@toa.io/norm')
5
+ const { directory: { find } } = require('@toa.io/filesystem')
6
+
7
+ const serve = async (argv) => {
8
+ argv.path = shortcuts.resolve(argv.path)
9
+
10
+ const module = find(argv.path, process.cwd())
11
+
12
+ const { Factory } = require(module)
13
+
14
+ /** @type {toa.core.extensions.Factory} */
15
+ const factory = new Factory(boot)
16
+
17
+ /** @type {toa.core.Connector} */
18
+ const service = factory.service()
19
+
20
+ if (service === undefined) throw new Error(`Cannot find service '${argv.name}' in ${argv.path}`)
21
+
22
+ await service.connect()
23
+
24
+ // for tests
25
+ return service
26
+ }
27
+
28
+ exports.serve = serve
package/src/program.js CHANGED
@@ -1,28 +1,29 @@
1
+ // noinspection JSUnresolvedVariable
2
+
1
3
  'use strict'
2
4
 
3
5
  const yargs = require('yargs/yargs')
4
6
 
5
- const { console } = require('@toa.io/gears')
6
- const { version } = require('../package.json')
7
+ const { console } = require('@toa.io/console')
8
+ const { version } = require('@toa.io/runtime')
7
9
 
8
10
  yargs(process.argv.slice(2))
9
11
  .parserConfiguration({
10
12
  'boolean-negation': false
11
13
  })
12
14
  .middleware((argv) => {
13
- if (argv.log === undefined) argv.log = 'info'
15
+ if (argv.log === undefined) argv.log = process.env.TOA_DEBUG === '1' ? 'debug' : 'info'
14
16
 
15
17
  console.level(argv.log)
16
18
  })
17
19
  .fail((msg, err) => {
18
20
  const actual = err || new Error(msg)
19
21
 
20
- console.error(process.env.TOA_ENV === 'local' ? actual : actual.message)
22
+ console.error(process.env.TOA_DEBUG === '1' ? actual : actual.message)
21
23
 
22
24
  process.exit(actual.exitCode > 0 ? actual.exitCode : 1)
23
25
  })
24
26
  .option('log', {
25
- type: 'string',
26
27
  describe: 'Log level'
27
28
  })
28
29
  .commandDir('./commands')
package/src/util/args.js CHANGED
@@ -8,7 +8,7 @@ const bindings = (argv) => {
8
8
  if (argv.bindings !== undefined) {
9
9
  bindings = argv.bindings.map((binding) => {
10
10
  if (binding[0] === '@' && binding.indexOf('/') === -1) {
11
- binding = '@toa.io/bindings.' + binding.substr(1)
11
+ binding = '@toa.io/bindings.' + binding.substring(1)
12
12
  }
13
13
 
14
14
  return binding
package/src/util/find.js CHANGED
@@ -3,25 +3,53 @@
3
3
  const { dirname, resolve } = require('node:path')
4
4
  const findUp = require('find-up')
5
5
 
6
- const find = (from = '.', filename) => {
6
+ /**
7
+ * @param {string | string[]} from
8
+ * @param {string} filename
9
+ * @param {boolean} test
10
+ * @return {string | string[] | null}
11
+ */
12
+ const find = (from, filename, test) => {
7
13
  if (from instanceof Array) {
8
- const found = new Set(from.map((path) => find(path, filename)))
14
+ const found = new Set(from.map((path) => find(path, filename, true)))
9
15
 
10
- found.delete(undefined)
16
+ found.delete(null)
11
17
 
12
- return found.size > 0 ? [...found] : undefined
18
+ if (found.size === 0) {
19
+ if (test === true) return null
20
+ else throw new Error(`File '${filename}' is found in ${from.join(', ')}`)
21
+ }
22
+
23
+ return [...found]
13
24
  }
14
25
 
15
- const path = findUp.sync(filename, { cwd: resolve(process.cwd(), from) })
26
+ const cwd = resolve(process.cwd(), from)
27
+ const path = findUp.sync(filename, { cwd })
28
+
29
+ if (path === undefined) {
30
+ if (test === true) return null
31
+ else throw new Error(`Cannot find '${filename}' from '${from}'`)
32
+ }
16
33
 
17
- return path === undefined ? undefined : dirname(path)
34
+ return dirname(path)
18
35
  }
19
36
 
20
- const manifest = (from = '.') => find(from, MANIFEST)
21
- const context = (from = '.') => find(from, CONTEXT)
37
+ /**
38
+ * @param {string | string[]} from
39
+ * @param {boolean} test
40
+ * @return {string | string[] | null}
41
+ */
42
+ const components = (from, test = false) => find(from, MANIFEST, test)
43
+
44
+ /**
45
+ * @param {string | string[]} from
46
+ * @param {boolean} test
47
+ * @return {string | string[] | null}
48
+ */
49
+ const context = (from, test = false) => find(from, CONTEXT, test)
22
50
 
23
51
  const MANIFEST = 'manifest.toa.yaml'
24
52
  const CONTEXT = 'context.toa.yaml'
25
53
 
26
- exports.manifest = manifest
54
+ exports.components = components
27
55
  exports.context = context
@@ -0,0 +1,10 @@
1
+ declare namespace toa.cli.deploy {
2
+
3
+ interface Arguments {
4
+ path: string
5
+ environment?: string
6
+ namespace?: string
7
+ dry: boolean
8
+ wait: boolean
9
+ }
10
+ }
package/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2020-present Artem Gurtovoi
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,22 +0,0 @@
1
- 'use strict'
2
-
3
- const { dump } = require('../../handlers/deploy/export')
4
-
5
- const builder = (yargs) => {
6
- yargs
7
- .positional('path', {
8
- type: 'string',
9
- desc: 'Path to context',
10
- default: '.'
11
- })
12
- .positional('target', {
13
- type: 'string',
14
- desc: 'Export target path'
15
- })
16
- .usage('Usage: toa deploy export /path/to/context /export/path')
17
- }
18
-
19
- exports.command = 'export [path] [target]'
20
- exports.desc = 'Export context deployment chart'
21
- exports.builder = builder
22
- exports.handler = dump
@@ -1,18 +0,0 @@
1
- 'use strict'
2
-
3
- const { manifest } = require('../handlers/manifest')
4
-
5
- const builder = (yargs) => {
6
- yargs
7
- .positional('path', {
8
- type: 'string',
9
- desc: 'Path to component',
10
- default: '.'
11
- })
12
- .usage('Usage: toa manifest /path/to/component')
13
- }
14
-
15
- exports.command = 'manifest [path]'
16
- exports.desc = 'Print manifest'
17
- exports.builder = builder
18
- exports.handler = manifest
@@ -1,16 +0,0 @@
1
- 'use strict'
2
-
3
- const boot = require('@toa.io/boot')
4
- const { console } = require('@toa.io/gears')
5
-
6
- const { context: find } = require('../../util/find')
7
-
8
- const dump = async (argv) => {
9
- const context = find(argv.path)
10
- const deployment = await boot.deployment(context)
11
- const path = await deployment.export(argv.target)
12
-
13
- console.log(path)
14
- }
15
-
16
- exports.dump = dump
@@ -1,14 +0,0 @@
1
- 'use strict'
2
-
3
- const { manifest: load } = require('@toa.io/package')
4
- const { console, yaml } = require('@toa.io/gears')
5
-
6
- const { manifest: find } = require('../util/find')
7
-
8
- const print = async (argv) => {
9
- const manifest = await load(find(argv.path))
10
-
11
- console.log(yaml.dump(manifest))
12
- }
13
-
14
- exports.manifest = print