Comparing version 1.23.1 to 1.23.2
@@ -9,7 +9,6 @@ import { join } from 'node:path'; | ||
import { CREDENTIALS_FILE } from '../config.js'; | ||
import { showHelpMiddleware } from '../help.js'; | ||
export const command = 'auth'; | ||
export const aliases = ['login']; | ||
export const describe = 'Authenticate'; | ||
export const builder = (yargs) => yargs.middleware(showHelpMiddleware(yargs, true)); | ||
export const builder = (yargs) => yargs; | ||
export const handler = async (args) => { | ||
@@ -47,3 +46,3 @@ await authFlow(args); | ||
export const ensureAuth = async (props) => { | ||
if (props._.length === 0) { | ||
if (props._.length === 0 || props.help) { | ||
return; | ||
@@ -50,0 +49,0 @@ } |
@@ -7,3 +7,2 @@ import { EndpointType } from '@neondatabase/api-client'; | ||
import { looksLikeBranchId, looksLikeLSN, looksLikeTimestamp, } from '../utils/formats.js'; | ||
import { showHelpMiddleware } from '../help.js'; | ||
import { psql } from '../utils/psql.js'; | ||
@@ -72,4 +71,3 @@ const BRANCH_FIELDS = [ | ||
.command('delete <id|name>', 'Delete a branch', (yargs) => yargs, async (args) => await deleteBranch(args)) | ||
.command('get <id|name>', 'Get a branch', (yargs) => yargs, async (args) => await get(args)) | ||
.middleware(showHelpMiddleware(argv), true); | ||
.command('get <id|name>', 'Get a branch', (yargs) => yargs, async (args) => await get(args)); | ||
export const handler = (args) => { | ||
@@ -76,0 +74,0 @@ return args; |
import { EndpointType } from '@neondatabase/api-client'; | ||
import { branchIdFromProps, fillSingleProject } from '../utils/enrichers.js'; | ||
import { showHelpMiddleware } from '../help.js'; | ||
import { writer } from '../writer.js'; | ||
@@ -12,3 +11,2 @@ import { psql } from '../utils/psql.js'; | ||
.usage('$0 connection-string [branch] [options]') | ||
.middleware(showHelpMiddleware(argv, true)) | ||
.positional('branch', { | ||
@@ -15,0 +13,0 @@ describe: 'Branch name or id. If ommited will use the primary branch', |
import { retryOnLock } from '../api.js'; | ||
import { branchIdFromProps, fillSingleProject } from '../utils/enrichers.js'; | ||
import { writer } from '../writer.js'; | ||
import { showHelpMiddleware } from '../help.js'; | ||
const DATABASE_FIELDS = ['name', 'owner_name', 'created_at']; | ||
@@ -11,3 +10,2 @@ export const command = 'databases'; | ||
.usage('$0 databases <sub-command> [options]') | ||
.middleware(showHelpMiddleware(argv)) | ||
.options({ | ||
@@ -14,0 +12,0 @@ 'project-id': { |
import { fillSingleProject } from '../utils/enrichers.js'; | ||
import { writer } from '../writer.js'; | ||
import { showHelpMiddleware } from '../help.js'; | ||
const OPERATIONS_FIELDS = ['id', 'action', 'status', 'created_at']; | ||
@@ -10,3 +9,2 @@ export const command = 'operations'; | ||
.usage('$0 operations <sub-command> [options]') | ||
.middleware(showHelpMiddleware(argv)) | ||
.options({ | ||
@@ -13,0 +11,0 @@ 'project-id': { |
@@ -1,2 +0,1 @@ | ||
import { showHelpMiddleware } from '../help.js'; | ||
import { log } from '../log.js'; | ||
@@ -23,3 +22,2 @@ import { projectCreateRequest } from '../parameters.gen.js'; | ||
.usage('$0 projects <sub-command> [options]') | ||
.middleware(showHelpMiddleware(argv)) | ||
.command('list', 'List projects', (yargs) => yargs, async (args) => { | ||
@@ -26,0 +24,0 @@ await list(args); |
import { retryOnLock } from '../api.js'; | ||
import { branchIdFromProps, fillSingleProject } from '../utils/enrichers.js'; | ||
import { writer } from '../writer.js'; | ||
import { showHelpMiddleware } from '../help.js'; | ||
const ROLES_FIELDS = ['name', 'created_at']; | ||
@@ -10,3 +9,2 @@ export const command = 'roles'; | ||
export const builder = (argv) => argv | ||
.middleware(showHelpMiddleware(argv)) | ||
.usage('$0 roles <sub-command> [options]') | ||
@@ -13,0 +11,0 @@ .options({ |
@@ -1,3 +0,1 @@ | ||
import yargs from 'yargs'; | ||
import { showHelpMiddleware } from '../help.js'; | ||
import { updateContextFile } from '../context.js'; | ||
@@ -8,3 +6,2 @@ import { branchIdFromProps } from '../utils/enrichers.js'; | ||
export const builder = (argv) => argv | ||
.middleware(showHelpMiddleware(yargs, true)) | ||
.usage('$0 set-context [options]') | ||
@@ -11,0 +8,0 @@ .options({ |
@@ -1,6 +0,5 @@ | ||
import { showHelpMiddleware } from '../help.js'; | ||
import { writer } from '../writer.js'; | ||
export const command = 'me'; | ||
export const describe = 'Show current user'; | ||
export const builder = (yargs) => yargs.middleware(showHelpMiddleware(yargs, true)); | ||
export const builder = (yargs) => yargs; | ||
export const handler = async (args) => { | ||
@@ -7,0 +6,0 @@ await me(args); |
@@ -115,6 +115,1 @@ import cliui from 'cliui'; | ||
}; | ||
export const showHelpMiddleware = (argv, ignoreSubCmdPresence) => async (args) => { | ||
if ((!ignoreSubCmdPresence && args._.length === 1) || args.help) { | ||
await showHelp(argv); | ||
} | ||
}; |
22
index.js
@@ -28,2 +28,3 @@ import { basename } from 'node:path'; | ||
import { currentContextFile, enrichFromContext } from './context.js'; | ||
const NO_SUBCOMMANDS_VERBS = ['auth', 'me', 'cs', 'connection-string', 'set-context']; | ||
let builder = yargs(hideBin(process.argv)); | ||
@@ -95,2 +96,15 @@ builder = builder | ||
.middleware((args) => fillInArgs(args), true) | ||
.help(false) | ||
.group('help', 'Global options:') | ||
.option('help', { | ||
describe: 'Show help', | ||
type: 'boolean', | ||
default: false, | ||
}) | ||
.alias('help', 'h') | ||
.middleware(async (args) => { | ||
if (args.help || args._.length === 1 && !NO_SUBCOMMANDS_VERBS.includes(args._[0])) { | ||
await showHelp(builder); | ||
} | ||
}) | ||
.middleware(ensureAuth) | ||
@@ -109,10 +123,2 @@ .middleware(enrichFromContext) | ||
.alias('version', 'v') | ||
.help(false) | ||
.group('help', 'Global options:') | ||
.option('help', { | ||
describe: 'Show help', | ||
type: 'boolean', | ||
default: false, | ||
}) | ||
.alias('help', 'h') | ||
.completion() | ||
@@ -119,0 +125,0 @@ .scriptName(basename(process.argv[1]) === 'neon' ? 'neon' : 'neonctl') |
@@ -8,3 +8,3 @@ { | ||
"type": "module", | ||
"version": "1.23.1", | ||
"version": "1.23.2", | ||
"description": "CLI tool for NeonDB Cloud management", | ||
@@ -11,0 +11,0 @@ "main": "index.js", |
@@ -43,3 +43,7 @@ // returns the next string if matches the given matcher, | ||
}; | ||
export const splitColumns = (line) => line.trim().split(/\s{2,}/); | ||
export const splitColumns = (line) => { | ||
const result = line.trim().split(/\s{2,}/); | ||
result[1] = result[1] ?? ''; | ||
return result; | ||
}; | ||
export const drawPointer = (width) => { | ||
@@ -46,0 +50,0 @@ const result = []; |
105275
2685