neonctl 0.2.1 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "neonctl",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "CLI tool for NeonDB Cloud management",
5
5
  "main": "index.js",
6
6
  "author": "NeonDB",
@@ -38,7 +38,7 @@ const node_fs_1 = require("node:fs");
38
38
  const auth_1 = require("../auth");
39
39
  const log_1 = require("../log");
40
40
  const CREDENTIALS_FILE = 'credentials.json';
41
- const authFlow = ({ configDir, oauthHost, clientId, }) => __awaiter(void 0, void 0, void 0, function* () {
41
+ const authFlow = ({ 'config-dir': configDir, 'oauth-host': oauthHost, 'client-id': clientId, }) => __awaiter(void 0, void 0, void 0, function* () {
42
42
  if (!clientId) {
43
43
  throw new Error('Missing client id');
44
44
  }
@@ -57,18 +57,19 @@ const ensureAuth = (props) => __awaiter(void 0, void 0, void 0, function* () {
57
57
  if (props._[0] === 'auth') {
58
58
  return;
59
59
  }
60
- const credentialsPath = (0, node_path_1.join)(props.configDir, CREDENTIALS_FILE);
60
+ const credentialsPath = (0, node_path_1.join)(props['config-dir'], CREDENTIALS_FILE);
61
61
  if ((0, node_fs_1.existsSync)(credentialsPath)) {
62
62
  try {
63
63
  const token = (yield Promise.resolve().then(() => __importStar(require(credentialsPath)))).access_token;
64
64
  props.token = token;
65
+ return;
65
66
  }
66
67
  catch (e) {
67
- throw new Error('Invalid credentials, please re-authenticate');
68
+ yield (0, exports.authFlow)(props);
68
69
  }
69
70
  }
70
71
  else {
71
- throw new Error('No credentials found, please authenticate');
72
+ yield (0, exports.authFlow)(props);
72
73
  }
73
74
  });
74
75
  exports.ensureAuth = ensureAuth;
package/src/config.js CHANGED
@@ -14,7 +14,7 @@ const node_path_1 = require("node:path");
14
14
  const node_fs_1 = require("node:fs");
15
15
  const DIR_NAME = '.neonctl';
16
16
  exports.defaultDir = (0, node_path_1.join)(process.cwd(), DIR_NAME);
17
- const ensureConfigDir = ({ configDir, }) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const ensureConfigDir = ({ 'config-dir': configDir, }) => __awaiter(void 0, void 0, void 0, function* () {
18
18
  if (!(0, node_fs_1.existsSync)(configDir)) {
19
19
  (0, node_fs_1.mkdirSync)(configDir);
20
20
  }
package/src/index.js CHANGED
@@ -41,39 +41,41 @@ const gateway_1 = require("./api/gateway");
41
41
  const auth_1 = require("./commands/auth");
42
42
  const config_1 = require("./config");
43
43
  const log_1 = require("./log");
44
- const wrapWithHelp = (yargs) => __awaiter(void 0, void 0, void 0, function* () {
45
- const { _ } = yield yargs.argv;
46
- if (_.length === 1) {
44
+ const showHelpMiddleware = (argv) => {
45
+ if (argv._.length === 1) {
47
46
  yargs.showHelp();
48
47
  }
49
- return yargs;
50
- });
48
+ };
51
49
  const builder = yargs
52
50
  .scriptName(package_json_1.default.name)
53
51
  .usage('usage: $0 <cmd> [args]')
54
52
  .help()
55
- .option('apiHost', {
53
+ .option('json', {
54
+ describe: 'Set output format to JSON',
55
+ type: 'boolean',
56
+ })
57
+ .option('api-host', {
56
58
  describe: 'The API host',
57
59
  default: 'https://console.neon.tech',
58
60
  })
59
61
  // Setup config directory
60
- .option('configDir', {
62
+ .option('config-dir', {
61
63
  describe: 'Path to config directory',
62
64
  type: 'string',
63
65
  default: config_1.defaultDir,
64
66
  })
65
67
  .middleware(config_1.ensureConfigDir)
66
68
  // Auth flow
67
- .command('auth', 'Authenticate user', (yargs) => yargs
68
- .option('oauthHost', {
69
+ .option('oauth-host', {
69
70
  description: 'URL to Neon OAUTH host',
70
71
  default: 'https://oauth2.neon.tech',
71
72
  })
72
- .option('clientId', {
73
+ .option('client-id', {
73
74
  description: 'OAuth client id',
74
75
  type: 'string',
75
- demandOption: true,
76
- }), (args) => __awaiter(void 0, void 0, void 0, function* () {
76
+ default: 'neonctl',
77
+ })
78
+ .command('auth', 'Authenticate user', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
77
79
  (yield Promise.resolve().then(() => __importStar(require('./commands/auth')))).authFlow(args);
78
80
  }))
79
81
  // Ensure auth token
@@ -86,14 +88,23 @@ const builder = yargs
86
88
  .command('me', 'Get user info', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
87
89
  yield (yield Promise.resolve().then(() => __importStar(require('./commands/users')))).me(args);
88
90
  }))
89
- .command('projects', 'Manage projects', (yargs) => wrapWithHelp(yargs
90
- .usage('usage: $0 projects <cmd> [args]')
91
- .command('list', 'List projects', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
92
- yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).list(args);
91
+ .command('projects', 'Manage projects', (yargs) => __awaiter(void 0, void 0, void 0, function* () {
92
+ yargs
93
+ .usage('usage: $0 projects <cmd> [args]')
94
+ // .command(
95
+ // 'list',
96
+ // 'List projects',
97
+ // (yargs) => yargs,
98
+ // async (args) => {
99
+ // await (await import('./commands/projects')).list(args);
100
+ // }
101
+ // )
102
+ .command('create', 'Create a project', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
103
+ yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).create(args);
104
+ }))
105
+ .middleware(showHelpMiddleware);
93
106
  }))
94
- .command('create', 'Create a project', (yargs) => yargs, (args) => __awaiter(void 0, void 0, void 0, function* () {
95
- yield (yield Promise.resolve().then(() => __importStar(require('./commands/projects')))).create(args);
96
- }))))
107
+ .strict()
97
108
  .fail((msg, err) => __awaiter(void 0, void 0, void 0, function* () {
98
109
  if (err instanceof gateway_1.ApiError) {
99
110
  log_1.log.error(yield err.getApiError());
@@ -104,7 +115,8 @@ const builder = yargs
104
115
  process.exit(1);
105
116
  }));
106
117
  (() => __awaiter(void 0, void 0, void 0, function* () {
107
- if ((yield builder.argv)._.length === 0) {
118
+ const args = yield builder.argv;
119
+ if (args._.length === 0) {
108
120
  yargs.showHelp();
109
121
  }
110
122
  }))();