Skip to content

Commit

Permalink
feat: present commands output in tables
Browse files Browse the repository at this point in the history
  • Loading branch information
bchelkowski committed Oct 18, 2023
1 parent 7bb73e5 commit 955f8a1
Show file tree
Hide file tree
Showing 14 changed files with 59 additions and 32 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,10 @@ Roku ECP - `query/device-info`
Retrieves device information similar to that returned by roDeviceInfo.

```bash
roku device [--ip <Roku device IP>]
roku device [field] [--ip <Roku device IP>]
```

* **field** - Field of the data object that should be picked
* **ip** - IP of the Roku device

Environment variables (command argument/option):
Expand Down Expand Up @@ -320,9 +321,10 @@ The information returned includes the current stream segment and position of the
the running time of the content, audio format, and buffering.

```bash
roku player [--ip <Roku device IP>]
roku player [field] [--ip <Roku device IP>]
```

* **field** - Field of the data object that should be picked
* **ip** - IP of the Roku device

Environment variables (command argument/option):
Expand Down
9 changes: 9 additions & 0 deletions src/cli/arguments/field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { ParsedArgumentsObject } from '@caporal/core';

export function getFieldArgumentDefinition(): [string, string] {
return ['[field]', 'Field of the data object that should be picked'];
}

export function getField<T>(args: ParsedArgumentsObject): string {
return args.field as string;
}
4 changes: 2 additions & 2 deletions src/cli/commands/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { getRokuIP, getRokuIPOptionDefinition } from '../options/rokuIP';
export default function ({ createCommand }: CreateCommandParameters): Command {
return createCommand('Shows data of the current active app')
.option(...getRokuIPOptionDefinition())
.action(async ({ logger, options }) => {
.action(async ({ options }) => {
const apps = await activeApp({
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
});

logger.info('Active App: %j', apps);
console.table(apps);
});
}
4 changes: 2 additions & 2 deletions src/cli/commands/apps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { getRokuIP, getRokuIPOptionDefinition } from '../options/rokuIP';
export default function ({ createCommand }: CreateCommandParameters): Command {
return createCommand('Shows data of all installed apps')
.option(...getRokuIPOptionDefinition())
.action(async ({ logger, options }) => {
.action(async ({ options }) => {
const apps = await installedApps({
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
});

logger.info('Installed Apps: %j', apps);
console.table(apps);
});
}
4 changes: 2 additions & 2 deletions src/cli/commands/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { getRokuIP, getRokuIPOptionDefinition } from '../options/rokuIP';
export default function ({ createCommand }: CreateCommandParameters): Command {
return createCommand('Returns a list of the assets that have been loaded into texture memory')
.option(...getRokuIPOptionDefinition())
.action(async ({ logger, options }) => {
.action(async ({ options }) => {
const _assets = await assets({
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
});

logger.info('Assets: %j', _assets);
console.table(_assets);
});
}
4 changes: 2 additions & 2 deletions src/cli/commands/beacons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export default function ({ createCommand }: CreateCommandParameters): Command {
validator: ['log', 'track', 'untrack'],
}))
.option(...getRokuIPOptionDefinition())
.action(async ({ args, logger, options }) => {
.action(async ({ args, options }) => {
const _beacons = await beacons({
channelId: getChannelId(args) || envVariables.CHANNEL_ID || '',
command: getCommand<CommandType>(args),
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
});

logger.info('Beacons: %j', _beacons);
console.table(_beacons);
});
}
13 changes: 10 additions & 3 deletions src/cli/commands/device.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import type { CreateCommandParameters, Command } from '@caporal/core';
import { envVariables } from '../../env/args';
import deviceInfo from '../../requests/deviceInfo';
import deviceInfo, { DeviceInfoType } from '../../requests/deviceInfo';
import { getField, getFieldArgumentDefinition } from '../arguments/field';
import { getRokuIP, getRokuIPOptionDefinition } from '../options/rokuIP';

export default function ({ createCommand }: CreateCommandParameters): Command {
return createCommand('Retrieves device information similar to that returned by roDeviceInfo')
.argument(...getFieldArgumentDefinition())
.option(...getRokuIPOptionDefinition())
.action(async ({ logger, options }) => {
.action(async ({ args, options }) => {
const device = await deviceInfo({
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
});

logger.info('Device Info: %j', device);
const field = getField(args) as keyof DeviceInfoType;
if (field && device[field]) {
console.table(device[field]);
} else {
console.table(device);
}
});
}
4 changes: 2 additions & 2 deletions src/cli/commands/fps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { getRokuIP, getRokuIPOptionDefinition } from '../options/rokuIP';
export default function ({ createCommand }: CreateCommandParameters): Command {
return createCommand('Returns the recent number of rendered graphics frames per seconds (this value is separate from the video frame rate).')
.option(...getRokuIPOptionDefinition())
.action(async ({ logger, options }) => {
.action(async ({ options }) => {
const fps = await graphicsFrameRate({
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
});

logger.info('FPS: %j', fps);
console.table(fps);
});
}
5 changes: 2 additions & 3 deletions src/cli/commands/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ export default function ({ createCommand }: CreateCommandParameters): Command {
}))
.argument(...getNodeIdArgumentDefinition())
.option(...getRokuIPOptionDefinition())
.action(async ({ args, logger, options }) => {
.action(async ({ args, options }) => {
const sgNodesData = await sgNodes({
nodeId: getNodeId(options),
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
type: getType(args),
});
const sgNodesString = JSON.stringify(sgNodesData, null, ' ');

logger.info('Nodes: %s', sgNodesString);
console.table(sgNodesData);
});
}
5 changes: 2 additions & 3 deletions src/cli/commands/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ export default function ({ createCommand }: CreateCommandParameters): Command {
return createCommand('Returns the current memory and CPU utilization of the channel running in the foreground (RAM usage is reported bytes).')
.argument(...getChannelIdArgumentDefinition())
.option(...getRokuIPOptionDefinition())
.action(async ({ args, options, logger }) => {
.action(async ({ args, options }) => {
const channelPerformanceData = await channelPerformance({
channelId: getChannelId(args) || envVariables.CHANNEL_ID || '',
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
});
const channelPerformanceString = JSON.stringify(channelPerformanceData, null, ' ');

logger.info('Channel Performance: %s', channelPerformanceString);
console.table(channelPerformanceData);
});
}
14 changes: 10 additions & 4 deletions src/cli/commands/player.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import type { CreateCommandParameters, Command } from '@caporal/core';
import { envVariables } from '../../env/args';
import mediaPlayer from '../../requests/mediaPlayer';
import mediaPlayer, { MediaPlayerType } from '../../requests/mediaPlayer';
import { getField, getFieldArgumentDefinition } from '../arguments/field';
import { getRokuIP, getRokuIPOptionDefinition } from '../options/rokuIP';

export default function ({ createCommand }: CreateCommandParameters): Command {
return createCommand('Returns a child element named \'player\' that identifies the media player state.')
.argument(...getFieldArgumentDefinition())
.option(...getRokuIPOptionDefinition())
.action(async ({ logger, options }) => {
.action(async ({ args, options }) => {
const mediaPlayerData = await mediaPlayer({
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
});
const mediaPlayerString = JSON.stringify(mediaPlayerData, null, ' ');

logger.info('Media Player: %s', mediaPlayerString);
const field = getField(args) as keyof MediaPlayerType;
if (field && mediaPlayerData[field]) {
console.table(mediaPlayerData[field]);
} else {
console.table(mediaPlayerData);
}
});
}
12 changes: 9 additions & 3 deletions src/cli/commands/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function ({ createCommand }: CreateCommandParameters): Command {
.option(...getKeysOptionDefinition())
.option(...getSectionsOptionDefinition())
.option(...getRokuIPOptionDefinition())
.action(async ({ args, logger, options }) => {
.action(async ({ args, options }) => {
const keys = getKeys(options);
const sections = getSections(options);
const registryData = await registry({
Expand All @@ -24,8 +24,14 @@ export default function ({ createCommand }: CreateCommandParameters): Command {
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
sections: sections ? sections.split('|') : undefined,
});
const registryString = JSON.stringify(registryData, null, ' ');

logger.info('Registry Data: %s', registryString);
console.table(registryData);

const sectionsData = (registryData.registry as { sections: object | undefined })?.sections;
if (sectionsData) {
const sectionsString = JSON.stringify(sectionsData, null, ' ');

console.log('sections: ', sectionsString);
}
});
}
5 changes: 2 additions & 3 deletions src/cli/commands/rendezvous.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ export default function ({ createCommand }: CreateCommandParameters): Command {
validator: ['log', 'track', 'untrack'],
}))
.option(...getRokuIPOptionDefinition())
.action(async ({ args, logger, options }) => {
.action(async ({ args, options }) => {
const rendezvousData = await rendezvous({
channelId: getChannelId(args) || envVariables.CHANNEL_ID || '',
command: getCommand<CommandType>(args),
rokuIP: getRokuIP(options) || envVariables.ROKU_IP || '',
});
const rendezvousString = JSON.stringify(rendezvousData, null, ' ');

logger.info('Rendezvous: %s', rendezvousString);
console.table(rendezvousData);
});
}
2 changes: 1 addition & 1 deletion src/requests/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type RegistryOptions = {
sections?: string[];
};

export default async (options: RegistryOptions): Promise<{ [key: string]: string }> => {
export default async (options: RegistryOptions): Promise<{ [key: string]: string | object }> => {
if (!options.channelId) throw Error('Missing channelId');

const queryParams = [];
Expand Down

0 comments on commit 955f8a1

Please sign in to comment.