Skip to content

Commit d16bdf6

Browse files
author
Sahil
committed
Structure the Todo CLI Project
1 parent 48ad2a5 commit d16bdf6

File tree

6 files changed

+79
-8
lines changed

6 files changed

+79
-8
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*_live/
2+
__pycache__
3+
.vscode/

todo_cli/README.md

+11-8
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@ source venv/bin/activate
2323

2424
## Commands
2525

26-
1. `todo lists`
27-
2. `todo use list`
28-
3. `item add item_names`
29-
4. `item list`
30-
5. `item edit item_id new_item_name`
31-
6. `item remove item_id`
32-
7. `item complete item_id`
33-
8. `item incomplete item_id`
26+
1. `list show`
27+
2. `list use list_name`
28+
3. `list create list_name`
29+
3. `todo add item_names`
30+
4. `todo all`
31+
5. `todo edit item_id new_item_name`
32+
6. `todo remove item_id`
33+
7. `todo complete item_id`
34+
8. `todo incomplete item_id`
35+
9. `help`
36+
10. `quit`

todo_cli/app.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from commands import commands_dict
2+
3+
def parse(command):
4+
"""
5+
Takes the command as input and returns the command name and args
6+
"""
7+
cmd_list = command.split()
8+
cmd_type = cmd_list[0]
9+
if (cmd_type == 'help' or cmd_type == 'quit'):
10+
return cmd_type, []
11+
elif (cmd_type == 'list' or cmd_type == 'todo'):
12+
return cmd_list[1], cmd_list[2:]
13+
else:
14+
return 'invalid', []
15+
16+
def main():
17+
print('Started the Todo application...')
18+
19+
while(1):
20+
# take the command as input from the user
21+
command = input()
22+
command_name, command_args = parse(command)
23+
print(command_name, command_args)
24+
25+
if __name__ == '__main__':
26+
main()

todo_cli/commands/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import commands.lists
2+
import commands.todos
3+
4+
commands_dict = {
5+
'show': lists.show_lists,
6+
'use': lists.use_list,
7+
'create': lists.create_list,
8+
'add': todos.add_item,
9+
'all': todos.show_items,
10+
'edit': todos.edit_item,
11+
'remove': todos.remove_item,
12+
'complete': todos.complete_item,
13+
'incomplete': todos.incomplete_item
14+
}

todo_cli/commands/lists.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def show_lists(args):
2+
print(args)
3+
4+
def use_list(args):
5+
print(args)
6+
7+
def create_list(args):
8+
print(args)

todo_cli/commands/todos.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
def add_item(args):
2+
print(args)
3+
4+
def show_items(args):
5+
print(args)
6+
7+
def edit_item(args):
8+
print(args)
9+
10+
def remove_item(args):
11+
print(args)
12+
13+
def complete_item(args):
14+
print(args)
15+
16+
def incomplete_item(args):
17+
print(args)

0 commit comments

Comments
 (0)