mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
list: add name-only and path-only options
`repo list -n` prints only the name of the projects. `repo list -p` prints only the path of the projects. Change-Id: If7d78eb2651f0b1b2fe555dc286bd2bdcad0d56d Signed-off-by: Chirayu Desai <cdesai@cyanogenmod.org>
This commit is contained in:
parent
0a1c6a1c16
commit
04d84a23fd
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import re
|
import re
|
||||||
|
import sys
|
||||||
|
|
||||||
from command import Command, MirrorSafeCommand
|
from command import Command, MirrorSafeCommand
|
||||||
|
|
||||||
@ -38,6 +39,12 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
|
|||||||
p.add_option('-f', '--fullpath',
|
p.add_option('-f', '--fullpath',
|
||||||
dest='fullpath', action='store_true',
|
dest='fullpath', action='store_true',
|
||||||
help="Display the full work tree path instead of the relative path")
|
help="Display the full work tree path instead of the relative path")
|
||||||
|
p.add_option('-n', '--name-only',
|
||||||
|
dest='name_only', action='store_true',
|
||||||
|
help="Display only the name of the repository")
|
||||||
|
p.add_option('-p', '--path-only',
|
||||||
|
dest='path_only', action='store_true',
|
||||||
|
help="Display only the path of the repository")
|
||||||
|
|
||||||
def Execute(self, opt, args):
|
def Execute(self, opt, args):
|
||||||
"""List all projects and the associated directories.
|
"""List all projects and the associated directories.
|
||||||
@ -50,6 +57,11 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
|
|||||||
opt: The options.
|
opt: The options.
|
||||||
args: Positional args. Can be a list of projects to list, or empty.
|
args: Positional args. Can be a list of projects to list, or empty.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
if opt.fullpath and opt.name_only:
|
||||||
|
print('error: cannot combine -f and -n', file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if not opt.regex:
|
if not opt.regex:
|
||||||
projects = self.GetProjects(args)
|
projects = self.GetProjects(args)
|
||||||
else:
|
else:
|
||||||
@ -62,7 +74,12 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
|
|||||||
|
|
||||||
lines = []
|
lines = []
|
||||||
for project in projects:
|
for project in projects:
|
||||||
lines.append("%s : %s" % (_getpath(project), project.name))
|
if opt.name_only and not opt.path_only:
|
||||||
|
lines.append("%s" % ( project.name))
|
||||||
|
elif opt.path_only and not opt.name_only:
|
||||||
|
lines.append("%s" % (_getpath(project)))
|
||||||
|
else:
|
||||||
|
lines.append("%s : %s" % (_getpath(project), project.name))
|
||||||
|
|
||||||
lines.sort()
|
lines.sort()
|
||||||
print('\n'.join(lines))
|
print('\n'.join(lines))
|
||||||
|
Loading…
Reference in New Issue
Block a user