Merge pull request #1 from DrewMcArthur/master
Add a help screen that appears if zip option undefined or help option is present.
This commit is contained in:
50
index.js
50
index.js
@ -1,23 +1,61 @@
|
|||||||
// Require npm packages.
|
// Require npm packages.
|
||||||
const fetch = require('node-fetch');
|
const fetch = require('node-fetch');
|
||||||
const commandLineArgs = require('command-line-args');
|
const commandLineArgs = require('command-line-args');
|
||||||
|
const getUsage = require('command-line-usage');
|
||||||
|
|
||||||
// Get partNumbers from json file.
|
// Get partNumbers from json file.
|
||||||
const partNumbers = require('./partNumbers.json');
|
const partNumbers = require('./partNumbers.json');
|
||||||
|
|
||||||
// Define command line args accepted.
|
// Define command line args accepted.
|
||||||
const optionDefinitions = [
|
const optionDefinitions = [
|
||||||
{ name: 'carrier', type: String, defaultValue: 'TMOBILE' },
|
{ name: 'carrier', type: String, defaultValue: 'TMOBILE', description: "Define which carrier to search for. Accepted options are: 'ATT', 'SPRING', 'TMOBILE', 'VERIZON'."},
|
||||||
{ name: 'model', type: String, defaultValue: 'x' },
|
{ name: 'model', type: String, defaultValue: 'x', description: "Define which model iPhone to search for. 'x' is the only option currently available."},
|
||||||
{ name: 'color', type: String, defaultValue: 'gray' },
|
{ name: 'color', type: String, defaultValue: 'gray', description: "Define which color iPhone to search for. Accepted options are: 'silver', 'gray'."},
|
||||||
{ name: 'storage', type: String, defaultValue: '256' },
|
{ name: 'storage', type: String, defaultValue: '256', description: "Define which storage size to search for. Accepted options are: '64', '256'."},
|
||||||
{ name: 'zip', type: String, defaultOption: true },
|
{ name: 'zip', type: String, defaultOption: true, description: "Define the area to search in by zip code. This option is required."},
|
||||||
{ name: 'delay', type: Number, defaultValue: 30 },
|
{ name: 'delay', type: Number, defaultValue: 30, description: "Define the number of seconds between requests."},
|
||||||
|
{ name: 'help', type: Boolean, description: "Display this help screen."},
|
||||||
];
|
];
|
||||||
|
|
||||||
// Parse command line args.
|
// Parse command line args.
|
||||||
const options = commandLineArgs(optionDefinitions);
|
const options = commandLineArgs(optionDefinitions);
|
||||||
|
|
||||||
|
// Define the help screen to be displayed if --help is present in options
|
||||||
|
const usageDefinition = [
|
||||||
|
{
|
||||||
|
header: 'iPhone X Availability Node CLI',
|
||||||
|
content: "The app continously makes requests to Apple's availability api. When it finds some new stock near you, it displays the stores' name and distance from your zipcode then exits the program."
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: 'Synopsis',
|
||||||
|
content: [
|
||||||
|
{
|
||||||
|
desc: 'Default arguments.',
|
||||||
|
example: '$ node index.js [bold]{--carrier} TMOBILE [bold]{--model} x [bold]{--color} gray [bold]{--storage} 256 [bold]{--delay} 30'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: 'Simple example',
|
||||||
|
example: '$ node index.js [bold]{--zip} 10001 [bold]{--color} silver'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
desc: 'Help screen.',
|
||||||
|
example: '$ node index.js [bold]{--help}'
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
header: "Options",
|
||||||
|
optionList: optionDefinitions
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
// if --help is present or --zip wasn't defined,
|
||||||
|
// then display the help screen and exit the program.
|
||||||
|
if (options['help'] || options['zip'] === undefined) {
|
||||||
|
console.log(getUsage(usageDefinition));
|
||||||
|
process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
// Get part number for the specified device.
|
// Get part number for the specified device.
|
||||||
const partNumber =
|
const partNumber =
|
||||||
partNumbers[options.model][options.carrier.toUpperCase()][options.color][options.storage];
|
partNumbers[options.model][options.carrier.toUpperCase()][options.color][options.storage];
|
||||||
|
55
package-lock.json
generated
55
package-lock.json
generated
@ -45,6 +45,14 @@
|
|||||||
"integrity": "sha1-YXmX/F9gV2iUxDX5QNgZ4TW4B2I=",
|
"integrity": "sha1-YXmX/F9gV2iUxDX5QNgZ4TW4B2I=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"ansi-escape-sequences": {
|
||||||
|
"version": "4.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/ansi-escape-sequences/-/ansi-escape-sequences-4.0.0.tgz",
|
||||||
|
"integrity": "sha512-v+0wW9Wezwsyb0uF4aBVCjmSqit3Ru7PZFziGF0o2KwTvN2zWfTi3BRLq9EkJFdg3eBbyERXGTntVpBxH1J68Q==",
|
||||||
|
"requires": {
|
||||||
|
"array-back": "2.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"ansi-escapes": {
|
"ansi-escapes": {
|
||||||
"version": "3.0.0",
|
"version": "3.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-3.0.0.tgz",
|
||||||
@ -256,6 +264,17 @@
|
|||||||
"typical": "2.6.1"
|
"typical": "2.6.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"command-line-usage": {
|
||||||
|
"version": "4.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/command-line-usage/-/command-line-usage-4.0.1.tgz",
|
||||||
|
"integrity": "sha512-IqYzZuXizukrdhnbdUj2hh4iceycow+Jn10mER4lwU4IapYvl5ZzoRPsj5Yraew5oRk4yfFKMuULGvAfb5o29w==",
|
||||||
|
"requires": {
|
||||||
|
"ansi-escape-sequences": "4.0.0",
|
||||||
|
"array-back": "2.0.0",
|
||||||
|
"table-layout": "0.4.2",
|
||||||
|
"typical": "2.6.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
|
||||||
@ -305,6 +324,11 @@
|
|||||||
"ms": "2.0.0"
|
"ms": "2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"deep-extend": {
|
||||||
|
"version": "0.5.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.5.0.tgz",
|
||||||
|
"integrity": "sha1-bvSgmwX5iw41jW2T1Mo8rsZnKAM="
|
||||||
|
},
|
||||||
"deep-is": {
|
"deep-is": {
|
||||||
"version": "0.1.3",
|
"version": "0.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
|
"resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz",
|
||||||
@ -961,6 +985,11 @@
|
|||||||
"integrity": "sha1-9HGh2khr5g9quVXRcRVSPdHSVdU=",
|
"integrity": "sha1-9HGh2khr5g9quVXRcRVSPdHSVdU=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"lodash.padend": {
|
||||||
|
"version": "4.6.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/lodash.padend/-/lodash.padend-4.6.1.tgz",
|
||||||
|
"integrity": "sha1-U8y6BH0G4VjTEfRdpiX05J5vFm4="
|
||||||
|
},
|
||||||
"lru-cache": {
|
"lru-cache": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-4.1.1.tgz",
|
||||||
@ -1251,6 +1280,11 @@
|
|||||||
"util-deprecate": "1.0.2"
|
"util-deprecate": "1.0.2"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"reduce-flatten": {
|
||||||
|
"version": "1.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/reduce-flatten/-/reduce-flatten-1.0.1.tgz",
|
||||||
|
"integrity": "sha1-JYx479FT3fk8tWEjf2EYTzaW4yc="
|
||||||
|
},
|
||||||
"require-uncached": {
|
"require-uncached": {
|
||||||
"version": "1.0.3",
|
"version": "1.0.3",
|
||||||
"resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz",
|
"resolved": "https://registry.npmjs.org/require-uncached/-/require-uncached-1.0.3.tgz",
|
||||||
@ -1456,6 +1490,18 @@
|
|||||||
"string-width": "2.1.1"
|
"string-width": "2.1.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"table-layout": {
|
||||||
|
"version": "0.4.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/table-layout/-/table-layout-0.4.2.tgz",
|
||||||
|
"integrity": "sha512-tygyl5+eSHj4chpq5Zfy6cpc7MOUBClAW9ozghFH7hg9bAUzShOYn+/vUzTRkKOSLJWKfgYtP2tAU2c0oAD8eg==",
|
||||||
|
"requires": {
|
||||||
|
"array-back": "2.0.0",
|
||||||
|
"deep-extend": "0.5.0",
|
||||||
|
"lodash.padend": "4.6.1",
|
||||||
|
"typical": "2.6.1",
|
||||||
|
"wordwrapjs": "3.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"test-value": {
|
"test-value": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/test-value/-/test-value-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/test-value/-/test-value-2.1.0.tgz",
|
||||||
@ -1553,6 +1599,15 @@
|
|||||||
"integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=",
|
"integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"wordwrapjs": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/wordwrapjs/-/wordwrapjs-3.0.0.tgz",
|
||||||
|
"integrity": "sha512-mO8XtqyPvykVCsrwj5MlOVWvSnCdT+C+QVbm6blradR7JExAhbkZ7hZ9A+9NUtwzSqrlUo9a67ws0EiILrvRpw==",
|
||||||
|
"requires": {
|
||||||
|
"reduce-flatten": "1.0.1",
|
||||||
|
"typical": "2.6.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"wrappy": {
|
"wrappy": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"command-line-args": "^4.0.7",
|
"command-line-args": "^4.0.7",
|
||||||
|
"command-line-usage": "^4.0.1",
|
||||||
"node-fetch": "^1.7.3"
|
"node-fetch": "^1.7.3"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
Reference in New Issue
Block a user