@heroku/heroku-cli-util 9.0.0-beta.3 → 9.0.1-beta.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 +84 -23
- package/dist/index.d.ts +7 -3
- package/dist/index.js +7 -3
- package/dist/ux/styled-json.d.ts +1 -1
- package/dist/ux/styled-json.js +2 -2
- package/dist/ux/table.d.ts +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,50 +19,111 @@ 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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
hux.styledObject({ foo: 'bar' });
|
|
37
|
+
|
|
38
|
+
// Table output
|
|
39
|
+
hux.table([
|
|
40
|
+
{name: 'Alice', age: 30},
|
|
41
|
+
{name: 'Bob', age: 25},
|
|
42
|
+
], {
|
|
43
|
+
name: {header: 'Name'},
|
|
44
|
+
age: {header: 'Age'},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Wait indicator
|
|
48
|
+
const stop = hux.wait('Processing...');
|
|
49
|
+
// ...do async work...
|
|
50
|
+
stop();
|
|
46
51
|
```
|
|
47
52
|
|
|
48
53
|
### User Interaction
|
|
49
54
|
|
|
50
55
|
```js
|
|
51
|
-
import {
|
|
52
|
-
const name = await prompt('What is your name?');
|
|
56
|
+
import { hux } from '@heroku/heroku-cli-util';
|
|
53
57
|
|
|
54
|
-
|
|
55
|
-
const proceed = await confirm('Continue?');
|
|
58
|
+
const name = await hux.prompt('What is your name?');
|
|
59
|
+
const proceed = await hux.confirm('Continue?');
|
|
56
60
|
```
|
|
57
61
|
|
|
58
62
|
### Test Helpers
|
|
59
63
|
|
|
60
64
|
```js
|
|
61
|
-
import {
|
|
62
|
-
|
|
65
|
+
import { testHelpers } from '@heroku/heroku-cli-util';
|
|
66
|
+
|
|
67
|
+
testHelpers.initCliTest();
|
|
68
|
+
|
|
69
|
+
testHelpers.setupStdoutStderr();
|
|
70
|
+
// ...run your CLI code...
|
|
71
|
+
const output = testHelpers.stdout();
|
|
72
|
+
const errorOutput = testHelpers.stderr();
|
|
73
|
+
testHelpers.restoreStdoutStderr();
|
|
74
|
+
|
|
75
|
+
testHelpers.expectOutput(output, 'expected output');
|
|
76
|
+
|
|
77
|
+
// Run a command (see docs for details)
|
|
78
|
+
// await testHelpers.runCommand(MyCommand, ['arg1', 'arg2']);
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Types
|
|
82
|
+
|
|
83
|
+
```js
|
|
84
|
+
import { types } from '@heroku/heroku-cli-util';
|
|
85
|
+
|
|
86
|
+
// Error types
|
|
87
|
+
try {
|
|
88
|
+
throw new types.errors.AmbiguousError([{ name: 'foo' }, { name: 'bar' }], 'addon');
|
|
89
|
+
} catch (err) {
|
|
90
|
+
if (err instanceof types.errors.AmbiguousError) {
|
|
91
|
+
console.error('Ambiguous:', err.message);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
throw new types.errors.NotFound();
|
|
97
|
+
} catch (err) {
|
|
98
|
+
if (err instanceof types.errors.NotFound) {
|
|
99
|
+
console.error('Not found:', err.message);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// PG types (for TypeScript)
|
|
104
|
+
/**
|
|
105
|
+
* types.pg.AddOnAttachmentWithConfigVarsAndPlan
|
|
106
|
+
* types.pg.AddOnWithRelatedData
|
|
107
|
+
* types.pg.ConnectionDetails
|
|
108
|
+
* types.pg.ConnectionDetailsWithAttachment
|
|
109
|
+
* types.pg.Link
|
|
110
|
+
* types.pg.TunnelConfig
|
|
111
|
+
*/
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Database and Utility Helpers
|
|
115
|
+
|
|
116
|
+
```js
|
|
117
|
+
import { utils } from '@heroku/heroku-cli-util';
|
|
118
|
+
|
|
119
|
+
// Get Heroku Postgres database connection details (requires APIClient from @heroku-cli/command)
|
|
120
|
+
// const db = await utils.pg.databases(herokuApiClient, 'my-app', 'DATABASE_URL');
|
|
121
|
+
|
|
122
|
+
// Get Heroku Postgres host
|
|
123
|
+
const host = utils.pg.host();
|
|
63
124
|
|
|
64
|
-
|
|
65
|
-
//
|
|
125
|
+
// Run a query (requires a ConnectionDetails object)
|
|
126
|
+
// const result = await utils.pg.psql.exec(db, 'SELECT 1');
|
|
66
127
|
```
|
|
67
128
|
|
|
68
129
|
## Development
|
package/dist/index.d.ts
CHANGED
|
@@ -10,8 +10,10 @@ import { exec } from './utils/pg/psql';
|
|
|
10
10
|
import { confirm } from './ux/confirm';
|
|
11
11
|
import { prompt } from './ux/prompt';
|
|
12
12
|
import { styledHeader } from './ux/styled-header';
|
|
13
|
-
import {
|
|
13
|
+
import { styledJSON } from './ux/styled-json';
|
|
14
14
|
import { styledObject } from './ux/styled-object';
|
|
15
|
+
import { table } from './ux/table';
|
|
16
|
+
import { wait } from './ux/wait';
|
|
15
17
|
export declare const testHelpers: {
|
|
16
18
|
expectOutput: (actual: string, expected: string) => Chai.Assertion;
|
|
17
19
|
initCliTest: typeof initCliTest;
|
|
@@ -44,10 +46,12 @@ export declare const utils: {
|
|
|
44
46
|
};
|
|
45
47
|
};
|
|
46
48
|
};
|
|
47
|
-
export declare const
|
|
49
|
+
export declare const hux: {
|
|
48
50
|
confirm: typeof confirm;
|
|
49
51
|
prompt: typeof prompt;
|
|
50
52
|
styledHeader: typeof styledHeader;
|
|
51
|
-
|
|
53
|
+
styledJSON: typeof styledJSON;
|
|
52
54
|
styledObject: typeof styledObject;
|
|
55
|
+
table: typeof table;
|
|
56
|
+
wait: typeof wait;
|
|
53
57
|
};
|
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");
|
|
@@ -15,6 +15,8 @@ const prompt_1 = require("./ux/prompt");
|
|
|
15
15
|
const styled_header_1 = require("./ux/styled-header");
|
|
16
16
|
const styled_json_1 = require("./ux/styled-json");
|
|
17
17
|
const styled_object_1 = require("./ux/styled-object");
|
|
18
|
+
const table_1 = require("./ux/table");
|
|
19
|
+
const wait_1 = require("./ux/wait");
|
|
18
20
|
exports.testHelpers = {
|
|
19
21
|
expectOutput: expect_output_1.default,
|
|
20
22
|
initCliTest: init_1.initCliTest,
|
|
@@ -47,10 +49,12 @@ exports.utils = {
|
|
|
47
49
|
},
|
|
48
50
|
},
|
|
49
51
|
};
|
|
50
|
-
exports.
|
|
52
|
+
exports.hux = {
|
|
51
53
|
confirm: confirm_1.confirm,
|
|
52
54
|
prompt: prompt_1.prompt,
|
|
53
55
|
styledHeader: styled_header_1.styledHeader,
|
|
54
|
-
|
|
56
|
+
styledJSON: styled_json_1.styledJSON,
|
|
55
57
|
styledObject: styled_object_1.styledObject,
|
|
58
|
+
table: table_1.table,
|
|
59
|
+
wait: wait_1.wait,
|
|
56
60
|
};
|
package/dist/ux/styled-json.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function styledJSON(obj: unknown): void;
|
package/dist/ux/styled-json.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.styledJSON = styledJSON;
|
|
4
4
|
const core_1 = require("@oclif/core");
|
|
5
|
-
function
|
|
5
|
+
function styledJSON(obj) {
|
|
6
6
|
return core_1.ux.styledJSON(obj);
|
|
7
7
|
}
|
package/dist/ux/table.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function table<T extends Record<string, unknown>>(data: T[], columns: Parameters<typeof
|
|
1
|
+
import { table as cliTable } from '@oclif/core/lib/cli-ux';
|
|
2
|
+
export declare function table<T extends Record<string, unknown>>(data: T[], columns: Parameters<typeof cliTable>[1], options?: Parameters<typeof cliTable>[2]): void;
|