diff --git a/cmsc388b/code_along/weather/.gitignore b/cmsc388b/code_along/weather/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..94374a6a35df952ae6bb401ff2d6f2c6eebee378 --- /dev/null +++ b/cmsc388b/code_along/weather/.gitignore @@ -0,0 +1,5 @@ +# only relevant for Mac systems +.DS_STORE + +#ingore npm packages +node_modules diff --git a/cmsc388b/code_along/weather/bin/weather b/cmsc388b/code_along/weather/bin/weather new file mode 100755 index 0000000000000000000000000000000000000000..17ee5bce51ebd50d0b88d41c56873bca3a5c3361 --- /dev/null +++ b/cmsc388b/code_along/weather/bin/weather @@ -0,0 +1,5 @@ +#!/usr/bin/env node +// require('../')() +var index = require('../index') +index() +//console.log("Another way to run a node application"); \ No newline at end of file diff --git a/cmsc388b/code_along/weather/cmds/foo.js b/cmsc388b/code_along/weather/cmds/foo.js new file mode 100644 index 0000000000000000000000000000000000000000..5e0f233f0c95995096aa115a7efbeb2bb668adba --- /dev/null +++ b/cmsc388b/code_along/weather/cmds/foo.js @@ -0,0 +1 @@ +console.log("executing the foo command"); \ No newline at end of file diff --git a/cmsc388b/code_along/weather/cmds/help.js b/cmsc388b/code_along/weather/cmds/help.js new file mode 100644 index 0000000000000000000000000000000000000000..5ab2f4e36024b87fd9293998d34cd6776df1c5e7 --- /dev/null +++ b/cmsc388b/code_along/weather/cmds/help.js @@ -0,0 +1,21 @@ +const menus = { + main: ` + weather [command] <options> + + today .............. show weather for today + version ............ show package version + help ............... show help menu for a command`, + + today: ` + weather today <options> + + --location, -l ..... the location to use`, +} + +module.exports = (args) => { + const subCmd = args._[0] === 'help' + ? args._[1] + : args._[0] + + console.log(menus[subCmd] || menus.main) +} \ No newline at end of file diff --git a/cmsc388b/code_along/weather/cmds/today.js b/cmsc388b/code_along/weather/cmds/today.js new file mode 100644 index 0000000000000000000000000000000000000000..a5668fd8e80a2f6bb32907f3563b6b6d0114f1e5 --- /dev/null +++ b/cmsc388b/code_along/weather/cmds/today.js @@ -0,0 +1,3 @@ +module.exports = (args) => { + console.log('today is sunny') +} diff --git a/cmsc388b/code_along/weather/cmds/version.js b/cmsc388b/code_along/weather/cmds/version.js new file mode 100644 index 0000000000000000000000000000000000000000..b7783f041dce707d4ff1f7e5fbb408f43bf358ae --- /dev/null +++ b/cmsc388b/code_along/weather/cmds/version.js @@ -0,0 +1,5 @@ +const { version } = require('../package.json') + +module.exports = (args) => { + console.log(`v${version}`) +} diff --git a/cmsc388b/code_along/weather/index.js b/cmsc388b/code_along/weather/index.js new file mode 100644 index 0000000000000000000000000000000000000000..40ba40a1243ca4c1a1ba515d613b5cff39a74f30 --- /dev/null +++ b/cmsc388b/code_along/weather/index.js @@ -0,0 +1,25 @@ +const minimist = require('minimist') + +module.exports = () => { + const args = minimist(process.argv.slice(2)) + //console.log(args); + const cmd = args._[0] + console.log(cmd); + switch (cmd) { + case 'today': + require('./cmds/today')(args) + break + case 'foo': + require('./cmds/foo') + break + case 'version': + require('./cmds/version')(args) + break + case 'help': + require('./cmds/help')(args) + break + default: + console.error(`"${cmd}" is not a valid command!`) + break + } +} diff --git a/cmsc388b/code_along/weather/package-lock.json b/cmsc388b/code_along/weather/package-lock.json new file mode 100644 index 0000000000000000000000000000000000000000..4695dab160dde04468dc0847918740e5c0096231 --- /dev/null +++ b/cmsc388b/code_along/weather/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "weather", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "minimist": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=" + } + } +} diff --git a/cmsc388b/code_along/weather/package.json b/cmsc388b/code_along/weather/package.json new file mode 100644 index 0000000000000000000000000000000000000000..cb9a50a3d85fb9293ae4eb67dfefc0324434a5f9 --- /dev/null +++ b/cmsc388b/code_along/weather/package.json @@ -0,0 +1,17 @@ +{ + "name": "weather", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "bin": { + "weather": "bin/weather" + }, + "dependencies": { + "minimist": "^1.2.0" + } +}