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
f2387fc0
Commit
f2387fc0
authored
14 years ago
by
Seblu
Browse files
Options
Downloads
Patches
Plain Diff
command auto expansion
Command are now callable with a part of it. e.g. a, al, ali,alia, call alias
parent
2d908e50
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
cccli/cli.py
+6
-3
6 additions, 3 deletions
cccli/cli.py
cccli/command.py
+15
-0
15 additions, 0 deletions
cccli/command.py
with
21 additions
and
3 deletions
cccli/cli.py
+
6
−
3
View file @
f2387fc0
...
@@ -122,15 +122,18 @@ class Cli(object):
...
@@ -122,15 +122,18 @@ class Cli(object):
# execute command
# execute command
Command
(
argv
,
self
).
call
()
Command
(
argv
,
self
).
call
()
except
BadArgument
,
e
:
except
BadArgument
,
e
:
if
str
(
e
)
!=
""
:
if
str
(
e
):
printer
.
error
(
"
Bad argument: %s.
"
%
str
(
e
))
printer
.
error
(
"
Bad argument: %s.
"
%
str
(
e
))
else
:
else
:
printer
.
error
(
"
Bad argument.
"
)
printer
.
error
(
"
Bad argument.
"
)
usage
=
Command
.
usage
(
argv
[
0
])
usage
=
Command
.
usage
(
argv
[
0
])
if
usage
!=
""
:
if
usage
!=
""
:
printer
.
out
(
"
usage: %s.
"
%
usage
)
printer
.
out
(
"
usage: %s.
"
%
usage
)
except
BadCommand
:
except
BadCommand
,
e
:
printer
.
error
(
"
No command: %s.
"
%
argv
[
0
])
if
str
(
e
):
printer
.
error
(
"
command: %s.
"
%
str
(
e
))
else
:
printer
.
error
(
"
No command: %s.
"
%
argv
[
0
])
except
sjrpc
.
core
.
exceptions
.
RpcError
,
e
:
except
sjrpc
.
core
.
exceptions
.
RpcError
,
e
:
if
cccli
.
debug
:
raise
if
cccli
.
debug
:
raise
printer
.
error
(
"
sjRPC: %s
"
%
str
(
e
))
printer
.
error
(
"
sjRPC: %s
"
%
str
(
e
))
...
...
This diff is collapsed.
Click to expand it.
cccli/command.py
+
15
−
0
View file @
f2387fc0
...
@@ -10,8 +10,23 @@ from cccli.clierror import *
...
@@ -10,8 +10,23 @@ from cccli.clierror import *
class
Command
(
object
):
class
Command
(
object
):
def
__init__
(
self
,
argv
,
cli
):
def
__init__
(
self
,
argv
,
cli
):
# check argv
if
len
(
argv
)
<
1
:
if
len
(
argv
)
<
1
:
raise
BadCommand
()
raise
BadCommand
()
# check valid command chars
if
not
re
.
match
(
"
^[a-zA-Z0-9]+
"
,
argv
[
0
]):
raise
BadCommmand
(
"
Invalid command name
"
)
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
)
]
if
argv
[
0
]
in
cmdlist
:
pass
elif
len
(
matchlist
)
==
1
:
argv
[
0
]
=
matchlist
[
0
]
elif
len
(
matchlist
)
>
1
:
raise
BadCommand
(
"
Too many command: %s
"
%
"
,
"
.
join
(
matchlist
))
else
:
raise
BadCommand
()
self
.
_cmd
=
getattr
(
self
,
"
cmd_%s
"
%
argv
[
0
])
self
.
_argv
=
argv
self
.
_argv
=
argv
self
.
cli
=
cli
self
.
cli
=
cli
...
...
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