Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cc-cli
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
cc-cli
Commits
2c402543
Commit
2c402543
authored
14 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
fix alias subs
fix somes exception issues
parent
3897c003
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cccli/cli.py
+6
-7
6 additions, 7 deletions
cccli/cli.py
cccli/command.py
+14
-16
14 additions, 16 deletions
cccli/command.py
cccli/exception.py
+5
-2
5 additions, 2 deletions
cccli/exception.py
with
25 additions
and
25 deletions
cccli/cli.py
+
6
−
7
View file @
2c402543
...
@@ -104,7 +104,9 @@ class Cli(object):
...
@@ -104,7 +104,9 @@ class Cli(object):
continue
continue
# alias subsitution
# alias subsitution
if
argv
[
0
]
in
self
.
alias
:
if
argv
[
0
]
in
self
.
alias
:
argv
[
0
]
=
self
.
alias
[
argv
[
0
]]
oldargv
=
argv
[
1
:]
argv
=
shlex
.
split
(
self
.
alias
[
argv
[
0
]])
argv
.
extend
(
oldargv
)
self
.
_exec_command
(
argv
)
self
.
_exec_command
(
argv
)
if
self
.
interactive
:
if
self
.
interactive
:
self
.
printer
.
out
(
"
tcho!
"
)
self
.
printer
.
out
(
"
tcho!
"
)
...
@@ -120,7 +122,7 @@ class Cli(object):
...
@@ -120,7 +122,7 @@ class Cli(object):
Command
([
"
help
"
],
self
).
call
()
Command
([
"
help
"
],
self
).
call
()
else
:
else
:
Command
(
argv
,
self
).
call
()
Command
(
argv
,
self
).
call
()
except
BadArgument
as
e
:
except
cmd
BadArgument
as
e
:
if
str
(
e
):
if
str
(
e
):
self
.
printer
.
error
(
"
Bad argument: %s.
"
%
str
(
e
))
self
.
printer
.
error
(
"
Bad argument: %s.
"
%
str
(
e
))
else
:
else
:
...
@@ -128,11 +130,8 @@ class Cli(object):
...
@@ -128,11 +130,8 @@ class Cli(object):
usage
=
Command
.
usage
(
argv
[
0
])
usage
=
Command
.
usage
(
argv
[
0
])
if
usage
!=
""
:
if
usage
!=
""
:
self
.
printer
.
out
(
"
usage: %s.
"
%
usage
)
self
.
printer
.
out
(
"
usage: %s.
"
%
usage
)
except
BadCommand
as
e
:
except
cmdBadName
:
if
str
(
e
):
self
.
printer
.
error
(
"
No command: %s.
"
%
argv
[
0
])
self
.
printer
.
error
(
"
command: %s.
"
%
str
(
e
))
else
:
self
.
printer
.
error
(
"
No command: %s.
"
%
argv
[
0
])
except
cmdWarning
as
e
:
except
cmdWarning
as
e
:
self
.
printer
.
warn
(
"
%s: %s
"
%
(
argv
[
0
],
str
(
e
)))
self
.
printer
.
warn
(
"
%s: %s
"
%
(
argv
[
0
],
str
(
e
)))
except
cmdError
as
e
:
except
cmdError
as
e
:
...
...
This diff is collapsed.
Click to expand it.
cccli/command.py
+
14
−
16
View file @
2c402543
...
@@ -21,21 +21,19 @@ class Command(object):
...
@@ -21,21 +21,19 @@ class Command(object):
def
__init__
(
self
,
argv
,
cli
):
def
__init__
(
self
,
argv
,
cli
):
# check argv
# check argv
if
len
(
argv
)
<
1
:
if
len
(
argv
)
==
0
:
raise
BadCommand
()
raise
cmdBadName
()
# check valid command chars
# check valid command chars
if
not
re
.
match
(
"
^[a-zA-Z0-9]+
"
,
argv
[
0
]):
if
not
re
.
match
(
"
^[a-zA-Z0-9]+
"
,
argv
[
0
]):
raise
BadCommand
(
"
Invalid command n
ame
"
)
raise
cmdBadN
ame
(
)
cmdlist
=
[
x
[
4
:]
for
x
in
dir
(
self
)
if
x
.
startswith
(
"
cmd_
"
)
]
cmdlist
=
[
x
[
4
:]
for
x
in
dir
(
self
)
if
x
.
startswith
(
"
cmd_
"
)
]
matchlist
=
[
x
for
x
in
cmdlist
if
re
.
match
(
"
%s.+
"
%
argv
[
0
],
x
)
]
matchlist
=
[
x
for
x
in
cmdlist
if
re
.
match
(
"
%s.+
"
%
argv
[
0
],
x
)
]
if
argv
[
0
]
in
cmdlist
:
if
argv
[
0
]
in
cmdlist
:
pass
pass
elif
len
(
matchlist
)
==
1
:
elif
len
(
matchlist
)
==
1
:
argv
[
0
]
=
matchlist
[
0
]
argv
[
0
]
=
matchlist
[
0
]
elif
len
(
matchlist
)
>
1
:
raise
BadCommand
(
"
Too many command: %s
"
%
"
,
"
.
join
(
matchlist
))
else
:
else
:
raise
BadCommand
()
raise
cmdBadName
()
self
.
_cmd
=
getattr
(
self
,
"
cmd_%s
"
%
argv
[
0
])
self
.
_cmd
=
getattr
(
self
,
"
cmd_%s
"
%
argv
[
0
])
self
.
_argv
=
argv
self
.
_argv
=
argv
self
.
cli
=
cli
self
.
cli
=
cli
...
@@ -46,7 +44,7 @@ class Command(object):
...
@@ -46,7 +44,7 @@ class Command(object):
'''
Return usage of a command
'''
'''
Return usage of a command
'''
fname
=
"
cmd_%s
"
%
cmdname
fname
=
"
cmd_%s
"
%
cmdname
if
not
hasattr
(
cls
,
fname
):
if
not
hasattr
(
cls
,
fname
):
raise
BadArgument
(
cmdname
)
raise
cmdBadName
(
cmdname
)
if
hasattr
(
getattr
(
cls
,
fname
),
"
usage
"
):
if
hasattr
(
getattr
(
cls
,
fname
),
"
usage
"
):
return
getattr
(
getattr
(
cls
,
fname
),
"
usage
"
)
return
getattr
(
getattr
(
cls
,
fname
),
"
usage
"
)
return
""
return
""
...
@@ -58,7 +56,7 @@ class Command(object):
...
@@ -58,7 +56,7 @@ class Command(object):
if
hasattr
(
self
,
name
):
if
hasattr
(
self
,
name
):
cmd
=
getattr
(
self
,
name
)
cmd
=
getattr
(
self
,
name
)
return
cmd
(
self
.
_argv
)
return
cmd
(
self
.
_argv
)
raise
BadCommand
(
self
.
_argv
[
0
])
raise
cmdBadName
(
self
.
_argv
[
0
])
def
cmd_exit
(
self
,
argv
):
def
cmd_exit
(
self
,
argv
):
'''
Quit application with respect
'''
'''
Quit application with respect
'''
...
@@ -81,7 +79,7 @@ class Command(object):
...
@@ -81,7 +79,7 @@ class Command(object):
def
cmd_usage
(
self
,
argv
):
def
cmd_usage
(
self
,
argv
):
'''
Print usage of a command
'''
'''
Print usage of a command
'''
if
len
(
argv
)
!=
2
:
if
len
(
argv
)
!=
2
:
raise
BadArgument
()
raise
cmd
BadArgument
()
usage
=
Command
.
usage
(
argv
[
1
])
usage
=
Command
.
usage
(
argv
[
1
])
if
usage
!=
""
:
if
usage
!=
""
:
self
.
printer
.
out
(
"
usage: %s
"
%
usage
)
self
.
printer
.
out
(
"
usage: %s
"
%
usage
)
...
@@ -120,9 +118,9 @@ class Command(object):
...
@@ -120,9 +118,9 @@ class Command(object):
if
hasattr
(
getattr
(
self
,
fname
),
"
details
"
):
if
hasattr
(
getattr
(
self
,
fname
),
"
details
"
):
Self
.
Printer
.
out
(
"
Details: %s
"
%
getattr
(
getattr
(
self
,
fname
),
"
details
"
))
Self
.
Printer
.
out
(
"
Details: %s
"
%
getattr
(
getattr
(
self
,
fname
),
"
details
"
))
else
:
else
:
raise
BadArgument
(
argv
[
1
])
raise
cmd
BadArgument
(
argv
[
1
])
else
:
else
:
raise
BadArgument
()
raise
cmd
BadArgument
()
cmd_help
.
usage
=
"
help [command]
"
cmd_help
.
usage
=
"
help [command]
"
cmd_help
.
desc
=
"
Print help about a command
"
cmd_help
.
desc
=
"
Print help about a command
"
...
@@ -133,22 +131,22 @@ class Command(object):
...
@@ -133,22 +131,22 @@ class Command(object):
self
.
printer
.
out
(
"
%s=%s
"
%
(
n
,
v
))
self
.
printer
.
out
(
"
%s=%s
"
%
(
n
,
v
))
elif
len
(
argv
)
==
2
:
elif
len
(
argv
)
==
2
:
if
argv
[
1
]
not
in
self
.
cli
.
alias
:
if
argv
[
1
]
not
in
self
.
cli
.
alias
:
raise
BadArgument
(
argv
[
1
])
raise
cmd
BadArgument
(
argv
[
1
])
self
.
printer
.
out
(
"
%s=%s
"
%
(
argv
[
1
],
self
.
cli
.
alias
[
argv
[
1
]]))
self
.
printer
.
out
(
"
%s=%s
"
%
(
argv
[
1
],
self
.
cli
.
alias
[
argv
[
1
]]))
elif
len
(
argv
)
==
3
:
elif
len
(
argv
)
==
3
:
self
.
cli
.
alias
[
argv
[
1
]]
=
argv
[
2
]
self
.
cli
.
alias
[
argv
[
1
]]
=
argv
[
2
]
self
.
cli
.
alias
.
save
(
self
.
cli
.
settings
.
get
(
"
alias
"
,
""
))
self
.
cli
.
alias
.
save
(
self
.
cli
.
settings
.
get
(
"
alias
"
,
""
))
else
:
else
:
raise
BadArgument
()
raise
cmd
BadArgument
()
cmd_alias
.
usage
=
"
alias [name] [value]
"
cmd_alias
.
usage
=
"
alias [name] [value]
"
cmd_alias
.
desc
=
"
Show or create aliases
"
cmd_alias
.
desc
=
"
Show or create aliases
"
def
cmd_unalias
(
self
,
argv
):
def
cmd_unalias
(
self
,
argv
):
'''
Remove an alias
'''
'''
Remove an alias
'''
if
len
(
argv
)
!=
2
:
if
len
(
argv
)
!=
2
:
raise
BadArgument
()
raise
cmd
BadArgument
()
if
argv
[
1
]
not
in
self
.
cli
.
alias
:
if
argv
[
1
]
not
in
self
.
cli
.
alias
:
raise
BadArgument
(
"
%s: No such alias
"
%
argv
[
1
])
raise
cmd
BadArgument
(
"
%s: No such alias
"
%
argv
[
1
])
del
self
.
cli
.
alias
[
argv
[
1
]]
del
self
.
cli
.
alias
[
argv
[
1
]]
self
.
cli
.
alias
.
save
(
self
.
cli
.
settings
.
get
(
"
alias
"
,
""
))
self
.
cli
.
alias
.
save
(
self
.
cli
.
settings
.
get
(
"
alias
"
,
""
))
cmd_unalias
.
usage
=
"
unalias [name]
"
cmd_unalias
.
usage
=
"
unalias [name]
"
...
@@ -184,7 +182,7 @@ class Command(object):
...
@@ -184,7 +182,7 @@ class Command(object):
def
_startstopsdestroypauseresume
(
self
,
argv
):
def
_startstopsdestroypauseresume
(
self
,
argv
):
# arg stuff
# arg stuff
if
len
(
argv
)
==
1
:
if
len
(
argv
)
==
1
:
raise
BadArgument
()
raise
cmd
BadArgument
()
tql
=
str
.
join
(
"
"
,
argv
[
1
:])
tql
=
str
.
join
(
"
"
,
argv
[
1
:])
# print tql list result
# print tql list result
items
=
self
.
cli
.
rpc
.
list
(
tql
)
items
=
self
.
cli
.
rpc
.
list
(
tql
)
...
...
This diff is collapsed.
Click to expand it.
cccli/exception.py
+
5
−
2
View file @
2c402543
...
@@ -12,14 +12,17 @@ class cliException(Exception):
...
@@ -12,14 +12,17 @@ class cliException(Exception):
class
cliError
(
cliException
):
class
cliError
(
cliException
):
pass
pass
class
Bad
Command
(
cliError
):
class
Bad
Argument
(
cliError
):
pass
pass
################################################################################
################################################################################
class
cmdException
(
cliException
):
class
cmdException
(
cliException
):
pass
pass
class
BadArgument
(
cmdException
):
class
cmdBadName
(
cmdException
):
pass
class
cmdBadArgument
(
cmdException
):
pass
pass
class
cmdWarning
(
cmdException
):
class
cmdWarning
(
cmdException
):
...
...
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