mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Clement Denis
1bfda49bb8
|
4 years ago | |
---|---|---|
.. | ||
README.md | 4 years ago |
README.md
personal-shopper
Instructions
You know your guests, but don't forget you have to feed them if you want to be considered as a good host.
Create a personal-shopper.mjs
script that:
- Takes a file as first argument, for example
shopping-list.json
- Takes one of these keywords as second argument:
create
: create the filedelete
: delete the fileadd
: add a new element to the list in the file.- This command line must take a third argument which is the name of the new
entry in your list. If no third argument is passed, console must print
this error:
No elem specified.
. - This command line could take a fourth argument which is the number of
elements you want for this new entry.
- If there is no 4rth argument or the 4rth argument is
NaN
, 1 would be the value by default. - If the entry already exists, it would add 1 or more to the original value.
- Using a negative number must behave as
rm
command.
- If there is no 4rth argument or the 4rth argument is
- This command line must take a third argument which is the name of the new
entry in your list. If no third argument is passed, console must print
this error:
rm
: remove an element from the list in the file- This command line must take a third argument which is the name of the
entry to remove from the list.
- If no third argument is passed, console must print this error:
No elem specified.
. - If the entry does not exists, it does nothing.
- If no third argument is passed, console must print this error:
- This command line could take a fourth argument which is the number of
elements you want to delete from this entry.
- If there is no 4rth argument: it remove the entry.
- If the 4rth argument is
NaN
, nothing is removed and console must print this errorUnexpected request: nothing has been removed
. - If the 4rth argument is a number, it will substract this number from the original value (if the new value is <= 0, it will remove the entry).
- Using a negative number must behave as
add
command.
- This command line must take a third argument which is the name of the
entry to remove from the list.
help
: print all the command lines available, with a description of it (specifications in the examples)ls
or no more arguments: print the list in the console.- Each line is formated like this:
- element (number)
- If the list is empty, this message should appear in console:
Empty list.
.
- Each line is formated like this:
Examples
-
node personal-shopper.mjs shopping-list.json create
would create the file -
node personal-shopper.mjs shopping-list.json delete
would remove the file -
node personal-shopper.mjs shopping-list.json add "tzatziki pot"
would update the content of the file like:
'{
"tzatziki pot": 1
}'
node personal-shopper.mjs shopping-list.json add carrots 5
would update the content of the file like:
'{
"tzatziki pot": 1,
"carrots": 5
}'
node personal-shopper.mjs shopping-list.json add carrots 2
would update the content of the file like:
'{
"tzatziki pot": 1,
"carrots": 7
}'
node personal-shopper.mjs shopping-list.json rm carrots 4
would update the content of the file like:
'{
"tzatziki pot": 1,
"carrots": 3
}'
node personal-shopper.mjs shopping-list.json rm carrots
would update the content of the file like:
'{
"tzatziki pot": 1
}'
node personal-shopper.mjs shopping-list.json rm carrots -3
would update the content of the file like:
'{
"tzatziki pot": 1,
"carrots": 3
}'
node personal-shopper.mjs shopping-list.json add carrots -3
would update the content of the file like:
'{
"tzatziki pot": 1
}'
node personal-shopper.mjs shopping-list.json ls
would print the list in your console like this:
- tzatziki pot (1)
node personal-shopper.mjs help
would print a list of all available commands in your console :
Commands:
- create: takes a filename as argument and create it (should have `.json` extension specified)
- delete: takes a filename as argument and delete it
<!-- etc. -->