-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: present commands output in tables
- Loading branch information
1 parent
7bb73e5
commit 955f8a1
Showing
14 changed files
with
59 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters