Author | Message |
---|---|
wevanw
Posts: 25
|
Posted 20:34 Mar 01, 2017 |
Hi, I see the characterCount function takes an array as argument: const characterCount = (files) => { But when the app calls this function, it takes flags.word/flags.character as argument: module.exports.run = (flags) => { if (flags.character) Could someone tell me why 'flags.character' is treated as an array? Thanks in advance! |
hippiewho
Posts: 46
|
Posted 21:02 Mar 01, 2017 |
Hello, In cli.js those arguments are defined as arrays: .options('c', { alias: 'character', describe: 'displays character count', array: true }) .options('w', { alias: 'word', describe: 'displays word count', array: true }) This is because you can supply two or more files to be counted. |
wevanw
Posts: 25
|
Posted 21:10 Mar 01, 2017 |
thanks, btw could you tell me what is the 'flags'? is it an array of arguments? and why can we use it like this: 'flags.word' ? as noted in homework, if we want to get the difficulty, why can't we use like this: 'flags.difficult.easy' ? Thanks for the answer again!
|
hippiewho
Posts: 46
|
Posted 21:28 Mar 01, 2017 |
flags is an object containing the arguments in key value pairs. You can see this by adding the line console.line(flags) in the cli.js file right before app.run().
"flags.difficulty.easy" is looking for a key called easy in the value with the key "difficulty". "flags.difficulty" will give you the argument you passed along with "node cli.js -d <arg>". I think if you add "console.line(flags)" it becomes more apparent as to why that doesnt work EDIT: I misspoke about "difficulty" not being accessible. Ive changed my response. Last edited by hippiewho at
01:17 Mar 02, 2017.
|