diff options
| author | Priyansh <[email protected]> | 2021-03-06 22:28:55 +0530 |
|---|---|---|
| committer | Priyansh <[email protected]> | 2021-03-06 22:28:55 +0530 |
| commit | d8ccff2a997971d5c8b28d4835da5540a281b9f7 (patch) | |
| tree | 07332b4d03815d23d6c7505e82249484b31610c1 /bin | |
| parent | 50702d25c0359124dfa7fe94e0d0a68edc41c1f7 (diff) | |
| download | calculator-d8ccff2a997971d5c8b28d4835da5540a281b9f7.tar.xz calculator-d8ccff2a997971d5c8b28d4835da5540a281b9f7.zip | |
Added yargs, help and info options
Diffstat (limited to 'bin')
| -rw-r--r-- | bin/index.js | 35 | ||||
| -rw-r--r-- | bin/infoMessages.js | 27 |
2 files changed, 40 insertions, 22 deletions
diff --git a/bin/index.js b/bin/index.js index e7339f4..f4167db 100644 --- a/bin/index.js +++ b/bin/index.js @@ -1,25 +1,16 @@ #!/usr/bin/env node +const infoMessage = require("./infoMessages"); +const yargs = require('yargs'); -const chalk = require("chalk"); -const boxen = require("boxen"); -const terminalLink = require('terminal-link'); -var packageInfo = require('./../package.json'); +const args = yargs.scriptName("calculator") + .usage('$0 [command] [args]') + .option("i", { alias: "info", describe: "Display information about the calculator" }) + .option("h", { alias: "help" }) + .option("v", { alias: "version" }) + .help() + .strict() + .argv -// If the command is run without any options we will show the about screen -const terminalSupportedLink = `${chalk.blue.underline(terminalLink('here', packageInfo.homepage))}`; -const terminalUnsupportedLink = `here: ${chalk.blue.underline(packageInfo.homepage)}`; -const calculatorAboutMessage = ` -${chalk.white.bold('Calculator')} ${chalk.green.bold('v' + packageInfo.version)} -Written by ${packageInfo.author} — available ${terminalLink.isSupported ? terminalSupportedLink : terminalUnsupportedLink}. -Licensed under the ${packageInfo.license} License. - -Calculator, as the name suggests, is a Scientific Calculator which runs on the command line (CLI) -of your device and is available for all major desktop operating systems. This program is open -source and is written in JavaScript (NodeJS). - -For learning the usage run: ${chalk.green('calculator --help')} or ${chalk.green('calculator --h')} -License Information: ${chalk.green('calculator --license')} -Open Source Credis: ${chalk.green('calculator --credits')} -`; - -console.log(boxen(calculatorAboutMessage, {padding: 1, borderColor: "green"}));
\ No newline at end of file +if (args.info || Object.keys(args).length < 3) { + infoMessage.getIntroductoryMessage(); +} diff --git a/bin/infoMessages.js b/bin/infoMessages.js new file mode 100644 index 0000000..caab192 --- /dev/null +++ b/bin/infoMessages.js @@ -0,0 +1,27 @@ +const terminalLink = require('terminal-link'); +const boxen = require("boxen"); +const chalk = require("chalk"); +var packageInfo = require('./../package.json'); + +module.exports = { + getIntroductoryMessage: () => { + // If the command is run without any options we will show the about screen + const terminalSupportedLink = `${chalk.blue.underline(terminalLink('here', packageInfo.homepage))}`; + const terminalUnsupportedLink = `here: ${chalk.blue.underline(packageInfo.homepage)}`; + const calculatorAboutMessage = ` + ${chalk.white.bold('Calculator')} ${chalk.green.bold('v' + packageInfo.version)} + Written by ${packageInfo.author} — available ${terminalLink.isSupported ? terminalSupportedLink : terminalUnsupportedLink}. + Licensed under the ${packageInfo.license} License. + + Calculator, as the name suggests, is a Scientific Calculator which runs on the command line (CLI) + of your device and is available for all major desktop operating systems. This program is open + source and is written in JavaScript (NodeJS). + + For learning the usage run: ${chalk.green('calculator --help')} or ${chalk.green('calculator --h')} + License Information: ${chalk.green('calculator --license')} + Open Source Credis: ${chalk.green('calculator --credits')} + `; + + console.log(boxen(calculatorAboutMessage, { padding: 1, borderColor: "green" })) + } +}
\ No newline at end of file |
