Skip to content

Commit

Permalink
Merge pull request #17 from aerogear/AEROGEAR-10241
Browse files Browse the repository at this point in the history
Added app rename feature
  • Loading branch information
ziccardi authored Apr 16, 2020
2 parents c90c977 + e2cb6ae commit 19076da
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 26 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,15 @@ Application created successfully
╚═══════════╧══════════════════════════════════════╝
```

### Rename an existing app

To rename an application in a given instance of the _UnifiedPush Server_ the `rename` sub-command should be used:

```bash
ups -U http://localhost:9999 applications rename --app-id ecfe3c76-b547-4b1c-8f21-b08085c08c80 --name newname
Application renamed successfully
```

The command returns a table with the details of the just created application.

## Variants
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aerogear/unifiedpush-cli",
"version": "0.0.1-alpha.2",
"version": "0.0.1-alpha.3",
"description": "UnifiedPush Server CLI client",
"author": "AeroGear Team<aerogear@googlegroups.com>",
"homepage": "http://aerogear.org",
Expand Down Expand Up @@ -42,7 +42,7 @@
"typescript": "3.8.3"
},
"dependencies": {
"@aerogear/unifiedpush-admin-client": "0.1.4",
"@aerogear/unifiedpush-admin-client": "0.1.7",
"eslint-plugin-jest": "^23.8.2",
"figlet": "^1.3.0",
"inquirer": "^7.1.0",
Expand Down
22 changes: 18 additions & 4 deletions src/cmds/app-cmds/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {table} from 'table';
import {Arguments, Argv} from 'yargs';
import {
PushApplication,
PushApplicationFilter,
PushApplicationSearchOptions,
} from '@aerogear/unifiedpush-admin-client';
import {UPSAdminClientFactory} from '../../utils/UPSAdminClientFactory';
import {normalizeFilter} from '../../utils/FilterUtils';
Expand All @@ -24,9 +24,13 @@ export const builder = (yargs: Argv) => {
};

export const handler = async (argv: Arguments) => {
const filter: PushApplicationFilter | undefined = argv.filter
const filter: PushApplicationSearchOptions = argv.filter
? normalizeFilter(JSON.parse(argv.filter as string))
: undefined;
: {};

filter.includeActivity = true;
filter.includeDeviceCount = true;

const apps = await UPSAdminClientFactory.getUpsAdminInstance(
argv
).applications.find(filter);
Expand All @@ -40,10 +44,20 @@ export const handler = async (argv: Arguments) => {
currentValue.name,
currentValue.pushApplicationID!,
`${currentValue.variants?.length || 0}`,
`${currentValue.deviceCount}`,
`${currentValue.activity}`,
]);
return previousValue;
},
[['NAME', 'PUSH-APPLICATION-ID', 'VARIANTS']]
[
[
'NAME',
'PUSH-APPLICATION-ID',
'VARIANTS',
'INSTALLATIONS',
'SENT-MESSAGES',
],
]
);
console.log(table(tableData));
} else {
Expand Down
32 changes: 32 additions & 0 deletions src/cmds/app-cmds/rename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {Arguments, Argv} from 'yargs';
import {UPSAdminClientFactory} from '../../utils/UPSAdminClientFactory';

export const command = 'rename';

export const describe = 'rename one application';

export const builder = (yargs: Argv) => {
return yargs
.group('app-id', 'Rename Application:')
.option('app-id', {
required: true,
type: 'string',
describe: 'The push application ID of the app to be renamed',
requiresArg: true,
})
.option('name', {
required: true,
type: 'string',
describe: 'The new name',
requiresArg: true,
})
.help();
};

export const handler = async (argv: Arguments<Record<string, string>>) => {
await UPSAdminClientFactory.getUpsAdminInstance(argv).applications.rename(
argv.appId,
argv.name
);
console.log('Application renamed successfully');
};
10 changes: 8 additions & 2 deletions src/cmds/variants-cmds/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,20 @@ import {UPSAdminClientFactory} from '../../utils/UPSAdminClientFactory';
import {table} from 'table';
import {normalizeFilter} from '../../utils/FilterUtils';

exports.command = 'list <app-id>';
exports.command = 'list';

exports.describe =
'lists the variants for the application identified by <app-id>';

export const builder = (yargs: Argv) => {
return yargs
.group('filter', 'Variants list:')
.group(['filter', 'app-id'], 'Variants list:')
.option('app-id', {
required: true,
type: 'string',
describe: 'The application id',
requiresArg: true,
})
.option('filter', {
required: false,
type: 'string',
Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ const authOptions = (yargs: Argv): Argv => {
return keyCloakOptions(res);
};

const extractErrorDetails = (msg: string, err: any): string => {
if (msg) {
return msg;
}

if (err.response?.data) {
return err.response.data;
}

return err.message;
};

authOptions(yargs)
.demandCommand()
.option('U', {
Expand All @@ -76,7 +88,7 @@ authOptions(yargs)
.commandDir('cmds')
.strict()
.fail((msg, err) => {
console.log('ERROR -', msg || err);
console.log('ERROR -', extractErrorDetails(msg, err));
if (msg) {
console.log("ups: try 'ups --help' for more information");
}
Expand Down
22 changes: 11 additions & 11 deletions test/cmds/app-cmds/list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ describe('applications', () => {
await handler({url: 'http://localhost:9999'});
expect(ConsoleMock.log).toHaveBeenCalledTimes(1);
expect(ConsoleMock.log).toHaveBeenCalledWith(
`╔═══════════════╤═════════════════════╤══════════╗
║ NAME │ PUSH-APPLICATION-ID │ VARIANTS ║
╟───────────────┼─────────────────────┼──────────╢
║ Application 1 │ 1:1 │ 3 ║
╟───────────────┼─────────────────────┼──────────╢
║ Application 2 │ 2:2 │ 2 ║
╟───────────────┼─────────────────────┼──────────╢
║ Application 3 │ 3:3 │ 1 ║
╟───────────────┼─────────────────────┼──────────╢
║ Application 4 │ 4:4 │ 0 ║
╚═══════════════╧═════════════════════╧══════════╝
`╔═══════════════╤═════════════════════╤══════════╤═══════════════╤═══════════════
║ NAME │ PUSH-APPLICATION-ID │ VARIANTS │ INSTALLATIONS │ SENT-MESSAGES
╟───────────────┼─────────────────────┼──────────┼───────────────┼───────────────
║ Application 1 │ 1:1 │ 3 │ undefined │ undefined
╟───────────────┼─────────────────────┼──────────┼───────────────┼───────────────
║ Application 2 │ 2:2 │ 2 │ undefined │ undefined
╟───────────────┼─────────────────────┼──────────┼───────────────┼───────────────
║ Application 3 │ 3:3 │ 1 │ undefined │ undefined
╟───────────────┼─────────────────────┼──────────┼───────────────┼───────────────
║ Application 4 │ 4:4 │ 0 │ undefined │ undefined
╚═══════════════╧═════════════════════╧══════════╧═══════════════╧═══════════════
`
);
});
Expand Down
4 changes: 2 additions & 2 deletions test/mocks/MockUnifiedPushAdminClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {
PushApplication,
PushApplicationFilter,
PushApplicationSearchOptions,
Variant,
} from '@aerogear/unifiedpush-admin-client';
import {mockData} from '../mockData';
import {applyPushApplicationFilter} from '@aerogear/unifiedpush-admin-client/dist/src/applications/PushApplication';
import {applyVariantFilter} from '@aerogear/unifiedpush-admin-client/dist/src/variants/Variant';

const findApplicationsMock = jest.fn(
(filter?: PushApplicationFilter): PushApplication[] => {
(filter?: PushApplicationSearchOptions): PushApplication[] => {
return applyPushApplicationFilter(mockData, filter);
}
);
Expand Down

0 comments on commit 19076da

Please sign in to comment.