Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: CLI #50

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ dist
src/modules/images
src/images
test/resources/images/screenshot-test.*
*.tgz
*.tgz
main.zip
4 changes: 3 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ test
.github
.eslintrc.json
.prettierrc
rrconfig.json
src/modules/images
src/images
test/resources/images
*.tgz
*.tgz
main.zip
150 changes: 150 additions & 0 deletions docs/CommandLine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Command Line

Rokul Runnings has a CLI to execute all commands in the Rokul Runnings class via the command line.

## Setup

### Install

Rokul Runnings CLI can be set up to run either globally or at a project level. In order to use either, they must be installed:

```
// global
npm install -g @willowtreeapps/rokul-runnings
```

```
// project level
npm install @willowtreeapps/rokul-runnings
```

### Defining Config values

Rokul Runnings CLI creates an instance of the Rokul Runnings class based on defaults specified in a config JSON file. The structure of that file looks like:

```json
{
aaron-goff marked this conversation as resolved.
Show resolved Hide resolved
"ip": "", // IP address of the Roku, defaults to "", which will throw an error
aaron-goff marked this conversation as resolved.
Show resolved Hide resolved
"username": "rokudev", // username to access Roku Dev portal, defaults to "rokudev"
"password": "password", // password to access the Roku Dev portal, defaults to "password",
"options": {
// Rokul Runnings specific options
"pressDelay": 1000, // time to wait in milliseconds between trying keyPresses, defaults to 1000
madeleine-adams marked this conversation as resolved.
Show resolved Hide resolved
"retryDelay": 1000, // time to wait in milliseconds between retrying calls to the Roku, defaults to 1000
"retries": 1 // how many times a call is retried if a non-successful response is returned, defaults to 1
},
"printOptions": {
// options related to how text is printed, optional
"true": "", // text decoration to be used for true responses, optional, defaults to green
aaron-goff marked this conversation as resolved.
Show resolved Hide resolved
"false": "", // text decoration to be used for false responses, optional, defaults to red
"jsonKey": "", // text decoration to be used for keys in JSON objects, optional, defaults to green
"jsonValue": {
// text decoration to be used for values in JSON objects, optional
"string": "", // text decoration to be used for string values in JSON objects, optional, defaults to orange
"boolean": "", // text decoration to be used for boolean values in JSON objects, optional, defaults to blue
"number": "" // text decoration to be used for number values in JSON objects, optional, defaults to yellow
}
}
}
```

The `ip`, `username`, `password`, and `options` fields can be set via the CLI:

```
rr -ip 127.0.0.2 -u newUsername -p newPassword --retryDelay 2000 --pressDelay 2000 --retries 2
rr --ip 127.0.0.3 --username newUsername2 --password newPassword2
```

Setting any option via the CLI will also save them in the config JSON file.

`printOptions` can also be set as a comma-delimited list via the CLI:

```
rr --printOptions true=blue.bgRed.bold,false=red.bgBlue.bold,jsonKey=keyword\(\'pink\'\)
```

`jsonValue` fields are set with `jsonValue` prepended to their field name

```
rr --printOptions jsonValuestring=red,jsonValueboolean=blue,jsonValuenumber=green
```

All of the print options can be defined via [Chalk](https://www.npmjs.com/package/chalk). Certain characters will need to be escaped when being passed in via command line, such as `(`, `)`, `'`, and `'`.

If you need to find out where your file currently lives, the `debug` command will print out the config path, as well as the Rokul Runnings instance created:

```
rr --debug
```

```rr
Configstore {
path: '/path/to/rrconfig.json'
}
RokulRunnings {
rokuIPAddress: '127.0.0.1',
username: 'rokudev',
password: 'password',
devInstallerInfo: {
username: 'rokudev',
password: 'password',
rokuIPAddress: 'http://127.0.0.1'
},
pressDelayInMillis: 1000,
driver: Driver {
rokuIPAddress: '127.0.0.1',
retries: 1,
baseURL: 'http://127.0.0.1:8060'
},
retryDelayInMillis: 1000,
retries: 1
}
```

## Use

All of the following commands do not accept any parameters:
|CLI Option|Rokul Runnings Function|
|----|----|
|`-ga`,<br>`--getApps`|`getApps()`|
|`-gp`,<br>`--getPlayerInfo`|`getPlayerInfo()`|
|`--getScreenSource`|`getScreenSource()`|
|`-gc`,<br>`--getCurrentlChannelInfo`|`getCurrentChannelInfo()`|
|`-gd`,<br>`--getDeviceInfo`|`getDeviceInfo()`|
|`-gf`,<br>`--getFocusedElement`|`getFocusedElement()`|
|`--delete`|`deleteChannel()`|
|`--debug`| N/A |

Parameters can be passed in to the commands below. Parameters can either use the default parameter, in which case no key is required. Otherwise, parameters should be specified in a comma-delimited list, in the form of key=value, like so:
<br>`rr --command defaultParameterValue`
<br>`rr --command key1=value1,key2=value2,key3=value3`
|CLI Option|Parameters|Default Paramter|Rokul Runnings Function|Examples|
|----|----|----|----|----|
|`-lc`,<br>`--launchChannel`| `channelCode`, `contentId`, `mediaType`, `params` | `channelCode` | `launchTheChannel()` | `rr -lc dev`<br>`rr --launchChannel channelCode=1234,mediaType=foo`<br>`rr -lc`<br>'dev' is the default if no value is provided.|
|`-dl`,<br>`--deepLink`| `channelCode`, `contentId`, `mediaType`, `params` | `channelCode` | `deepLinkIntoChannel()` | `rr -dl dev`<br>`rr --deepLink channelCode=1234,mediaType=foo`|
|`--sendInstallChannel`|`channelCode`, `params`|`channelCode`|`sendInstallChannel()`|`rr --sendInstallChannel 12`|
|`-btn`<br>`--pressBtn`| `keyPress`, `params`|`keyPress`|`pressBtn()`|`rr -btn home`<br>`rr --pressBtn keyPress=home`|
|`--pressBtnDown`|`keyDown`, `params`|`keyDown`|`pressBtnDown()`|`rr --pressBtnDown keyDown=right`
|`--pressBtnUp`|`keyUp`, `params`|`keyUp`|`pressBtnUp()`|`rr --pressBtnUp select`|
|`-w`, `--sendWord`|`word`, `params`|`word`|`sendWord()`|`rr -w roku`|
|`--sendSequence`|`sequence`, `params`, `keyType`|`sequence`|`sendButtonSequence()`|`rr --sendSequence sequence=up^up^down`<br>Presses in the sequence are separated by a `^`|
|`--sendCustomSequence`|`customSequence`, `params`|`customSequence`|`sendMixedButtonSequence()`|`rr --sendCustomSequence customSequence=keyUp.home^keyPress.select^keyDown.right`<br>Key types are separated from key values with a `.`<br>Presses in the sequence are separated by a `^`|
|`--verifyChannelExist`|`id`|`id`|`verifyIsChannelExist()`|`rr --verifyChannelExist dev`<br>`rr --verifyChannelExist id=1234`<br>`rr --verifyChannelExist`<br>'dev' is the default if no value is provided.|
|`--verifyScreenLoaded`|`using`, `value`, `attribute`, `maxAttempts`| N/A |`verifyIsScreenLoaded()`|`rr --verifyScreenLoaded using=text,value=ArcInterpolator`|
|`--verifyElementOnScreen`|`using`, `value`, `attribute`, `maxAttempts`| N/A |`verifyIsElementOnScreen()`|`rr --verifyElementOnScreen using=tag,value=Label`|
|`--verifyFocusedElementIsOfCertainTag`|`tag`, `maxAttempts`| `tag`| `verifyFocusedElementIsOfCertainTag`|`rr --verifyFocusedElementIsOfCertainTag Label`<br>`rr --verifyFocusedElementIsOfCertainTag tag=Label,maxAttempts=2`|
|`--verifyChannelLoaded`|`id`, `maxAttempts`|`id`|`verifyIsChannelLoaded()`|`rr --verifyChannelLoaded dev`<br>`rr --verifyChannelLoaded id=dev`<br>`rr --verifyChannelLoaded`<br>'dev' is the default if no value is provided.<br>`id` must be specified if `maxAttempts` is specified.|
|`--verifyPlaybackStarted`|`maxAttempts`|`maxAttempts`|`verifyIsPlaybackStarted()`|`rr --verifyPlaybackStarted`<br>`rr --verifyPlaybackStarted 10`<br>`rr --verifyPlaybackStated maxAttempts=10`<br>All of the above are equivalent|
|`--getElement`,<br>`--getElements`|`using`, `value`, `attribute`| N/A |`getElement()`<br>`getElements()`|`rr --getElement using=attr,value=3,attribute=children`<br>`rr --getElements using=text,value=ArcInterpolator`
|`--getElementByText`<br>`--getElementsByText`|`value`|`value`|`getElementByText()`<br>`getElementsByText()`|`rr --getElementByText ArcInterpolator`<br>`rr --getElementsByText value=ArcInterpolator`|
|`--getElementByAttr`<br>`--getElementsByAttr`|`value`, `attribute`| N/A | `getElementByAttr()`<br>`getElementsByAttr()`|`rr --getElementByAttr value=5,attribute=children`<br>`rr --getElementsByAttr value=true,attribute=focused`|
|`--getElementByTag`<br>`--getElementsByTag`|`value`|`value`|`getElementByTag()`<br>`getElementsByTag()`|`rr --getElementByTag value=Label`<br>`rr --getElementsByTag Label`|
|`-gs`<br>`--getScreenshot`|`directoryPath`, `fileName`, `fileType`|`directoryPath`|`getScreenshot()`|`rr -gs`<br>`rr --getScreenshot directoryPath='../images'`<br>getScreenshot will fail if executed and the directoryPath specified does not exist.<br>If no value is passed in, the image will be saved to PWD|
|`--install`|`channelLocation`|`channelLocation`|`installChannel()`|`rr --install '/path/to/zip.zip`|
|`--replace`|`channelLocation`|`channelLocation`|`replaceChannel()`|`rr --replace '/path/to/zip.zip`|

## Global vs. Local

Rokul Runnings CLI uses simple logic to determine what config file to use. If the present working directory that the command is executed from contains a file named `rrconfig.json`, then that file is used. Otherwise, the global config file will be used. This will look something like FIND OUT WHAT IT LOOKS LIKE.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a comment so I actually come back and update this.


You can determine if you are using a local or global config file by running `rr --debug`, which will print out the Configstore path for Rokul Runnings.
Loading