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
4b8c8f09
Commit
4b8c8f09
authored
Feb 23, 2016
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #108 from mruwek/fix_107
Don't crash on shlex.split error
parents
25dd79b5
b2f34ad9
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
10 deletions
+38
-10
test/data/aliases.conf
test/data/aliases.conf
+1
-0
test/test_get_sub_command.py
test/test_get_sub_command.py
+10
-2
topydo/Commands.py
topydo/Commands.py
+6
-2
topydo/cli/CLI.py
topydo/cli/CLI.py
+5
-1
topydo/cli/Prompt.py
topydo/cli/Prompt.py
+8
-1
topydo/lib/Config.py
topydo/lib/Config.py
+8
-4
No files found.
test/data/aliases.conf
View file @
4b8c8f09
...
...
@@ -4,3 +4,4 @@ baz = FooBar
format
=
ls
-
F
"|I| x c d {(}p{)} s k"
-
n
25
smile
=
ls
☻
star
=
tag
{}
star
1
quot
=
lol
'
d
test/test_get_sub_command.py
View file @
4b8c8f09
...
...
@@ -21,9 +21,8 @@ from topydo.Commands import get_subcommand
from
topydo.commands.AddCommand
import
AddCommand
from
topydo.commands.DeleteCommand
import
DeleteCommand
from
topydo.commands.ListCommand
import
ListCommand
from
topydo.commands.ListProjectCommand
import
ListProjectCommand
from
topydo.commands.TagCommand
import
TagCommand
from
topydo.lib.Config
import
config
from
topydo.lib.Config
import
config
,
ConfigError
class
GetSubcommandTest
(
TopydoTest
):
def
test_normal_cmd
(
self
):
...
...
@@ -120,6 +119,15 @@ class GetSubcommandTest(TopydoTest):
real_cmd
,
final_args
=
get_subcommand
(
args
)
self
.
assertEqual
(
real_cmd
,
None
)
def
test_alias_quotation
(
self
):
config
(
"test/data/aliases.conf"
)
args
=
[
"quot"
]
with
self
.
assertRaises
(
ConfigError
)
as
ce
:
get_subcommand
(
args
)
self
.
assertEqual
(
str
(
ce
.
exception
),
'No closing quotation'
)
def
test_help
(
self
):
real_cmd
,
final_args
=
get_subcommand
([
'help'
,
'nonexisting'
])
self
.
assertFalse
(
real_cmd
)
...
...
topydo/Commands.py
View file @
4b8c8f09
...
...
@@ -21,7 +21,7 @@ instance based on an argument list.
import
sys
from
topydo.lib.Config
import
config
from
topydo.lib.Config
import
config
,
ConfigError
_SUBCOMMAND_MAP
=
{
'add'
:
'AddCommand'
,
...
...
@@ -90,7 +90,11 @@ def get_subcommand(p_args):
If alias resolves to non-existent command, main help message is
returned.
"""
real_subcommand
,
alias_args
=
alias_map
[
p_alias
]
try
:
real_subcommand
,
alias_args
=
alias_map
[
p_alias
]
except
ValueError
as
ve
:
raise
ConfigError
(
alias_map
[
p_alias
])
from
ve
try
:
result
=
import_subcommand
(
real_subcommand
)
args
=
join_args
(
p_args
,
alias_args
)
...
...
topydo/cli/CLI.py
View file @
4b8c8f09
...
...
@@ -50,7 +50,11 @@ class CLIApplication(CLIApplicationBase):
self
.
todofile
=
TodoFile
.
TodoFile
(
config
().
todotxt
())
self
.
todolist
=
TodoList
.
TodoList
(
self
.
todofile
.
read
())
(
subcommand
,
args
)
=
get_subcommand
(
args
)
try
:
(
subcommand
,
args
)
=
get_subcommand
(
args
)
except
ConfigError
as
ce
:
error
(
'Error: '
+
str
(
ce
)
+
'. Check your aliases configuration'
)
sys
.
exit
(
1
)
if
subcommand
is
None
:
self
.
_usage
()
...
...
topydo/cli/Prompt.py
View file @
4b8c8f09
...
...
@@ -99,9 +99,16 @@ class PromptApplication(CLIApplicationBase):
sys
.
exit
(
0
)
except
KeyboardInterrupt
:
continue
except
ValueError
as
verr
:
error
(
'Error: '
+
str
(
verr
))
mtime_after
=
_todotxt_mtime
()
(
subcommand
,
args
)
=
get_subcommand
(
user_input
)
try
:
(
subcommand
,
args
)
=
get_subcommand
(
user_input
)
except
ConfigError
as
ce
:
error
(
'Error: '
+
str
(
ce
)
+
'. Check your aliases configuration'
)
continue
# refuse to perform operations such as 'del' and 'do' if the
# todo.txt file has been changed in the background.
...
...
topydo/lib/Config.py
View file @
4b8c8f09
...
...
@@ -18,6 +18,7 @@ import configparser
import
os
import
shlex
class
ConfigError
(
Exception
):
def
__init__
(
self
,
p_text
):
self
.
text
=
p_text
...
...
@@ -299,10 +300,13 @@ class _Config:
alias_dict
=
dict
()
for
alias
,
meaning
in
aliases
:
meaning
=
shlex
.
split
(
meaning
)
real_subcommand
=
meaning
[
0
]
alias_args
=
meaning
[
1
:]
alias_dict
[
alias
]
=
(
real_subcommand
,
alias_args
)
try
:
meaning
=
shlex
.
split
(
meaning
)
real_subcommand
=
meaning
[
0
]
alias_args
=
meaning
[
1
:]
alias_dict
[
alias
]
=
(
real_subcommand
,
alias_args
)
except
ValueError
as
verr
:
alias_dict
[
alias
]
=
str
(
verr
)
return
alias_dict
...
...
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