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

Nausheen-S_created_part_1 #145

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":["eat_bak_kut_teh","go_shopping","feed_dog","swim_practice","code_app","meet_gabriel","meet_gabriel_again","checking"]}
90 changes: 83 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,95 @@
console.log("works!!", process.argv[2]);

var commandType = process.argv[2];

console.log("Your command was: "+commandType);

const jsonfile = require('jsonfile');
/*const jsonfile = require('jsonfile');

const file = 'data.json'

jsonfile.readFile(file, (err, obj) => {
console.log(obj)
if(obj.array === undefined){
obj.array = [];
obj.array.push(process.argv[3]);
}else{
obj.array.push(process.argv[3]);
}

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

jsonfile.writeFile(file, obj, (err) => {
console.log(err)
});
});*/
var actionToPerform = process.argv[2];
const jsonfile = require('jsonfile');

const file = 'data.json'

jsonfile.readFile(file, (err, obj) => {
if(process.argv[2] === "add"){
obj["todoItems"].push(process.argv[3])
}else if(process.argv[2] === "show"){
for(let i = 0; i < obj["todoItems"].length; i++){
console.log(i + 1 +". [ ] - " + obj["todoItems"][i]);
}
}
//console.log(obj);
jsonfile.writeFile(file, obj, (err) => {
console.log(err)
});
});
/*var commandType = process.argv[2];
var inputString = function(){
var stringArr = process.argv;
var remove = stringArr.splice(0,3);
// console.log(remove);
var outString = "";
for (id in stringArr){
outString += stringArr[id];
outString += " ";
}
return outString;
}
const jsonfile = require('jsonfile');

const file = 'data.json'

jsonfile.readFile(file, (err, obj) => {
switch (commandType) {
case "show":
show(obj.todoItems);
break;
case "add":
add(obj.todoItems);
break;
default:
break;
}
// console.log(obj);
jsonfile.writeFile(file, obj, (err) => {
if (err != null || err != undefined) {
console.log(err)
}

});
});

function show(list) {
if (list.length == 0) {
console.log("List is empty...");
} else if (list.length > 0) {
var listOut = "";
for (id in list){
listOut += `${parseInt(id)+1}. [ ] - ${list[id]}\n`;
}
listOut = listOut.trim();
console.log(listOut);
}

}

function add(list) {
var input = inputString().trim();
list.push(input);
show(list);

}*/
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/Nausheen-S/cli-todo.git"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/Nausheen-S/cli-todo/issues"
},
"homepage": "https://github.com/Nausheen-S/cli-todo#readme",
"dependencies": {
"jsonfile": "^6.0.1"
}
}