diff --git a/command.py b/command.py index 78dab96d..997acec0 100644 --- a/command.py +++ b/command.py @@ -230,3 +230,8 @@ class MirrorSafeCommand(object): """Command permits itself to run within a mirror, and does not require a working directory. """ + +class RequiresGitcCommand(object): + """Command that requires GITC to be available, but does + not require the local client to be a GITC client. + """ diff --git a/main.py b/main.py index adfaffb0..a5979a87 100755 --- a/main.py +++ b/main.py @@ -42,6 +42,7 @@ from git_command import git, GitCommand from git_config import init_ssh, close_ssh from command import InteractiveCommand from command import MirrorSafeCommand +from command import RequiresGitcCommand from subcmds.version import Version from editor import Editor from error import DownloadError @@ -143,6 +144,11 @@ class _Repo(object): file=sys.stderr) return 1 + if isinstance(cmd, RequiresGitcCommand) and not gitc_utils.get_gitc_manifest_dir(): + print("fatal: '%s' requires GITC to be available" % name, + file=sys.stderr) + return 1 + try: copts, cargs = cmd.OptionParser.parse_args(argv) copts = cmd.ReadEnvironmentOptions(copts) diff --git a/repo b/repo index 01c1cb0e..b7d8024f 100755 --- a/repo +++ b/repo @@ -214,6 +214,7 @@ group.add_option('--config-name', help='Always prompt for name/e-mail') def _GitcInitOptions(init_optparse): + init_optparse.set_usage("repo gitc-init -u url -c client [options]") g = init_optparse.add_option_group('GITC options') g.add_option('-f', '--manifest-file', dest='manifest_file', @@ -272,9 +273,12 @@ def _Init(args, gitc_init=False): if gitc_init: gitc_manifest_dir = get_gitc_manifest_dir() if not gitc_manifest_dir: - _print('error: GITC filesystem is not running. Exiting...', + _print('fatal: GITC filesystem is not available. Exiting...', file=sys.stderr) sys.exit(1) + if not opt.gitc_client: + _print('fatal: GITC client (-c) is required.', file=sys.stderr) + sys.exit(1) client_dir = os.path.join(gitc_manifest_dir, opt.gitc_client) if not os.path.exists(client_dir): os.makedirs(client_dir) @@ -681,6 +685,10 @@ def _ParseArguments(args): def _Usage(): + gitc_usage = "" + if get_gitc_manifest_dir(): + gitc_usage = " gitc-init Initialize a GITC Client.\n" + _print( """usage: repo COMMAND [ARGS] @@ -689,7 +697,8 @@ repo is not yet installed. Use "repo init" to install it here. The most commonly used repo commands are: init Install repo in the current working directory - help Display detailed help on a command +""" + gitc_usage + +""" help Display detailed help on a command For access to the full online help, install repo ("repo init"). """, file=sys.stderr) @@ -701,6 +710,10 @@ def _Help(args): if args[0] == 'init': init_optparse.print_help() sys.exit(0) + elif args[0] == 'gitc-init': + _GitcInitOptions(init_optparse) + init_optparse.print_help() + sys.exit(0) else: _print("error: '%s' is not a bootstrap command.\n" ' For access to online help, install repo ("repo init").' diff --git a/subcmds/gitc_init.py b/subcmds/gitc_init.py index c0568caa..e99affa5 100644 --- a/subcmds/gitc_init.py +++ b/subcmds/gitc_init.py @@ -18,10 +18,11 @@ import os import sys import gitc_utils +from command import RequiresGitcCommand from subcmds import init -class GitcInit(init.Init): +class GitcInit(init.Init, RequiresGitcCommand): common = True helpSummary = "Initialize a GITC Client." helpUsage = """ diff --git a/subcmds/help.py b/subcmds/help.py index 4aa3f863..ae5b8f08 100644 --- a/subcmds/help.py +++ b/subcmds/help.py @@ -19,7 +19,8 @@ import sys from formatter import AbstractFormatter, DumbWriter from color import Coloring -from command import PagedCommand, MirrorSafeCommand +from command import PagedCommand, MirrorSafeCommand, RequiresGitcCommand +import gitc_utils class Help(PagedCommand, MirrorSafeCommand): common = False @@ -54,9 +55,17 @@ Displays detailed usage information about a command. def _PrintCommonCommands(self): print('usage: repo COMMAND [ARGS]') print('The most commonly used repo commands are:') + + def gitc_supported(cmd): + if not isinstance(cmd, RequiresGitcCommand): + return True + if gitc_utils.get_gitc_manifest_dir(): + return True + return False + commandNames = list(sorted([name for name, command in self.commands.items() - if command.common])) + if command.common and gitc_supported(command)])) maxlen = 0 for name in commandNames: