From 3ba552f3c20526db6e5194434ac396390e91e688 Mon Sep 17 00:00:00 2001 From: Daniel Leong Date: Sat, 9 Mar 2019 15:20:41 -0500 Subject: [PATCH] Refactor CLI code to get babel-ified and generally be more maintainable (#114) * Begin initial CLI refactor Refs #108 The general approach here is that each command should be simple to write with an easy means of operating against a provided UI and device. That way we can test against mocks/fakes and also easily swap out a different "UI" implementation. I don't plan to add a GUI, but this would make it easier to support `--json` mode, or even possibly a headless stdin-based daemon mode. I've decided against oclif because it just seems like too much, but commander.js or yargs seem like good options. * Restore some logging * Improve cli test correctness; support inline PIN prompts Closes #113 * Implement command routing using our old friend minimist Refs #108 Yargs has some great stuff but I don't like how it renders the options info. Commander.js seems very close, but it doesn't wrap descriptions at all. docopt and neodoc seem neat but don't let us nicely and succinctly describe what each command does. Minimist is simple and easy, and doesn't introduce any new dependency overhead, so let's just stick with it! * Remove old bin script and udpate package.json * Update readme with latest, cleaned up help text Closes #108 --- .eslintrc.js | 1 + README.md | 50 +- bin/.eslintrc.js | 317 ------- bin/cmd.js | 393 --------- lib/cli.js | 156 ++++ lib/cli/base.js | 265 ++++++ lib/cli/check.js | 20 + lib/cli/osk.js | 22 + lib/cli/pin.js | 27 + lib/cli/remote.js | 23 + lib/cli/search.js | 8 + lib/cli/standby.js | 8 + lib/cli/start.js | 17 + lib/cli/ui/standard.js | 57 ++ lib/cli/wake.js | 8 + lib/detector.js | 60 +- lib/device.js | 10 +- lib/waker.js | 3 +- package-lock.json | 1702 ++++++++++++++++++++------------------ package.json | 4 +- test/cli/base-test.js | 92 +++ test/cli/test-command.js | 95 +++ test/cli/test-ui.js | 36 + 23 files changed, 1825 insertions(+), 1549 deletions(-) delete mode 100644 bin/.eslintrc.js delete mode 100755 bin/cmd.js create mode 100755 lib/cli.js create mode 100644 lib/cli/base.js create mode 100644 lib/cli/check.js create mode 100644 lib/cli/osk.js create mode 100644 lib/cli/pin.js create mode 100644 lib/cli/remote.js create mode 100644 lib/cli/search.js create mode 100644 lib/cli/standby.js create mode 100644 lib/cli/start.js create mode 100644 lib/cli/ui/standard.js create mode 100644 lib/cli/wake.js create mode 100755 test/cli/base-test.js create mode 100644 test/cli/test-command.js create mode 100644 test/cli/test-ui.js diff --git a/.eslintrc.js b/.eslintrc.js index 3ba09a5..cc0796f 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -8,6 +8,7 @@ module.exports = { "ecmaVersion": 2018 }, "rules": { + "class-methods-use-this": "off", "arrow-body-style": "off", "func-names": "off", // for now "indent": ["error", 4], diff --git a/README.md b/README.md index 846f9c8..73412e5 100644 --- a/README.md +++ b/README.md @@ -29,43 +29,49 @@ to get the following usage information: ps4-waker - Wake your PS4 (and more!) with help from the Playstation App Usage: - ps4-waker [options] Wake PS4 device(s) - ps4-waker [options] osk-submit (text) Submit the OSK, optionally providing the text - ps4-waker [options] remote (...) Send remote key-press event(s) - ps4-waker [options] search Search for devices - ps4-waker [options] standby Request the device enter standby/rest mode - ps4-waker [options] start Start a specified title id - ps4-waker --help | -h | -? Shows this help message. - ps4-waker --version | -v Show package version. + ps4-waker [options] Wake PS4 device(s) + ps4-waker [options] osk-submit [text] Submit the OSK, optionally + providing the text + ps4-waker [options] remote Send remote key-press event(s) + ps4-waker [options] search Search for devices + ps4-waker [options] standby Request the device enter + standby/rest mode + ps4-waker [options] start Start a specified title id + ps4-waker --help | -h | -? Shows this help message. + ps4-waker --version | -v Show package version. Options: - --bind | -b Bind to a specific network adapter IP, if you have multiple - --bind-port | -p Bind on a specific port, if you need to route specifically + --bind | -b Bind to a specific network adapter IP, if + you have multiple + --bind-port | -p Bind on a specific port, if you need to + route specifically --credentials | -c Specify credentials file --device | -d Specify IP address of a specific PS4 --failfast Don't request credentials if none --skip-login Don't automatically login --pin Manual pin-code registration --pass Provide passcode for login, if needed - --timeout | -t