diff --git a/bin/index.js b/bin/index.js index c865562..a750b2b 100755 --- a/bin/index.js +++ b/bin/index.js @@ -2,22 +2,38 @@ const os = require('os'); +const chalk = require('chalk'); +const meow = require('meow'); + const updateNotifier = require('update-notifier'); const pkg = require('../package.json'); const getUnityUrls = require('../lib/get-unity-urls'); +const cli = meow( + ` + Usage + $ get-unity [options] + + Options + ${chalk.yellow('--help, -h')} Display this help message. + ${chalk.yellow('--version, -v')} Display the current installed version. + `, + { + 'flags': { + 'autoHelp': true, + 'autoVersion': true + } + } +); + const osKeyMap = { 'Darwin': 'mac', 'Windows_NT': 'win64' }; -const PROCESS_CMD_LINE_ARGS_LENGTH = 2; - -const requestedVersion = process.argv.slice(PROCESS_CMD_LINE_ARGS_LENGTH).pop(); - updateNotifier({pkg}).notify(); -getUnityUrls(requestedVersion).then(urls => +getUnityUrls(cli.input[0]).then(urls => process.stdout.write(`${urls[osKeyMap[os.type()]]}`)); diff --git a/package.json b/package.json index dcaee9b..92560b1 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,8 @@ }, "license": "MIT", "dependencies": { + "chalk": "2.4.2", + "meow": "5.0.0", "update-notifier": "3.0.1" }, "devDependencies": {