summaryrefslogtreecommitdiffstats
path: root/repo
diff options
context:
space:
mode:
Diffstat (limited to 'repo')
-rwxr-xr-xrepo61
1 files changed, 33 insertions, 28 deletions
diff --git a/repo b/repo
index f7e7581a..5674be84 100755
--- a/repo
+++ b/repo
@@ -253,26 +253,37 @@ home_dot_repo = os.path.expanduser('~/.repoconfig')
253gpg_dir = os.path.join(home_dot_repo, 'gnupg') 253gpg_dir = os.path.join(home_dot_repo, 'gnupg')
254 254
255extra_args = [] 255extra_args = []
256init_optparse = optparse.OptionParser(usage="repo init -u url [options]")
257 256
258 257
259def _InitParser(): 258def GetParser(gitc_init=False):
260 """Setup the init subcommand parser.""" 259 """Setup the CLI parser."""
260 if gitc_init:
261 usage = 'repo gitc-init -u url -c client [options]'
262 else:
263 usage = 'repo init -u url [options]'
264
265 parser = optparse.OptionParser(usage=usage)
266
261 # Logging. 267 # Logging.
262 group = init_optparse.add_option_group('Logging options') 268 group = parser.add_option_group('Logging options')
263 group.add_option('-q', '--quiet', 269 group.add_option('-q', '--quiet',
264 action='store_true', default=False, 270 action='store_true', default=False,
265 help='be quiet') 271 help='be quiet')
266 272
267 # Manifest. 273 # Manifest.
268 group = init_optparse.add_option_group('Manifest options') 274 group = parser.add_option_group('Manifest options')
269 group.add_option('-u', '--manifest-url', 275 group.add_option('-u', '--manifest-url',
270 help='manifest repository location', metavar='URL') 276 help='manifest repository location', metavar='URL')
271 group.add_option('-b', '--manifest-branch', 277 group.add_option('-b', '--manifest-branch',
272 help='manifest branch or revision', metavar='REVISION') 278 help='manifest branch or revision', metavar='REVISION')
273 group.add_option('-m', '--manifest-name', 279 group.add_option('-m', '--manifest-name',
274 help='initial manifest file', metavar='NAME.xml') 280 help='initial manifest file', metavar='NAME.xml')
275 group.add_option('--current-branch', 281 cbr_opts = ['--current-branch']
282 # The gitc-init subcommand allocates -c itself, but a lot of init users
283 # want -c, so try to satisfy both as best we can.
284 if not gitc_init:
285 cbr_opts += ['-c']
286 group.add_option(*cbr_opts,
276 dest='current_branch_only', action='store_true', 287 dest='current_branch_only', action='store_true',
277 help='fetch only current manifest branch from server') 288 help='fetch only current manifest branch from server')
278 group.add_option('--mirror', action='store_true', 289 group.add_option('--mirror', action='store_true',
@@ -310,7 +321,7 @@ def _InitParser():
310 help="don't fetch tags in the manifest") 321 help="don't fetch tags in the manifest")
311 322
312 # Tool. 323 # Tool.
313 group = init_optparse.add_option_group('repo Version options') 324 group = parser.add_option_group('repo Version options')
314 group.add_option('--repo-url', metavar='URL', 325 group.add_option('--repo-url', metavar='URL',
315 help='repo repository location ($REPO_URL)') 326 help='repo repository location ($REPO_URL)')
316 group.add_option('--repo-branch', metavar='REVISION', 327 group.add_option('--repo-branch', metavar='REVISION',
@@ -319,21 +330,20 @@ def _InitParser():
319 help='do not verify repo source code') 330 help='do not verify repo source code')
320 331
321 # Other. 332 # Other.
322 group = init_optparse.add_option_group('Other options') 333 group = parser.add_option_group('Other options')
323 group.add_option('--config-name', 334 group.add_option('--config-name',
324 action='store_true', default=False, 335 action='store_true', default=False,
325 help='Always prompt for name/e-mail') 336 help='Always prompt for name/e-mail')
326 337
338 # gitc-init specific settings.
339 if gitc_init:
340 group = parser.add_option_group('GITC options')
341 group.add_option('-f', '--manifest-file',
342 help='Optional manifest file to use for this GITC client.')
343 group.add_option('-c', '--gitc-client',
344 help='Name of the gitc_client instance to create or modify.')
327 345
328def _GitcInitOptions(init_optparse_arg): 346 return parser
329 init_optparse_arg.set_usage("repo gitc-init -u url -c client [options]")
330 g = init_optparse_arg.add_option_group('GITC options')
331 g.add_option('-f', '--manifest-file',
332 dest='manifest_file',
333 help='Optional manifest file to use for this GITC client.')
334 g.add_option('-c', '--gitc-client',
335 dest='gitc_client',
336 help='The name of the gitc_client instance to create or modify.')
337 347
338 348
339# This is a poor replacement for subprocess.run until we require Python 3.6+. 349# This is a poor replacement for subprocess.run until we require Python 3.6+.
@@ -432,11 +442,10 @@ class CloneFailure(Exception):
432def _Init(args, gitc_init=False): 442def _Init(args, gitc_init=False):
433 """Installs repo by cloning it over the network. 443 """Installs repo by cloning it over the network.
434 """ 444 """
435 if gitc_init: 445 parser = GetParser(gitc_init=gitc_init)
436 _GitcInitOptions(init_optparse) 446 opt, args = parser.parse_args(args)
437 opt, args = init_optparse.parse_args(args)
438 if args: 447 if args:
439 init_optparse.print_usage() 448 parser.print_usage()
440 sys.exit(1) 449 sys.exit(1)
441 450
442 url = opt.repo_url 451 url = opt.repo_url
@@ -896,12 +905,9 @@ For access to the full online help, install repo ("repo init").
896 905
897def _Help(args): 906def _Help(args):
898 if args: 907 if args:
899 if args[0] == 'init': 908 if args[0] in {'init', 'gitc-init'}:
900 init_optparse.print_help() 909 parser = GetParser(gitc_init=args[0] == 'gitc-init')
901 sys.exit(0) 910 parser.print_help()
902 elif args[0] == 'gitc-init':
903 _GitcInitOptions(init_optparse)
904 init_optparse.print_help()
905 sys.exit(0) 911 sys.exit(0)
906 else: 912 else:
907 print("error: '%s' is not a bootstrap command.\n" 913 print("error: '%s' is not a bootstrap command.\n"
@@ -983,7 +989,6 @@ def main(orig_args):
983 'command from the corresponding client under /gitc/', 989 'command from the corresponding client under /gitc/',
984 file=sys.stderr) 990 file=sys.stderr)
985 sys.exit(1) 991 sys.exit(1)
986 _InitParser()
987 if not repo_main: 992 if not repo_main:
988 if opt.help: 993 if opt.help:
989 _Usage() 994 _Usage()