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
727a980b
Commit
727a980b
authored
Oct 21, 2015
by
Jacek Sowiński
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make aliases capable of being the default_command
Also move resolving aliases logic to a function.
parent
9088cd37
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
8 deletions
+22
-8
topydo/Commands.py
topydo/Commands.py
+22
-8
No files found.
topydo/Commands.py
View file @
727a980b
...
@@ -79,6 +79,21 @@ def get_subcommand(p_args):
...
@@ -79,6 +79,21 @@ def get_subcommand(p_args):
__import__
(
modulename
,
globals
(),
locals
(),
[
classname
],
0
)
__import__
(
modulename
,
globals
(),
locals
(),
[
classname
],
0
)
return
getattr
(
sys
.
modules
[
modulename
],
classname
)
return
getattr
(
sys
.
modules
[
modulename
],
classname
)
def
resolve_alias
(
p_alias
,
p_args
):
"""
Resolves a subcommand alias and returns a tuple (Command, args).
If alias resolves to non-existent command, main help message is
returned.
"""
real_subcommand
,
alias_args
=
alias_map
[
p_alias
]
try
:
result
=
import_subcommand
(
real_subcommand
)
args
=
alias_args
+
p_args
return
(
result
,
args
)
except
KeyError
:
return
get_subcommand
([
'help'
])
result
=
None
result
=
None
args
=
p_args
args
=
p_args
alias_map
=
config
().
aliases
()
alias_map
=
config
().
aliases
()
...
@@ -87,12 +102,7 @@ def get_subcommand(p_args):
...
@@ -87,12 +102,7 @@ def get_subcommand(p_args):
subcommand
=
p_args
[
0
]
subcommand
=
p_args
[
0
]
if
subcommand
in
alias_map
:
if
subcommand
in
alias_map
:
real_subcommand
,
alias_args
=
alias_map
[
subcommand
]
result
,
args
=
resolve_alias
(
subcommand
,
args
[
1
:])
try
:
result
=
import_subcommand
(
real_subcommand
)
args
=
alias_args
+
args
[
1
:]
except
ImportError
:
pass
elif
subcommand
in
_SUBCOMMAND_MAP
:
elif
subcommand
in
_SUBCOMMAND_MAP
:
result
=
import_subcommand
(
subcommand
)
result
=
import_subcommand
(
subcommand
)
args
=
args
[
1
:]
args
=
args
[
1
:]
...
@@ -108,12 +118,16 @@ def get_subcommand(p_args):
...
@@ -108,12 +118,16 @@ def get_subcommand(p_args):
pass
pass
else
:
else
:
p_command
=
config
().
default_command
()
p_command
=
config
().
default_command
()
if
p_command
in
_SUBCOMMAND_MAP
:
if
p_command
in
alias_map
:
result
,
args
=
resolve_alias
(
p_command
,
args
)
elif
p_command
in
_SUBCOMMAND_MAP
:
result
=
import_subcommand
(
p_command
)
result
=
import_subcommand
(
p_command
)
# leave args unchanged
# leave args unchanged
except
IndexError
:
except
IndexError
:
p_command
=
config
().
default_command
()
p_command
=
config
().
default_command
()
if
p_command
in
_SUBCOMMAND_MAP
:
if
p_command
in
alias_map
:
result
,
args
=
resolve_alias
(
p_command
,
args
)
elif
p_command
in
_SUBCOMMAND_MAP
:
result
=
import_subcommand
(
p_command
)
result
=
import_subcommand
(
p_command
)
return
(
result
,
args
)
return
(
result
,
args
)
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