@heroku/heroku-cli-util 9.0.0-beta.3 → 9.0.0
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/README.md +70 -23
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,50 +19,97 @@ npm install @heroku/heroku-cli-util
|
|
|
19
19
|
|
|
20
20
|
## Usage
|
|
21
21
|
|
|
22
|
-
You can import the utilities you need.
|
|
22
|
+
You can import the utilities you need from the main exports.
|
|
23
23
|
|
|
24
24
|
### Output Utilities
|
|
25
25
|
|
|
26
26
|
```js
|
|
27
|
+
import { hux } from '@heroku/heroku-cli-util';
|
|
28
|
+
|
|
27
29
|
// Styled header
|
|
28
|
-
|
|
29
|
-
styledHeader('My CLI Header');
|
|
30
|
+
hux.styledHeader('My CLI Header');
|
|
30
31
|
|
|
31
32
|
// Styled JSON
|
|
32
|
-
|
|
33
|
-
styledJSON({ foo: 'bar' });
|
|
33
|
+
hux.styledJson({ foo: 'bar' });
|
|
34
34
|
|
|
35
35
|
// Styled object
|
|
36
|
-
|
|
37
|
-
styledObject({ foo: 'bar' });
|
|
38
|
-
|
|
39
|
-
// Table
|
|
40
|
-
import { table } from '@heroku/heroku-cli-util/dist/ux/table';
|
|
41
|
-
table([{ name: 'Alice' }, { name: 'Bob' }], { columns: [{ key: 'name' }] });
|
|
42
|
-
|
|
43
|
-
// Wait
|
|
44
|
-
import { wait } from '@heroku/heroku-cli-util/dist/ux/wait';
|
|
45
|
-
await wait('Processing...');
|
|
36
|
+
hux.styledObject({ foo: 'bar' });
|
|
46
37
|
```
|
|
47
38
|
|
|
48
39
|
### User Interaction
|
|
49
40
|
|
|
50
41
|
```js
|
|
51
|
-
import {
|
|
52
|
-
const name = await prompt('What is your name?');
|
|
42
|
+
import { hux } from '@heroku/heroku-cli-util';
|
|
53
43
|
|
|
54
|
-
|
|
55
|
-
const proceed = await confirm('Continue?');
|
|
44
|
+
const name = await hux.prompt('What is your name?');
|
|
45
|
+
const proceed = await hux.confirm('Continue?');
|
|
56
46
|
```
|
|
57
47
|
|
|
58
48
|
### Test Helpers
|
|
59
49
|
|
|
60
50
|
```js
|
|
61
|
-
import {
|
|
62
|
-
|
|
51
|
+
import { testHelpers } from '@heroku/heroku-cli-util';
|
|
52
|
+
|
|
53
|
+
testHelpers.initCliTest();
|
|
54
|
+
|
|
55
|
+
testHelpers.setupStdoutStderr();
|
|
56
|
+
// ...run your CLI code...
|
|
57
|
+
const output = testHelpers.stdout();
|
|
58
|
+
const errorOutput = testHelpers.stderr();
|
|
59
|
+
testHelpers.restoreStdoutStderr();
|
|
60
|
+
|
|
61
|
+
testHelpers.expectOutput(output, 'expected output');
|
|
62
|
+
|
|
63
|
+
// Run a command (see docs for details)
|
|
64
|
+
// await testHelpers.runCommand(MyCommand, ['arg1', 'arg2']);
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Types
|
|
68
|
+
|
|
69
|
+
```js
|
|
70
|
+
import { types } from '@heroku/heroku-cli-util';
|
|
71
|
+
|
|
72
|
+
// Error types
|
|
73
|
+
try {
|
|
74
|
+
throw new types.errors.AmbiguousError([{ name: 'foo' }, { name: 'bar' }], 'addon');
|
|
75
|
+
} catch (err) {
|
|
76
|
+
if (err instanceof types.errors.AmbiguousError) {
|
|
77
|
+
console.error('Ambiguous:', err.message);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
throw new types.errors.NotFound();
|
|
83
|
+
} catch (err) {
|
|
84
|
+
if (err instanceof types.errors.NotFound) {
|
|
85
|
+
console.error('Not found:', err.message);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// PG types (for TypeScript)
|
|
90
|
+
/**
|
|
91
|
+
* types.pg.AddOnAttachmentWithConfigVarsAndPlan
|
|
92
|
+
* types.pg.AddOnWithRelatedData
|
|
93
|
+
* types.pg.ConnectionDetails
|
|
94
|
+
* types.pg.ConnectionDetailsWithAttachment
|
|
95
|
+
* types.pg.Link
|
|
96
|
+
* types.pg.TunnelConfig
|
|
97
|
+
*/
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
### Database and Utility Helpers
|
|
101
|
+
|
|
102
|
+
```js
|
|
103
|
+
import { utils } from '@heroku/heroku-cli-util';
|
|
104
|
+
|
|
105
|
+
// Get Heroku Postgres database connection details (requires APIClient from @heroku-cli/command)
|
|
106
|
+
// const db = await utils.pg.databases(herokuApiClient, 'my-app', 'DATABASE_URL');
|
|
107
|
+
|
|
108
|
+
// Get Heroku Postgres host
|
|
109
|
+
const host = utils.pg.host();
|
|
63
110
|
|
|
64
|
-
|
|
65
|
-
//
|
|
111
|
+
// Run a query (requires a ConnectionDetails object)
|
|
112
|
+
// const result = await utils.pg.psql.exec(db, 'SELECT 1');
|
|
66
113
|
```
|
|
67
114
|
|
|
68
115
|
## Development
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.hux = exports.utils = exports.types = exports.testHelpers = void 0;
|
|
4
4
|
const expect_output_1 = require("./test-helpers/expect-output");
|
|
5
5
|
const init_1 = require("./test-helpers/init");
|
|
6
6
|
const run_command_1 = require("./test-helpers/run-command");
|
|
@@ -47,7 +47,7 @@ exports.utils = {
|
|
|
47
47
|
},
|
|
48
48
|
},
|
|
49
49
|
};
|
|
50
|
-
exports.
|
|
50
|
+
exports.hux = {
|
|
51
51
|
confirm: confirm_1.confirm,
|
|
52
52
|
prompt: prompt_1.prompt,
|
|
53
53
|
styledHeader: styled_header_1.styledHeader,
|