Now in order to get started, we need to make some changes inside of app.js. We're going to start with the add command (for more information, please refer to the Adding and saving notes section in the previous chapter).
We want to add a few helpful pieces of information in argv function inside app.js, that will:
- Let yargs verify the add command is ran appropriately, and
- Let the user know how the add command is meant to be executed
Now we are going to be chaining property calls, which means right before I access .argv I want to call .command, and then I'll call .argv on the return value from command as shown here:
const argv = yargs
.command()
.argv;
Now this chaining syntax probably looks familiar if you've used jQuery, a lot of different libraries are supported. Once we call .command on yargs, we're going to pass in three arguments.
The first one is the command name, exactly how the user is going to type it in Terminal, in our case it's going to be add:
const argv = yargs
.command('add')
.argv;
Then we're going to pass another string in, and this is going to be a description of what the command does. It is going to be some sort of English readable description that a user can read to figure out weather that's the command that they want to run:
const argv = yargs
.command('add', 'Add a new note')
.argv;
The next one is going to be an object. This is going to be the options object that lets us specify what arguments this command requires.