Skip to content

Commit

Permalink
feat(tcp-redirs list-namespaces): add --format json|human option
Browse files Browse the repository at this point in the history
Fixes #589
  • Loading branch information
pdesoyres-cc authored and hsablonniere committed Jul 1, 2024
1 parent 8d14c6e commit 02e9a9d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions bin/clever.js
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ function run () {
const tcpRedirs = lazyRequirePromiseModule('../src/commands/tcp-redirs.js');
const tcpRedirsListNamespacesCommand = cliparse.command('list-namespaces', {
description: 'List the namespaces in which you can create new TCP redirections',
options: [opts.humanJsonOutputFormat],
}, tcpRedirs('listNamespaces'));
const tcpRedirsAddCommand = cliparse.command('add', {
description: 'Add a new TCP redirection to the application',
Expand Down
30 changes: 27 additions & 3 deletions src/commands/tcp-redirs.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,37 @@ const application = require('@clevercloud/client/cjs/api/v2/application.js');
const Application = require('../models/application.js');

async function listNamespaces (params) {
const { alias, app: appIdOrName } = params.options;
const { alias, app: appIdOrName, format } = params.options;
const { ownerId } = await Application.resolveId(appIdOrName, alias);

const namespaces = await Namespaces.getNamespaces(ownerId);

Logger.println('Available namespaces: ' + namespaces.map(({ namespace }) => namespace).join(', '));
};
namespaces.sort((a, b) => a.namespace.localeCompare(b.namespace));

switch (format) {
case 'json': {
Logger.printJson(namespaces);
break;
}
case 'human':
default: {
Logger.println('Available namespaces:');
namespaces.forEach(({ namespace }) => {
switch (namespace) {
case 'cleverapps':
Logger.println(`- ${namespace}: for redirections used with 'cleverapps.io' domain`);
break;
case 'default':
Logger.println(`- ${namespace}: for redirections used with custom domains`);
break;
default:
Logger.println(`- ${namespace}`);
}
});
break;
}
}
}

async function list (params) {
const { alias, app: appIdOrName, format } = params.options;
Expand Down

0 comments on commit 02e9a9d

Please sign in to comment.