Comparing version 0.2.1 to 0.3.0
{ | ||
"name": "neonctl", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "CLI tool for NeonDB Cloud management", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -41,3 +41,3 @@ "use strict"; | ||
const CREDENTIALS_FILE = 'credentials.json'; | ||
const authFlow = ({ configDir, oauthHost, clientId, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
const authFlow = ({ 'config-dir': configDir, 'oauth-host': oauthHost, 'client-id': clientId, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (!clientId) { | ||
@@ -61,3 +61,3 @@ throw new Error('Missing client id'); | ||
} | ||
const credentialsPath = (0, node_path_1.join)(props.configDir, CREDENTIALS_FILE); | ||
const credentialsPath = (0, node_path_1.join)(props['config-dir'], CREDENTIALS_FILE); | ||
if ((0, node_fs_1.existsSync)(credentialsPath)) { | ||
@@ -67,11 +67,12 @@ try { | ||
props.token = token; | ||
return; | ||
} | ||
catch (e) { | ||
throw new Error('Invalid credentials, please re-authenticate'); | ||
yield (0, exports.authFlow)(props); | ||
} | ||
} | ||
else { | ||
throw new Error('No credentials found, please authenticate'); | ||
yield (0, exports.authFlow)(props); | ||
} | ||
}); | ||
exports.ensureAuth = ensureAuth; |
@@ -17,3 +17,3 @@ "use strict"; | ||
exports.defaultDir = (0, node_path_1.join)(process.cwd(), DIR_NAME); | ||
const ensureConfigDir = ({ configDir, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
const ensureConfigDir = ({ 'config-dir': configDir, }) => __awaiter(void 0, void 0, void 0, function* () { | ||
if (!(0, node_fs_1.existsSync)(configDir)) { | ||
@@ -20,0 +20,0 @@ (0, node_fs_1.mkdirSync)(configDir); |
@@ -44,9 +44,7 @@ "use strict"; | ||
const log_1 = require("./log"); | ||
const wrapWithHelp = (yargs) => __awaiter(void 0, void 0, void 0, function* () { | ||
const { _ } = yield yargs.argv; | ||
if (_.length === 1) { | ||
const showHelpMiddleware = (argv) => { | ||
if (argv._.length === 1) { | ||
yargs.showHelp(); | ||
} | ||
return yargs; | ||
}); | ||
}; | ||
const builder = yargs | ||
@@ -56,3 +54,7 @@ .scriptName(package_json_1.default.name) | ||
.help() | ||
.option('apiHost', { | ||
.option('json', { | ||
describe: 'Set output format to JSON', | ||
type: 'boolean', | ||
}) | ||
.option('api-host', { | ||
describe: 'The API host', | ||
@@ -62,3 +64,3 @@ default: 'https://console.neon.tech', | ||
// Setup config directory | ||
.option('configDir', { | ||
.option('config-dir', { | ||
describe: 'Path to config directory', | ||
@@ -70,12 +72,12 @@ type: 'string', | ||
// Auth flow | ||
.command('auth', 'Authenticate user', (yargs) => yargs | ||
.option('oauthHost', { | ||
.option('oauth-host', { | ||
description: 'URL to Neon OAUTH host', | ||
default: 'https://oauth2.neon.tech', | ||
}) | ||
.option('clientId', { | ||
.option('client-id', { | ||
description: 'OAuth client id', | ||
type: 'string', | ||
demandOption: true, | ||
}), (args) => __awaiter(void 0, void 0, void 0, function* () { | ||
default: 'neonctl', | ||
}) | ||
.command('auth', 'Authenticate user', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () { | ||
(yield Promise.resolve().then(() => __importStar(require('./commands/auth')))).authFlow(args); | ||
@@ -93,10 +95,19 @@ })) | ||
})) | ||
.command('projects', 'Manage projects', (yargs) => wrapWithHelp(yargs | ||
.usage('usage: $0 projects <cmd> [args]') | ||
.command('list', 'List projects', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () { | ||
yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).list(args); | ||
.command('projects', 'Manage projects', (yargs) => __awaiter(void 0, void 0, void 0, function* () { | ||
yargs | ||
.usage('usage: $0 projects <cmd> [args]') | ||
// .command( | ||
// 'list', | ||
// 'List projects', | ||
// (yargs) => yargs, | ||
// async (args) => { | ||
// await (await import('./commands/projects')).list(args); | ||
// } | ||
// ) | ||
.command('create', 'Create a project', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () { | ||
yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).create(args); | ||
})) | ||
.middleware(showHelpMiddleware); | ||
})) | ||
.command('create', 'Create a project', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () { | ||
yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).create(args); | ||
})))) | ||
.strict() | ||
.fail((msg, err) => __awaiter(void 0, void 0, void 0, function* () { | ||
@@ -112,5 +123,6 @@ if (err instanceof gateway_1.ApiError) { | ||
(() => __awaiter(void 0, void 0, void 0, function* () { | ||
if ((yield builder.argv)._.length === 0) { | ||
const args = yield builder.argv; | ||
if (args._.length === 0) { | ||
yargs.showHelp(); | ||
} | ||
}))(); |
28526
452