2008-10-21 14:00:00 +00:00
|
|
|
# Copyright (C) 2008 The Android Open Source Project
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
|
2009-03-04 22:26:50 +00:00
|
|
|
import re
|
2008-10-21 14:00:00 +00:00
|
|
|
import sys
|
2021-04-14 00:22:01 +00:00
|
|
|
import textwrap
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2020-02-25 20:12:37 +00:00
|
|
|
from subcmds import all_commands
|
2008-10-21 14:00:00 +00:00
|
|
|
from color import Coloring
|
2015-08-31 22:45:06 +00:00
|
|
|
from command import PagedCommand, MirrorSafeCommand, GitcAvailableCommand, GitcClientCommand
|
2015-08-31 22:45:06 +00:00
|
|
|
import gitc_utils
|
2021-04-21 03:38:04 +00:00
|
|
|
from wrapper import Wrapper
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2020-02-12 06:20:19 +00:00
|
|
|
|
2009-03-04 01:47:06 +00:00
|
|
|
class Help(PagedCommand, MirrorSafeCommand):
|
2008-10-21 14:00:00 +00:00
|
|
|
common = False
|
|
|
|
helpSummary = "Display detailed help on a command"
|
|
|
|
helpUsage = """
|
|
|
|
%prog [--all|command]
|
|
|
|
"""
|
|
|
|
helpDescription = """
|
|
|
|
Displays detailed usage information about a command.
|
|
|
|
"""
|
|
|
|
|
2019-12-02 21:49:13 +00:00
|
|
|
def _PrintCommands(self, commandNames):
|
|
|
|
"""Helper to display |commandNames| summaries."""
|
2008-10-21 14:00:00 +00:00
|
|
|
maxlen = 0
|
|
|
|
for name in commandNames:
|
|
|
|
maxlen = max(maxlen, len(name))
|
|
|
|
fmt = ' %%-%ds %%s' % maxlen
|
|
|
|
|
|
|
|
for name in commandNames:
|
2020-02-25 20:18:31 +00:00
|
|
|
command = all_commands[name]()
|
2008-10-21 14:00:00 +00:00
|
|
|
try:
|
|
|
|
summary = command.helpSummary.strip()
|
|
|
|
except AttributeError:
|
|
|
|
summary = ''
|
2012-11-02 05:59:27 +00:00
|
|
|
print(fmt % (name, summary))
|
2019-12-02 21:49:13 +00:00
|
|
|
|
|
|
|
def _PrintAllCommands(self):
|
|
|
|
print('usage: repo COMMAND [ARGS]')
|
|
|
|
print('The complete list of recognized repo commands are:')
|
2020-02-25 20:12:37 +00:00
|
|
|
commandNames = list(sorted(all_commands))
|
2019-12-02 21:49:13 +00:00
|
|
|
self._PrintCommands(commandNames)
|
2013-03-05 08:26:46 +00:00
|
|
|
print("See 'repo help <command>' for more information on a "
|
2012-11-02 05:59:27 +00:00
|
|
|
'specific command.')
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
def _PrintCommonCommands(self):
|
2012-11-02 05:59:27 +00:00
|
|
|
print('usage: repo COMMAND [ARGS]')
|
|
|
|
print('The most commonly used repo commands are:')
|
2015-08-31 22:45:06 +00:00
|
|
|
|
|
|
|
def gitc_supported(cmd):
|
2015-08-31 22:45:06 +00:00
|
|
|
if not isinstance(cmd, GitcAvailableCommand) and not isinstance(cmd, GitcClientCommand):
|
2015-08-31 22:45:06 +00:00
|
|
|
return True
|
2020-09-06 18:53:18 +00:00
|
|
|
if self.client.isGitcClient:
|
2015-08-31 22:45:06 +00:00
|
|
|
return True
|
|
|
|
if isinstance(cmd, GitcClientCommand):
|
|
|
|
return False
|
2015-08-31 22:45:06 +00:00
|
|
|
if gitc_utils.get_gitc_manifest_dir():
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2013-03-01 13:44:38 +00:00
|
|
|
commandNames = list(sorted([name
|
2020-02-25 20:12:37 +00:00
|
|
|
for name, command in all_commands.items()
|
2020-02-12 05:58:39 +00:00
|
|
|
if command.common and gitc_supported(command)]))
|
2019-12-02 21:49:13 +00:00
|
|
|
self._PrintCommands(commandNames)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2012-11-02 05:59:27 +00:00
|
|
|
print(
|
2020-02-12 05:58:39 +00:00
|
|
|
"See 'repo help <command>' for more information on a specific command.\n"
|
|
|
|
"See 'repo help --all' for a complete list of recognized commands.")
|
2021-04-21 03:38:04 +00:00
|
|
|
print('Bug reports:', Wrapper().BUG_URL)
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2019-07-31 22:17:44 +00:00
|
|
|
def _PrintCommandHelp(self, cmd, header_prefix=''):
|
2008-10-21 14:00:00 +00:00
|
|
|
class _Out(Coloring):
|
|
|
|
def __init__(self, gc):
|
|
|
|
Coloring.__init__(self, gc, 'help')
|
|
|
|
self.heading = self.printer('heading', attr='bold')
|
2021-04-14 00:22:01 +00:00
|
|
|
self._first = True
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
def _PrintSection(self, heading, bodyAttr):
|
|
|
|
try:
|
|
|
|
body = getattr(cmd, bodyAttr)
|
|
|
|
except AttributeError:
|
|
|
|
return
|
2009-06-04 00:43:16 +00:00
|
|
|
if body == '' or body is None:
|
|
|
|
return
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2021-04-14 00:22:01 +00:00
|
|
|
if not self._first:
|
|
|
|
self.nl()
|
|
|
|
self._first = False
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2019-07-31 22:17:44 +00:00
|
|
|
self.heading('%s%s', header_prefix, heading)
|
2008-10-21 14:00:00 +00:00
|
|
|
self.nl()
|
|
|
|
self.nl()
|
|
|
|
|
|
|
|
me = 'repo %s' % cmd.NAME
|
|
|
|
body = body.strip()
|
|
|
|
body = body.replace('%prog', me)
|
|
|
|
|
2021-04-14 00:22:01 +00:00
|
|
|
# Extract the title, but skip any trailing {#anchors}.
|
|
|
|
asciidoc_hdr = re.compile(r'^\n?#+ ([^{]+)(\{#.+\})?$')
|
2008-10-21 14:00:00 +00:00
|
|
|
for para in body.split("\n\n"):
|
|
|
|
if para.startswith(' '):
|
|
|
|
self.write('%s', para)
|
|
|
|
self.nl()
|
|
|
|
self.nl()
|
2009-03-04 22:26:50 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
m = asciidoc_hdr.match(para)
|
|
|
|
if m:
|
2019-07-31 22:17:44 +00:00
|
|
|
self.heading('%s%s', header_prefix, m.group(1))
|
2009-03-04 22:26:50 +00:00
|
|
|
self.nl()
|
|
|
|
self.nl()
|
|
|
|
continue
|
|
|
|
|
2021-04-14 00:22:01 +00:00
|
|
|
lines = textwrap.wrap(para.replace(' ', ' '), width=80,
|
|
|
|
break_long_words=False, break_on_hyphens=False)
|
|
|
|
for line in lines:
|
|
|
|
self.write('%s', line)
|
|
|
|
self.nl()
|
|
|
|
self.nl()
|
2008-10-21 14:00:00 +00:00
|
|
|
|
2020-09-06 18:53:18 +00:00
|
|
|
out = _Out(self.client.globalConfig)
|
2008-10-21 14:00:00 +00:00
|
|
|
out._PrintSection('Summary', 'helpSummary')
|
2009-04-18 18:44:00 +00:00
|
|
|
cmd.OptionParser.print_help()
|
2008-10-21 14:00:00 +00:00
|
|
|
out._PrintSection('Description', 'helpDescription')
|
|
|
|
|
2019-07-31 22:17:44 +00:00
|
|
|
def _PrintAllCommandHelp(self):
|
2020-02-25 20:12:37 +00:00
|
|
|
for name in sorted(all_commands):
|
2020-02-25 20:18:31 +00:00
|
|
|
cmd = all_commands[name]()
|
2019-07-31 22:17:44 +00:00
|
|
|
cmd.manifest = self.manifest
|
|
|
|
self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,))
|
|
|
|
|
2008-10-21 14:00:00 +00:00
|
|
|
def _Options(self, p):
|
|
|
|
p.add_option('-a', '--all',
|
|
|
|
dest='show_all', action='store_true',
|
|
|
|
help='show the complete list of commands')
|
2019-07-31 22:17:44 +00:00
|
|
|
p.add_option('--help-all',
|
|
|
|
dest='show_all_help', action='store_true',
|
|
|
|
help='show the --help of all commands')
|
2008-10-21 14:00:00 +00:00
|
|
|
|
|
|
|
def Execute(self, opt, args):
|
|
|
|
if len(args) == 0:
|
2019-07-31 22:17:44 +00:00
|
|
|
if opt.show_all_help:
|
|
|
|
self._PrintAllCommandHelp()
|
|
|
|
elif opt.show_all:
|
2008-10-21 14:00:00 +00:00
|
|
|
self._PrintAllCommands()
|
|
|
|
else:
|
|
|
|
self._PrintCommonCommands()
|
|
|
|
|
|
|
|
elif len(args) == 1:
|
|
|
|
name = args[0]
|
|
|
|
|
|
|
|
try:
|
2020-02-25 20:18:31 +00:00
|
|
|
cmd = all_commands[name]()
|
2008-10-21 14:00:00 +00:00
|
|
|
except KeyError:
|
2012-11-02 05:59:27 +00:00
|
|
|
print("repo: '%s' is not a repo command." % name, file=sys.stderr)
|
2008-10-21 14:00:00 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2011-10-11 22:23:37 +00:00
|
|
|
cmd.manifest = self.manifest
|
2008-10-21 14:00:00 +00:00
|
|
|
self._PrintCommandHelp(cmd)
|
|
|
|
|
|
|
|
else:
|
|
|
|
self._PrintCommandHelp(self)
|