summaryrefslogtreecommitdiffstats
path: root/subcmds/list.py
diff options
context:
space:
mode:
Diffstat (limited to 'subcmds/list.py')
-rw-r--r--subcmds/list.py28
1 files changed, 19 insertions, 9 deletions
diff --git a/subcmds/list.py b/subcmds/list.py
index 5cbc0c22..6adf85b7 100644
--- a/subcmds/list.py
+++ b/subcmds/list.py
@@ -12,11 +12,13 @@
12# See the License for the specific language governing permissions and 12# See the License for the specific language governing permissions and
13# limitations under the License. 13# limitations under the License.
14 14
15import os
16
15from command import Command, MirrorSafeCommand 17from command import Command, MirrorSafeCommand
16 18
17 19
18class List(Command, MirrorSafeCommand): 20class List(Command, MirrorSafeCommand):
19 common = True 21 COMMON = True
20 helpSummary = "List projects and their associated directories" 22 helpSummary = "List projects and their associated directories"
21 helpUsage = """ 23 helpUsage = """
22%prog [-f] [<project>...] 24%prog [-f] [<project>...]
@@ -36,27 +38,33 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
36 def _Options(self, p): 38 def _Options(self, p):
37 p.add_option('-r', '--regex', 39 p.add_option('-r', '--regex',
38 dest='regex', action='store_true', 40 dest='regex', action='store_true',
39 help="Filter the project list based on regex or wildcard matching of strings") 41 help='filter the project list based on regex or wildcard matching of strings')
40 p.add_option('-g', '--groups', 42 p.add_option('-g', '--groups',
41 dest='groups', 43 dest='groups',
42 help="Filter the project list based on the groups the project is in") 44 help='filter the project list based on the groups the project is in')
43 p.add_option('-a', '--all', 45 p.add_option('-a', '--all',
44 action='store_true', 46 action='store_true',
45 help='Show projects regardless of checkout state') 47 help='show projects regardless of checkout state')
46 p.add_option('-f', '--fullpath',
47 dest='fullpath', action='store_true',
48 help="Display the full work tree path instead of the relative path")
49 p.add_option('-n', '--name-only', 48 p.add_option('-n', '--name-only',
50 dest='name_only', action='store_true', 49 dest='name_only', action='store_true',
51 help="Display only the name of the repository") 50 help='display only the name of the repository')
52 p.add_option('-p', '--path-only', 51 p.add_option('-p', '--path-only',
53 dest='path_only', action='store_true', 52 dest='path_only', action='store_true',
54 help="Display only the path of the repository") 53 help='display only the path of the repository')
54 p.add_option('-f', '--fullpath',
55 dest='fullpath', action='store_true',
56 help='display the full work tree path instead of the relative path')
57 p.add_option('--relative-to', metavar='PATH',
58 help='display paths relative to this one (default: top of repo client checkout)')
55 59
56 def ValidateOptions(self, opt, args): 60 def ValidateOptions(self, opt, args):
57 if opt.fullpath and opt.name_only: 61 if opt.fullpath and opt.name_only:
58 self.OptionParser.error('cannot combine -f and -n') 62 self.OptionParser.error('cannot combine -f and -n')
59 63
64 # Resolve any symlinks so the output is stable.
65 if opt.relative_to:
66 opt.relative_to = os.path.realpath(opt.relative_to)
67
60 def Execute(self, opt, args): 68 def Execute(self, opt, args):
61 """List all projects and the associated directories. 69 """List all projects and the associated directories.
62 70
@@ -76,6 +84,8 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
76 def _getpath(x): 84 def _getpath(x):
77 if opt.fullpath: 85 if opt.fullpath:
78 return x.worktree 86 return x.worktree
87 if opt.relative_to:
88 return os.path.relpath(x.worktree, opt.relative_to)
79 return x.relpath 89 return x.relpath
80 90
81 lines = [] 91 lines = []