Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
topydo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
topydo
Commits
2dc073a9
Commit
2dc073a9
authored
Oct 19, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement del subcommand.
parent
a053904c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
132 additions
and
0 deletions
+132
-0
DeleteCommand.py
DeleteCommand.py
+52
-0
Main.py
Main.py
+3
-0
test/DeleteCommandTest.py
test/DeleteCommandTest.py
+77
-0
No files found.
DeleteCommand.py
0 → 100644
View file @
2dc073a9
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from
Command
import
*
from
TodoList
import
InvalidTodoException
from
Utils
import
convert_todo_number
,
InvalidTodoNumberException
class
DeleteCommand
(
Command
):
def
__init__
(
self
,
p_args
,
p_todolist
,
p_out
=
lambda
a
:
None
,
p_err
=
lambda
a
:
None
,
p_prompt
=
lambda
a
:
None
):
super
(
DeleteCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
self
.
number
=
None
try
:
self
.
number
=
convert_todo_number
(
self
.
argument
(
0
))
self
.
todo
=
self
.
todolist
.
todo
(
self
.
number
)
except
(
InvalidCommandArgument
,
InvalidTodoNumberException
,
InvalidTodoException
):
self
.
todo
=
None
def
execute
(
self
):
if
not
super
(
DeleteCommand
,
self
).
execute
():
return
False
if
not
self
.
number
:
self
.
error
(
self
.
usage
())
elif
self
.
todo
:
self
.
todolist
.
delete
(
self
.
todo
)
self
.
out
(
"Todo %d removed."
%
self
.
number
)
else
:
self
.
error
(
"Invalid todo number given."
)
def
usage
(
self
):
return
"""Synopsis: del <NUMBER>"""
def
help
(
self
):
return
"""Deletes the todo item with the given number from the list."""
Main.py
View file @
2dc073a9
...
...
@@ -23,6 +23,7 @@ import sys
from
AddCommand
import
AddCommand
from
AppendCommand
import
AppendCommand
from
ArchiveCommand
import
ArchiveCommand
from
DeleteCommand
import
DeleteCommand
from
DepCommand
import
DepCommand
from
DepriCommand
import
DepriCommand
import
Config
...
...
@@ -102,6 +103,7 @@ class CLIApplication(object):
'add'
:
AddCommand
,
'app'
:
AppendCommand
,
'append'
:
AppendCommand
,
'del'
:
DeleteCommand
,
'dep'
:
DepCommand
,
'depri'
:
DepriCommand
,
'do'
:
DoCommand
,
...
...
@@ -115,6 +117,7 @@ class CLIApplication(object):
'listproject'
:
ListProjectCommand
,
'listprojects'
:
ListProjectCommand
,
'pri'
:
PriorityCommand
,
'rm'
:
DeleteCommand
,
}
args
=
arguments
()
...
...
test/DeleteCommandTest.py
0 → 100644
View file @
2dc073a9
# Topydo - A todo.txt client written in Python.
# Copyright (C) 2014 Bram Schoenmakers <me@bramschoenmakers.nl>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import
CommandTest
import
DeleteCommand
import
TodoList
class
DeleteCommandTest
(
CommandTest
.
CommandTest
):
def
setUp
(
self
):
todos
=
[
"Foo id:1"
,
"Bar p:1"
,
]
self
.
todolist
=
TodoList
.
TodoList
(
todos
)
def
test_del1
(
self
):
command
=
DeleteCommand
.
DeleteCommand
([
"1"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
todolist
.
todo
(
1
).
source
(),
"Bar"
)
self
.
assertEquals
(
self
.
output
,
"Todo 1 removed.
\
n
"
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_del2
(
self
):
command
=
DeleteCommand
.
DeleteCommand
([
"2"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertTrue
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
todolist
.
todo
(
1
).
source
(),
"Foo"
)
self
.
assertEquals
(
self
.
output
,
"Todo 2 removed.
\
n
"
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_del3
(
self
):
command
=
DeleteCommand
.
DeleteCommand
([
"99"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
output
,
""
)
self
.
assertEquals
(
self
.
errors
,
"Invalid todo number given.
\
n
"
)
def
test_del4
(
self
):
command
=
DeleteCommand
.
DeleteCommand
([
"A"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
output
,
""
)
self
.
assertEquals
(
self
.
errors
,
command
.
usage
()
+
"
\
n
"
)
def
test_empty
(
self
):
command
=
DeleteCommand
.
DeleteCommand
([],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertFalse
(
self
.
output
)
self
.
assertEquals
(
self
.
errors
,
command
.
usage
()
+
"
\
n
"
)
def
test_help
(
self
):
command
=
DeleteCommand
.
DeleteCommand
([
"help"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertEquals
(
self
.
output
,
""
)
self
.
assertEquals
(
self
.
errors
,
command
.
usage
()
+
"
\
n
\
n
"
+
command
.
help
()
+
"
\
n
"
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment