Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sjrpc
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Mirror
sjrpc
Commits
01c4b4d8
Commit
01c4b4d8
authored
14 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
Alias now use OptionCOmmand
parent
2672fc83
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
cccli/command/alias.py
+41
-23
41 additions, 23 deletions
cccli/command/alias.py
with
41 additions
and
23 deletions
cccli/command/alias.py
+
41
−
23
View file @
01c4b4d8
...
...
@@ -6,39 +6,57 @@ CloudControl alias related command
'''
from
cccli.exception
import
*
from
cccli.command.command
import
Command
from
cccli.command.command
import
OptionCommand
import
re
class
Command_alias
(
Command
):
class
Command_alias
(
Option
Command
):
'''
Show or create alias
'''
def
__init__
(
self
,
cli
,
argv0
):
OptionCommand
.
__init__
(
self
,
cli
,
argv0
)
self
.
set_usage
(
"
%prog [options] [name] [value]
"
)
def
__call__
(
self
,
argv
):
if
len
(
argv
)
==
1
:
for
n
,
v
in
self
.
cli
.
alias
.
items
():
self
.
printer
.
out
(
"
%s=%s
"
%
(
n
,
v
))
el
if
len
(
arg
v
)
==
2
:
if
argv
[
1
]
not
in
self
.
cli
.
alias
:
raise
cmdBadArgument
(
argv
[
1
])
self
.
printer
.
out
(
"
%s=%s
"
%
(
argv
[
1
],
self
.
cli
.
alias
[
argv
[
1
]]))
elif
len
(
arg
v
)
==
3
:
self
.
cli
.
alias
[
argv
[
1
]]
=
argv
[
2
]
self
.
cli
.
alias
.
save
(
self
.
cli
.
settings
.
get
(
"
alias
"
,
""
))
# args parse
self
.
parse_args
(
argv
)
_value
=
None
if
len
(
self
.
arg
s
)
==
0
:
_alias
=
self
.
cli
.
alias
.
keys
()
elif
len
(
self
.
args
)
==
1
:
_alias
=
self
.
args
[
0
]
elif
len
(
self
.
arg
s
)
==
2
:
_alias
=
self
.
args
[
0
]
_value
=
self
.
args
[
1
]
else
:
raise
cmdBadArgument
()
def
usage
(
self
):
return
"
Usage: alias [name] [value]
"
# printing
if
_value
is
None
:
for
a
in
_alias
:
if
a
in
self
.
cli
.
alias
:
self
.
printer
.
out
(
"
%s
\"
%s
\"
"
%
(
a
,
re
.
sub
(
"
\"
"
,
"
\\\"
"
,
self
.
cli
.
alias
[
a
])))
else
:
self
.
printer
.
warn
(
"
No alias %s
"
%
a
)
# editing
else
:
self
.
cli
.
alias
[
_alias
]
=
_value
self
.
cli
.
alias
.
save
(
self
.
cli
.
settings
.
get
(
"
alias
"
,
""
))
class
Command_unalias
(
Command
):
class
Command_unalias
(
Option
Command
):
'''
Remove an alias
'''
def
__init__
(
self
,
cli
,
argv0
):
OptionCommand
.
__init__
(
self
,
cli
,
argv0
)
self
.
set_usage
(
"
%prog [options] [name]
"
)
def
__call__
(
self
,
argv
):
if
len
(
argv
)
!=
2
:
# parse args
self
.
parse_args
(
argv
)
if
len
(
self
.
args
)
!=
1
:
raise
cmdBadArgument
()
if
argv
[
1
]
not
in
self
.
cli
.
alias
:
raise
cmdBadArgument
(
"
%s: No such alias
"
%
argv
[
1
])
del
self
.
cli
.
alias
[
argv
[
1
]]
# check alias existance
if
self
.
args
[
0
]
not
in
self
.
cli
.
alias
:
raise
cmdBadArgument
(
"
%s: No such alias
"
%
self
.
args
[
0
])
# deleting aliases
del
self
.
cli
.
alias
[
self
.
args
[
0
]]
self
.
cli
.
alias
.
save
(
self
.
cli
.
settings
.
get
(
"
alias
"
,
""
))
def
usage
(
self
):
return
"
Usage: unalias [name]
"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment