-
Notifications
You must be signed in to change notification settings - Fork 12
01 Caleb - Node CLI Greeting app #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
maschigokae
wants to merge
8
commits into
codefellows-seattle-javascript-401d12:master
Choose a base branch
from
maschigokae:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
81a13af
add some code to my lab project
maschigokae afd4126
set up functions to print welcome message, define name as cli user in…
maschigokae 7f39426
add eslintrc file
maschigokae ac82fd5
build out greeting message app functionality
maschigokae 8297227
build out basic tests
maschigokae 2f32fc2
rename code.js to greet.js
maschigokae 8dbd5e2
add error handling for empty name exception
maschigokae 0b25e84
add nested describe statement for welcome function
maschigokae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "rules": { | ||
| "no-console": "off", | ||
| "indent": [ "error", 2 ], | ||
| "quotes": [ "error", "single" ], | ||
| "semi": ["error", "always"], | ||
| "linebreak-style": [ "error", "unix" ] | ||
| }, | ||
| "env": { | ||
| "es6": true, | ||
| "node": true, | ||
| "mocha": true, | ||
| "jasmine": true | ||
| }, | ||
| "ecmaFeatures": { | ||
| "modules": true, | ||
| "experimentalObjectRestSpread": true, | ||
| "impliedStrict": true | ||
| }, | ||
| "extends": "eslint:recommended" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| 'use strict'; | ||
|
|
||
| const greeting = require('./lib/greeting.js'); | ||
|
|
||
| // set name as user inputed command line argument following 'node' and filename | ||
| var name = process.argv[process.argv.length - 1]; | ||
|
|
||
| greeting.welcome(name); | ||
| greeting.farewell(name); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = exports = {}; | ||
|
|
||
| exports.welcome = function(name) { | ||
| if (/[^a-z]/i.test(name)) throw new Error('non-alphabetical characters not allowed, or no name provided'); | ||
| if (arguments.length === 0) throw new Error('no name provided'); | ||
| var welcomeMessage = `Hello and welcome, ${name}! Glad you can be here!`; | ||
| console.log(welcomeMessage); | ||
| return welcomeMessage; | ||
| }; | ||
|
|
||
| exports.farewell = function(name) { | ||
| var farewellMessage = `Glad you could stay for a while, ${name}! Bye and see you next time!`; | ||
| console.log(farewellMessage); | ||
| return farewellMessage; | ||
| }; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stoked to see some RegEx in there to take care of another possible error! |
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| 'use strict'; | ||
|
|
||
| const greeting = require('../lib/greeting.js'); | ||
|
|
||
| const assert = require('assert'); | ||
|
|
||
| describe('Greeting', function() { | ||
| describe('#welcome', function() { | ||
| it('should print a greeting message customized with the user\'s inputted name.', function() { | ||
| var result = greeting.welcome('Caleb'); | ||
| assert.ok(result === 'Hello and welcome, Caleb! Glad you can be here!', 'greeting not printed as expected'); | ||
| }); | ||
| it('should throw an error indicating a missing name or unexpected charater', function() { | ||
| assert.throws(function() { | ||
| greeting.welcome(); | ||
| }, 'error not thrown'); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good use of process.argv! You could have also set var name = process.argv[2]
With node, the first element in the argv array on the global process object is literally 'node' followed by the filename you wish to run as the second element at the 1st index of the argv array, leaving process.argv[2] to represent your command line argument you wish to use for var name. For instance: node index.js
being located at and represented by process.argv[2] :)