Skip to content
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

Vignesh cli-todo #152

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"todoItems":["1. [ ] - watch Netflix","2. [ ] - buy grocery","3. [ ] - send email","4. [ ] - check letterbox","5. [ ] - take medicine"]}
48 changes: 37 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,45 @@
console.log("works!!", process.argv[2]);

var commandType = process.argv[2];
let command = process.argv[2];
let taskItem = process.argv[3];

console.log("Your command was: "+commandType);
let unmarked = " ";
let marked = "x";

const jsonfile = require('jsonfile');

const file = 'data.json'
const fileName = 'data.json'


const addData = (error, toDoList) => {
console.log(toDoList);
//adding task items to the list
if ( command === "add"){
// let itemsCount = toDoList['todoItems'].push(taskItem);
// console.log("the item add is " + itemsCount);
//create an output format
let itemsCount = toDoList['todoItems'].length + 1
let formattedData = itemsCount + "." + " [" + unmarked + "]" + " - " + taskItem;
console.log("the output is " + formattedData);
let addedItems = toDoList['todoItems'].push(formattedData);
console.log(addedItems);
console.log(toDoList['todoItems']);
//console.log(toDoList['todoItems'][0]);
}
if ( command === "show"){
for ( let i = 0; i < toDoList['todoItems'].length; i++){
console.log(toDoList['todoItems'][i]);
}
}


jsonfile.writeFile(fileName, toDoList)

}


jsonfile.readFile(fileName, addData)
console.log("read File")


jsonfile.readFile(file, (err, obj) => {

console.log(obj);
obj["helloworld"] = "monkey";

jsonfile.writeFile(file, obj, (err) => {
console.log(err)
});
});
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "cli-todo",
"version": "1.0.0",
"description": "![https://i.giphy.com/media/26ufnwz3wDUli7GU0/giphy.webp](https://i.giphy.com/media/26ufnwz3wDUli7GU0/giphy.webp)",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vigbit/cli-todo.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/vigbit/cli-todo/issues"
},
"homepage": "https://github.com/vigbit/cli-todo#readme",
"dependencies": {
"jsonfile": "^6.0.1"
}
}