diff options
Diffstat (limited to 'subcmds')
| -rw-r--r-- | subcmds/list.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/subcmds/list.py b/subcmds/list.py index 0d5c27f7..8eb06cdd 100644 --- a/subcmds/list.py +++ b/subcmds/list.py | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | from __future__ import print_function | 16 | from __future__ import print_function |
| 17 | import re | 17 | import re |
| 18 | import sys | ||
| 18 | 19 | ||
| 19 | from command import Command, MirrorSafeCommand | 20 | from command import Command, MirrorSafeCommand |
| 20 | 21 | ||
| @@ -38,6 +39,12 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | |||
| 38 | p.add_option('-f', '--fullpath', | 39 | p.add_option('-f', '--fullpath', |
| 39 | dest='fullpath', action='store_true', | 40 | dest='fullpath', action='store_true', |
| 40 | help="Display the full work tree path instead of the relative path") | 41 | help="Display the full work tree path instead of the relative path") |
| 42 | p.add_option('-n', '--name-only', | ||
| 43 | dest='name_only', action='store_true', | ||
| 44 | help="Display only the name of the repository") | ||
| 45 | p.add_option('-p', '--path-only', | ||
| 46 | dest='path_only', action='store_true', | ||
| 47 | help="Display only the path of the repository") | ||
| 41 | 48 | ||
| 42 | def Execute(self, opt, args): | 49 | def Execute(self, opt, args): |
| 43 | """List all projects and the associated directories. | 50 | """List all projects and the associated directories. |
| @@ -50,6 +57,11 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | |||
| 50 | opt: The options. | 57 | opt: The options. |
| 51 | args: Positional args. Can be a list of projects to list, or empty. | 58 | args: Positional args. Can be a list of projects to list, or empty. |
| 52 | """ | 59 | """ |
| 60 | |||
| 61 | if opt.fullpath and opt.name_only: | ||
| 62 | print('error: cannot combine -f and -n', file=sys.stderr) | ||
| 63 | sys.exit(1) | ||
| 64 | |||
| 53 | if not opt.regex: | 65 | if not opt.regex: |
| 54 | projects = self.GetProjects(args) | 66 | projects = self.GetProjects(args) |
| 55 | else: | 67 | else: |
| @@ -62,7 +74,12 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | |||
| 62 | 74 | ||
| 63 | lines = [] | 75 | lines = [] |
| 64 | for project in projects: | 76 | for project in projects: |
| 65 | lines.append("%s : %s" % (_getpath(project), project.name)) | 77 | if opt.name_only and not opt.path_only: |
| 78 | lines.append("%s" % ( project.name)) | ||
| 79 | elif opt.path_only and not opt.name_only: | ||
| 80 | lines.append("%s" % (_getpath(project))) | ||
| 81 | else: | ||
| 82 | lines.append("%s : %s" % (_getpath(project), project.name)) | ||
| 66 | 83 | ||
| 67 | lines.sort() | 84 | lines.sort() |
| 68 | print('\n'.join(lines)) | 85 | print('\n'.join(lines)) |
