neonctl 1.23.1 → 1.23.3
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/commands/auth.js +2 -3
- package/commands/branches.js +1 -3
- package/commands/connection_string.js +0 -2
- package/commands/databases.js +0 -2
- package/commands/operations.js +0 -2
- package/commands/projects.js +0 -2
- package/commands/roles.js +0 -2
- package/commands/set_context.js +0 -3
- package/commands/user.js +1 -2
- package/help.js +5 -5
- package/index.js +14 -8
- package/package.json +1 -1
- package/utils/ui.js +5 -1
package/commands/auth.js
CHANGED
|
@@ -6,11 +6,10 @@ import { log } from '../log.js';
|
|
|
6
6
|
import { getApiClient } from '../api.js';
|
|
7
7
|
import { isCi } from '../env.js';
|
|
8
8
|
import { CREDENTIALS_FILE } from '../config.js';
|
|
9
|
-
import { showHelpMiddleware } from '../help.js';
|
|
10
9
|
export const command = 'auth';
|
|
11
10
|
export const aliases = ['login'];
|
|
12
11
|
export const describe = 'Authenticate';
|
|
13
|
-
export const builder = (yargs) => yargs
|
|
12
|
+
export const builder = (yargs) => yargs;
|
|
14
13
|
export const handler = async (args) => {
|
|
15
14
|
await authFlow(args);
|
|
16
15
|
};
|
|
@@ -43,7 +42,7 @@ const preserveCredentials = async (path, credentials, apiClient) => {
|
|
|
43
42
|
});
|
|
44
43
|
};
|
|
45
44
|
export const ensureAuth = async (props) => {
|
|
46
|
-
if (props._.length === 0) {
|
|
45
|
+
if (props._.length === 0 || props.help) {
|
|
47
46
|
return;
|
|
48
47
|
}
|
|
49
48
|
if (props.apiKey || props._[0] === 'auth') {
|
package/commands/branches.js
CHANGED
|
@@ -4,7 +4,6 @@ import { branchCreateRequest, branchCreateRequestEndpointOptions, } from '../par
|
|
|
4
4
|
import { retryOnLock } from '../api.js';
|
|
5
5
|
import { branchIdFromProps, fillSingleProject } from '../utils/enrichers.js';
|
|
6
6
|
import { looksLikeBranchId, looksLikeLSN, looksLikeTimestamp, } from '../utils/formats.js';
|
|
7
|
-
import { showHelpMiddleware } from '../help.js';
|
|
8
7
|
import { psql } from '../utils/psql.js';
|
|
9
8
|
const BRANCH_FIELDS = [
|
|
10
9
|
'id',
|
|
@@ -68,8 +67,7 @@ export const builder = (argv) => argv
|
|
|
68
67
|
},
|
|
69
68
|
}), async (args) => await addCompute(args))
|
|
70
69
|
.command('delete <id|name>', 'Delete a branch', (yargs) => yargs, async (args) => await deleteBranch(args))
|
|
71
|
-
.command('get <id|name>', 'Get a branch', (yargs) => yargs, async (args) => await get(args))
|
|
72
|
-
.middleware(showHelpMiddleware(argv), true);
|
|
70
|
+
.command('get <id|name>', 'Get a branch', (yargs) => yargs, async (args) => await get(args));
|
|
73
71
|
export const handler = (args) => {
|
|
74
72
|
return args;
|
|
75
73
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { EndpointType } from '@neondatabase/api-client';
|
|
2
2
|
import { branchIdFromProps, fillSingleProject } from '../utils/enrichers.js';
|
|
3
|
-
import { showHelpMiddleware } from '../help.js';
|
|
4
3
|
import { writer } from '../writer.js';
|
|
5
4
|
import { psql } from '../utils/psql.js';
|
|
6
5
|
export const command = 'connection-string [branch]';
|
|
@@ -9,7 +8,6 @@ export const describe = 'Get connection string';
|
|
|
9
8
|
export const builder = (argv) => {
|
|
10
9
|
return argv
|
|
11
10
|
.usage('$0 connection-string [branch] [options]')
|
|
12
|
-
.middleware(showHelpMiddleware(argv, true))
|
|
13
11
|
.positional('branch', {
|
|
14
12
|
describe: 'Branch name or id. If ommited will use the primary branch',
|
|
15
13
|
type: 'string',
|
package/commands/databases.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { retryOnLock } from '../api.js';
|
|
2
2
|
import { branchIdFromProps, fillSingleProject } from '../utils/enrichers.js';
|
|
3
3
|
import { writer } from '../writer.js';
|
|
4
|
-
import { showHelpMiddleware } from '../help.js';
|
|
5
4
|
const DATABASE_FIELDS = ['name', 'owner_name', 'created_at'];
|
|
6
5
|
export const command = 'databases';
|
|
7
6
|
export const describe = 'Manage databases';
|
|
8
7
|
export const aliases = ['database', 'db'];
|
|
9
8
|
export const builder = (argv) => argv
|
|
10
9
|
.usage('$0 databases <sub-command> [options]')
|
|
11
|
-
.middleware(showHelpMiddleware(argv))
|
|
12
10
|
.options({
|
|
13
11
|
'project-id': {
|
|
14
12
|
describe: 'Project ID',
|
package/commands/operations.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { fillSingleProject } from '../utils/enrichers.js';
|
|
2
2
|
import { writer } from '../writer.js';
|
|
3
|
-
import { showHelpMiddleware } from '../help.js';
|
|
4
3
|
const OPERATIONS_FIELDS = ['id', 'action', 'status', 'created_at'];
|
|
5
4
|
export const command = 'operations';
|
|
6
5
|
export const describe = 'Manage operations';
|
|
7
6
|
export const aliases = ['operation'];
|
|
8
7
|
export const builder = (argv) => argv
|
|
9
8
|
.usage('$0 operations <sub-command> [options]')
|
|
10
|
-
.middleware(showHelpMiddleware(argv))
|
|
11
9
|
.options({
|
|
12
10
|
'project-id': {
|
|
13
11
|
describe: 'Project ID',
|
package/commands/projects.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { showHelpMiddleware } from '../help.js';
|
|
2
1
|
import { log } from '../log.js';
|
|
3
2
|
import { projectCreateRequest } from '../parameters.gen.js';
|
|
4
3
|
import { writer } from '../writer.js';
|
|
@@ -20,7 +19,6 @@ export const aliases = ['project'];
|
|
|
20
19
|
export const builder = (argv) => {
|
|
21
20
|
return argv
|
|
22
21
|
.usage('$0 projects <sub-command> [options]')
|
|
23
|
-
.middleware(showHelpMiddleware(argv))
|
|
24
22
|
.command('list', 'List projects', (yargs) => yargs, async (args) => {
|
|
25
23
|
await list(args);
|
|
26
24
|
})
|
package/commands/roles.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import { retryOnLock } from '../api.js';
|
|
2
2
|
import { branchIdFromProps, fillSingleProject } from '../utils/enrichers.js';
|
|
3
3
|
import { writer } from '../writer.js';
|
|
4
|
-
import { showHelpMiddleware } from '../help.js';
|
|
5
4
|
const ROLES_FIELDS = ['name', 'created_at'];
|
|
6
5
|
export const command = 'roles';
|
|
7
6
|
export const describe = 'Manage roles';
|
|
8
7
|
export const aliases = ['role'];
|
|
9
8
|
export const builder = (argv) => argv
|
|
10
|
-
.middleware(showHelpMiddleware(argv))
|
|
11
9
|
.usage('$0 roles <sub-command> [options]')
|
|
12
10
|
.options({
|
|
13
11
|
'project-id': {
|
package/commands/set_context.js
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import yargs from 'yargs';
|
|
2
|
-
import { showHelpMiddleware } from '../help.js';
|
|
3
1
|
import { updateContextFile } from '../context.js';
|
|
4
2
|
import { branchIdFromProps } from '../utils/enrichers.js';
|
|
5
3
|
export const command = 'set-context';
|
|
6
4
|
export const describe = 'Set the current context';
|
|
7
5
|
export const builder = (argv) => argv
|
|
8
|
-
.middleware(showHelpMiddleware(yargs, true))
|
|
9
6
|
.usage('$0 set-context [options]')
|
|
10
7
|
.options({
|
|
11
8
|
'project-id': {
|
package/commands/user.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { showHelpMiddleware } from '../help.js';
|
|
2
1
|
import { writer } from '../writer.js';
|
|
3
2
|
export const command = 'me';
|
|
4
3
|
export const describe = 'Show current user';
|
|
5
|
-
export const builder = (yargs) => yargs
|
|
4
|
+
export const builder = (yargs) => yargs;
|
|
6
5
|
export const handler = async (args) => {
|
|
7
6
|
await me(args);
|
|
8
7
|
};
|
package/help.js
CHANGED
|
@@ -23,6 +23,11 @@ const formatHelp = (help) => {
|
|
|
23
23
|
});
|
|
24
24
|
commandsBlock.forEach((line) => {
|
|
25
25
|
const [command, description] = splitColumns(line);
|
|
26
|
+
// patch the previous command if it was multiline
|
|
27
|
+
if (!description && ui.rows.length > 1) {
|
|
28
|
+
ui.rows[ui.rows.length - 2][0].text += command;
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
26
31
|
ui.div(chalk.cyan(command));
|
|
27
32
|
ui.div({
|
|
28
33
|
text: chalk.gray(drawPointer(SPACE_WIDTH)),
|
|
@@ -112,8 +117,3 @@ export const showHelp = async (argv) => {
|
|
|
112
117
|
process.stderr.write(formatHelp(help).join('\n') + '\n');
|
|
113
118
|
process.exit(0);
|
|
114
119
|
};
|
|
115
|
-
export const showHelpMiddleware = (argv, ignoreSubCmdPresence) => async (args) => {
|
|
116
|
-
if ((!ignoreSubCmdPresence && args._.length === 1) || args.help) {
|
|
117
|
-
await showHelp(argv);
|
|
118
|
-
}
|
|
119
|
-
};
|
package/index.js
CHANGED
|
@@ -25,6 +25,7 @@ import { isAxiosError } from 'axios';
|
|
|
25
25
|
import { matchErrorCode } from './errors.js';
|
|
26
26
|
import { showHelp } from './help.js';
|
|
27
27
|
import { currentContextFile, enrichFromContext } from './context.js';
|
|
28
|
+
const NO_SUBCOMMANDS_VERBS = ['auth', 'me', 'cs', 'connection-string', 'set-context'];
|
|
28
29
|
let builder = yargs(hideBin(process.argv));
|
|
29
30
|
builder = builder
|
|
30
31
|
.scriptName(pkg.name)
|
|
@@ -91,6 +92,19 @@ builder = builder
|
|
|
91
92
|
},
|
|
92
93
|
})
|
|
93
94
|
.middleware((args) => fillInArgs(args), true)
|
|
95
|
+
.help(false)
|
|
96
|
+
.group('help', 'Global options:')
|
|
97
|
+
.option('help', {
|
|
98
|
+
describe: 'Show help',
|
|
99
|
+
type: 'boolean',
|
|
100
|
+
default: false,
|
|
101
|
+
})
|
|
102
|
+
.alias('help', 'h')
|
|
103
|
+
.middleware(async (args) => {
|
|
104
|
+
if (args.help || args._.length === 1 && !NO_SUBCOMMANDS_VERBS.includes(args._[0])) {
|
|
105
|
+
await showHelp(builder);
|
|
106
|
+
}
|
|
107
|
+
})
|
|
94
108
|
.middleware(ensureAuth)
|
|
95
109
|
.middleware(enrichFromContext)
|
|
96
110
|
.command(commands)
|
|
@@ -104,14 +118,6 @@ builder = builder
|
|
|
104
118
|
.middleware(analyticsMiddleware, true)
|
|
105
119
|
.group('version', 'Global options:')
|
|
106
120
|
.alias('version', 'v')
|
|
107
|
-
.help(false)
|
|
108
|
-
.group('help', 'Global options:')
|
|
109
|
-
.option('help', {
|
|
110
|
-
describe: 'Show help',
|
|
111
|
-
type: 'boolean',
|
|
112
|
-
default: false,
|
|
113
|
-
})
|
|
114
|
-
.alias('help', 'h')
|
|
115
121
|
.completion()
|
|
116
122
|
.scriptName(basename(process.argv[1]) === 'neon' ? 'neon' : 'neonctl')
|
|
117
123
|
.fail(async (msg, err) => {
|
package/package.json
CHANGED
package/utils/ui.js
CHANGED
|
@@ -40,7 +40,11 @@ export const consumeBlockIfMatches = (lines, matcher) => {
|
|
|
40
40
|
}
|
|
41
41
|
return result;
|
|
42
42
|
};
|
|
43
|
-
export const splitColumns = (line) =>
|
|
43
|
+
export const splitColumns = (line) => {
|
|
44
|
+
const result = line.trim().split(/\s{2,}/);
|
|
45
|
+
result[1] = result[1] ?? '';
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
44
48
|
export const drawPointer = (width) => {
|
|
45
49
|
const result = [];
|
|
46
50
|
result.push('└');
|