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
fb445f42
Commit
fb445f42
authored
Dec 16, 2015
by
Bram Schoenmakers
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #85 from mruwek/aliases
Create placeholder for args in aliases
parents
c0d74920
56967191
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
1 deletion
+25
-1
test/data/aliases.conf
test/data/aliases.conf
+1
-0
test/test_get_sub_command.py
test/test_get_sub_command.py
+9
-0
topydo.conf
topydo.conf
+2
-0
topydo/Commands.py
topydo/Commands.py
+13
-1
No files found.
test/data/aliases.conf
View file @
fb445f42
...
...
@@ -3,3 +3,4 @@ foo = rm -f test
baz
=
FooBar
format
=
ls
-
F
"|I| x c d {(}p{)} s k"
-
n
25
smile
=
ls
☻
star
=
tag
{}
star
1
test/test_get_sub_command.py
View file @
fb445f42
...
...
@@ -22,6 +22,7 @@ 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
class
GetSubcommandTest
(
TopydoTest
):
...
...
@@ -60,6 +61,14 @@ class GetSubcommandTest(TopydoTest):
self
.
assertTrue
(
issubclass
(
real_cmd
,
ListCommand
))
self
.
assertEqual
(
final_args
,
[
u"
\
u263b
"
])
def
test_alias04
(
self
):
config
(
"test/data/aliases.conf"
)
args
=
[
"star"
,
"foo"
]
real_cmd
,
final_args
=
get_subcommand
(
args
)
self
.
assertTrue
(
issubclass
(
real_cmd
,
TagCommand
))
self
.
assertEqual
(
final_args
,
[
"foo"
,
"star"
,
"1"
])
def
test_default_cmd01
(
self
):
args
=
[
"bar"
]
real_cmd
,
final_args
=
get_subcommand
(
args
)
...
...
topydo.conf
View file @
fb445f42
...
...
@@ -53,6 +53,8 @@ append_parent_contexts = 0
;
showall
=
ls
-
x
;
next
=
ls
-
n
1
;
top
=
ls
-
F
'%I %x %P %S %k %{(}H{)}'
-
N
;
star
=
tag
{}
star
1
;
unstar
=
tag
{}
star
;
lsproj
=
lsprj
;
listprj
=
lsprj
;
listproj
=
lsprj
...
...
topydo/Commands.py
View file @
fb445f42
...
...
@@ -71,6 +71,18 @@ def get_subcommand(p_args):
__import__
(
modulename
,
globals
(),
locals
(),
[
classname
],
0
)
return
getattr
(
sys
.
modules
[
modulename
],
classname
)
def
join_args
(
p_cli_args
,
p_alias_args
):
"""
Returns properly joined args from alias definition and from user input.
"""
if
'{}'
in
p_alias_args
:
pos
=
p_alias_args
.
index
(
'{}'
)
args
=
p_alias_args
[:
pos
]
+
p_cli_args
+
p_alias_args
[
pos
+
1
:]
else
:
args
=
p_alias_args
+
p_cli_args
return
args
def
resolve_alias
(
p_alias
,
p_args
):
"""
Resolves a subcommand alias and returns a tuple (Command, args).
...
...
@@ -81,7 +93,7 @@ def get_subcommand(p_args):
real_subcommand
,
alias_args
=
alias_map
[
p_alias
]
try
:
result
=
import_subcommand
(
real_subcommand
)
args
=
alias_args
+
p_args
args
=
join_args
(
p_args
,
alias_args
)
return
(
result
,
args
)
except
KeyError
:
return
get_subcommand
([
'help'
])
...
...
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