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
5b948f08
Commit
5b948f08
authored
Oct 19, 2014
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to supply a custom sort string to the list command.
parent
e976c062
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
6 deletions
+35
-6
lib/ListCommand.py
lib/ListCommand.py
+27
-6
test/ListCommandTest.py
test/ListCommandTest.py
+8
-0
No files found.
lib/ListCommand.py
View file @
5b948f08
...
...
@@ -14,6 +14,8 @@
# 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
getopt
import
Command
import
Config
import
Filter
...
...
@@ -26,22 +28,39 @@ class ListCommand(Command.Command):
p_prompt
=
lambda
a
:
None
):
super
(
ListCommand
,
self
).
__init__
(
p_args
,
p_todolist
,
p_out
,
p_err
,
p_prompt
)
self
.
sort_expression
=
Config
.
SORT_STRING
self
.
show_all
=
False
def
_process_flags
(
self
):
try
:
opts
,
args
=
getopt
.
getopt
(
self
.
args
,
's:x'
)
except
getopt
.
GetoptError
:
return
self
.
args
for
o
,
a
in
opts
:
if
o
==
'-x'
:
self
.
show_all
=
True
elif
o
==
'-s'
:
self
.
sort_expression
=
a
return
args
def
execute
(
self
):
if
not
super
(
ListCommand
,
self
).
execute
():
return
False
show_all
=
self
.
argument_shift
(
"-x"
)
args
=
self
.
_process_flags
(
)
sorter
=
Sorter
.
Sorter
(
Config
.
SORT_STRING
)
filters
=
[]
if
show_all
else
[
Filter
.
DependencyFilter
(
self
.
todolist
),
Filter
.
RelevanceFilter
()]
sorter
=
Sorter
.
Sorter
(
self
.
sort_expression
)
filters
=
[]
if
s
elf
.
s
how_all
else
[
Filter
.
DependencyFilter
(
self
.
todolist
),
Filter
.
RelevanceFilter
()]
if
len
(
self
.
args
)
>
0
:
filters
.
append
(
Filter
.
GrepFilter
(
self
.
argument
(
0
)
))
if
len
(
args
)
>
0
:
filters
.
append
(
Filter
.
GrepFilter
(
args
[
0
]
))
self
.
out
(
self
.
todolist
.
view
(
sorter
,
filters
).
pretty_print
())
def
usage
(
self
):
return
"""Synopsis: ls [-x] [expression]"""
return
"""Synopsis: ls [-x] [
-s <sort_expression>] [
expression]"""
def
help
(
self
):
return
"""Lists all relevant todos. A todo is relevant when:
...
...
@@ -52,4 +71,6 @@ class ListCommand(Command.Command):
When an expression is given, only the todos matching that expression are shown.
-s : Sort the list according to a sort expression. Defaults to the expression
in the configuration.
-x : Show all todos (i.e. do not filter on dependencies or relevance)."""
test/ListCommandTest.py
View file @
5b948f08
...
...
@@ -62,6 +62,14 @@ class ListCommandTest(CommandTest.CommandTest):
self
.
assertEquals
(
self
.
output
,
""
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_list7
(
self
):
command
=
ListCommand
.
ListCommand
([
"-s"
,
"text"
,
"-x"
,
"Project1"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
self
.
assertFalse
(
self
.
todolist
.
is_dirty
())
self
.
assertEquals
(
self
.
output
,
" 3 (C) Baz @Context1 +Project1 key:value id:1
\
n
1 (C) Foo @Context2 Not@Context +Project1 Not+Project
\
n
"
)
self
.
assertEquals
(
self
.
errors
,
""
)
def
test_help
(
self
):
command
=
ListCommand
.
ListCommand
([
"help"
],
self
.
todolist
,
self
.
out
,
self
.
error
)
command
.
execute
()
...
...
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