From 4ba92bcfaf638a474bf5040b6cdfe2f612aeaf27 Mon Sep 17 00:00:00 2001
From: Andrej Rasevic <andrej@rasevicengineering.com>
Date: Thu, 10 Jan 2019 17:58:11 -0500
Subject: [PATCH] first iteration of weather app

---
 cmsc388b/code_along/weather/.gitignore        |  5 ++++
 cmsc388b/code_along/weather/bin/weather       |  5 ++++
 cmsc388b/code_along/weather/cmds/foo.js       |  1 +
 cmsc388b/code_along/weather/cmds/help.js      | 21 ++++++++++++++++
 cmsc388b/code_along/weather/cmds/today.js     |  3 +++
 cmsc388b/code_along/weather/cmds/version.js   |  5 ++++
 cmsc388b/code_along/weather/index.js          | 25 +++++++++++++++++++
 cmsc388b/code_along/weather/package-lock.json | 13 ++++++++++
 cmsc388b/code_along/weather/package.json      | 17 +++++++++++++
 9 files changed, 95 insertions(+)
 create mode 100644 cmsc388b/code_along/weather/.gitignore
 create mode 100755 cmsc388b/code_along/weather/bin/weather
 create mode 100644 cmsc388b/code_along/weather/cmds/foo.js
 create mode 100644 cmsc388b/code_along/weather/cmds/help.js
 create mode 100644 cmsc388b/code_along/weather/cmds/today.js
 create mode 100644 cmsc388b/code_along/weather/cmds/version.js
 create mode 100644 cmsc388b/code_along/weather/index.js
 create mode 100644 cmsc388b/code_along/weather/package-lock.json
 create mode 100644 cmsc388b/code_along/weather/package.json

diff --git a/cmsc388b/code_along/weather/.gitignore b/cmsc388b/code_along/weather/.gitignore
new file mode 100644
index 0000000..94374a6
--- /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 0000000..17ee5bc
--- /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 0000000..5e0f233
--- /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 0000000..5ab2f4e
--- /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 0000000..a5668fd
--- /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 0000000..b7783f0
--- /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 0000000..40ba40a
--- /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 0000000..4695dab
--- /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 0000000..cb9a50a
--- /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"
+  }
+}
-- 
GitLab