Skip to content

Instantly share code, notes, and snippets.

@harryWonder
Created May 26, 2020 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harryWonder/57399e9be8e28d9f9d9dfb7fc76c08c7 to your computer and use it in GitHub Desktop.
Save harryWonder/57399e9be8e28d9f9d9dfb7fc76c08c7 to your computer and use it in GitHub Desktop.
This file serves as the entry point into our application by executing different commands from the terminal.
//Node Modules....
const Yargs = require('yargs');
//Custom Modules....
const Notes = require('./app/Notes');
const Weather = require('./app/Weather');
//App Initialization...
const YargsArgV = Yargs
.command('add', 'Adds A New Note', {
title: {
alias: 't',
demand: true,
describe: 'Add a title for your new Note.',
},
body: {
alias: 'b',
demand: true,
describe: 'Add a body for your new Note.'
}
})
.command('list', 'List all notes.', {
status: {
alias: 's',
demand: false,
describe: 'Fetches all notes with a status type of completed and pending'
}
})
.command('fetchNote', 'Fetch a particular Note.', {
title: {
alias: 't',
demand: true,
describe: 'Fetch a Note with this title.'
}
}).command('completeNote', 'Completes a Note with this title', {
title: {
alias: 't',
demand: true,
describe: 'Marks a Note with a status of completed.'
}
}).command('updateNote', 'Updates a Note with this title', {
title: {
alias: 't',
demand: true,
describe: 'Updates a Note with this title.'
},
body: {
alias: 'b',
demand: true,
describe: 'A New content for the note.'
}
})
.command('deleteNote', 'Deletes a particular Note', {
title: {
alias: 't',
demand: true,
describe: 'Deletes a Note with this title.'
}
}).command('fetchWeather', 'Fetches information about the weather for a specific city', {
city: {
alias: 'c',
demand: true,
describe: 'Fetches information about the weather for this city.'
}
})
.help().argv;
//Fetch cli command...
const Command = YargsArgV._[0];
//Cli commands...
if (Command === 'add')
Notes.createNote( YargsArgV.title, YargsArgV.body );
else if (Command === 'list')
Notes.listNotes( YargsArgV.status );
else if (Command === 'fetchNote')
Notes.fetchNote( YargsArgV.title );
else if (Command == 'completeNote')
Notes.completeNote( YargsArgV.title );
else if (Command == 'updateNote')
Notes.updateNote( YargsArgV.title, YargsArgV.body );
else if (Command === 'deleteNote')
Notes.deleteNote( YargsArgV.title );
else if (Command == 'fetchWeather')
Weather.getWeather( YargsArgV.city );
else
console.log( 'Command not recognized...' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment