diff options
Diffstat (limited to 'subcmds/help.py')
-rw-r--r-- | subcmds/help.py | 61 |
1 files changed, 36 insertions, 25 deletions
diff --git a/subcmds/help.py b/subcmds/help.py index 78930502..1a60ef45 100644 --- a/subcmds/help.py +++ b/subcmds/help.py | |||
@@ -1,5 +1,3 @@ | |||
1 | # -*- coding:utf-8 -*- | ||
2 | # | ||
3 | # Copyright (C) 2008 The Android Open Source Project | 1 | # Copyright (C) 2008 The Android Open Source Project |
4 | # | 2 | # |
5 | # Licensed under the Apache License, Version 2.0 (the "License"); | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
@@ -14,17 +12,19 @@ | |||
14 | # See the License for the specific language governing permissions and | 12 | # See the License for the specific language governing permissions and |
15 | # limitations under the License. | 13 | # limitations under the License. |
16 | 14 | ||
17 | from __future__ import print_function | ||
18 | import re | 15 | import re |
19 | import sys | 16 | import sys |
20 | from formatter import AbstractFormatter, DumbWriter | 17 | import textwrap |
21 | 18 | ||
19 | from subcmds import all_commands | ||
22 | from color import Coloring | 20 | from color import Coloring |
23 | from command import PagedCommand, MirrorSafeCommand, GitcAvailableCommand, GitcClientCommand | 21 | from command import PagedCommand, MirrorSafeCommand, GitcAvailableCommand, GitcClientCommand |
24 | import gitc_utils | 22 | import gitc_utils |
23 | from wrapper import Wrapper | ||
24 | |||
25 | 25 | ||
26 | class Help(PagedCommand, MirrorSafeCommand): | 26 | class Help(PagedCommand, MirrorSafeCommand): |
27 | common = False | 27 | COMMON = False |
28 | helpSummary = "Display detailed help on a command" | 28 | helpSummary = "Display detailed help on a command" |
29 | helpUsage = """ | 29 | helpUsage = """ |
30 | %prog [--all|command] | 30 | %prog [--all|command] |
@@ -41,7 +41,7 @@ Displays detailed usage information about a command. | |||
41 | fmt = ' %%-%ds %%s' % maxlen | 41 | fmt = ' %%-%ds %%s' % maxlen |
42 | 42 | ||
43 | for name in commandNames: | 43 | for name in commandNames: |
44 | command = self.commands[name] | 44 | command = all_commands[name]() |
45 | try: | 45 | try: |
46 | summary = command.helpSummary.strip() | 46 | summary = command.helpSummary.strip() |
47 | except AttributeError: | 47 | except AttributeError: |
@@ -50,20 +50,27 @@ Displays detailed usage information about a command. | |||
50 | 50 | ||
51 | def _PrintAllCommands(self): | 51 | def _PrintAllCommands(self): |
52 | print('usage: repo COMMAND [ARGS]') | 52 | print('usage: repo COMMAND [ARGS]') |
53 | self.PrintAllCommandsBody() | ||
54 | |||
55 | def PrintAllCommandsBody(self): | ||
53 | print('The complete list of recognized repo commands are:') | 56 | print('The complete list of recognized repo commands are:') |
54 | commandNames = list(sorted(self.commands)) | 57 | commandNames = list(sorted(all_commands)) |
55 | self._PrintCommands(commandNames) | 58 | self._PrintCommands(commandNames) |
56 | print("See 'repo help <command>' for more information on a " | 59 | print("See 'repo help <command>' for more information on a " |
57 | 'specific command.') | 60 | 'specific command.') |
61 | print('Bug reports:', Wrapper().BUG_URL) | ||
58 | 62 | ||
59 | def _PrintCommonCommands(self): | 63 | def _PrintCommonCommands(self): |
60 | print('usage: repo COMMAND [ARGS]') | 64 | print('usage: repo COMMAND [ARGS]') |
65 | self.PrintCommonCommandsBody() | ||
66 | |||
67 | def PrintCommonCommandsBody(self): | ||
61 | print('The most commonly used repo commands are:') | 68 | print('The most commonly used repo commands are:') |
62 | 69 | ||
63 | def gitc_supported(cmd): | 70 | def gitc_supported(cmd): |
64 | if not isinstance(cmd, GitcAvailableCommand) and not isinstance(cmd, GitcClientCommand): | 71 | if not isinstance(cmd, GitcAvailableCommand) and not isinstance(cmd, GitcClientCommand): |
65 | return True | 72 | return True |
66 | if self.manifest.isGitcClient: | 73 | if self.client.isGitcClient: |
67 | return True | 74 | return True |
68 | if isinstance(cmd, GitcClientCommand): | 75 | if isinstance(cmd, GitcClientCommand): |
69 | return False | 76 | return False |
@@ -72,21 +79,21 @@ Displays detailed usage information about a command. | |||
72 | return False | 79 | return False |
73 | 80 | ||
74 | commandNames = list(sorted([name | 81 | commandNames = list(sorted([name |
75 | for name, command in self.commands.items() | 82 | for name, command in all_commands.items() |
76 | if command.common and gitc_supported(command)])) | 83 | if command.COMMON and gitc_supported(command)])) |
77 | self._PrintCommands(commandNames) | 84 | self._PrintCommands(commandNames) |
78 | 85 | ||
79 | print( | 86 | print( |
80 | "See 'repo help <command>' for more information on a specific command.\n" | 87 | "See 'repo help <command>' for more information on a specific command.\n" |
81 | "See 'repo help --all' for a complete list of recognized commands.") | 88 | "See 'repo help --all' for a complete list of recognized commands.") |
89 | print('Bug reports:', Wrapper().BUG_URL) | ||
82 | 90 | ||
83 | def _PrintCommandHelp(self, cmd, header_prefix=''): | 91 | def _PrintCommandHelp(self, cmd, header_prefix=''): |
84 | class _Out(Coloring): | 92 | class _Out(Coloring): |
85 | def __init__(self, gc): | 93 | def __init__(self, gc): |
86 | Coloring.__init__(self, gc, 'help') | 94 | Coloring.__init__(self, gc, 'help') |
87 | self.heading = self.printer('heading', attr='bold') | 95 | self.heading = self.printer('heading', attr='bold') |
88 | 96 | self._first = True | |
89 | self.wrap = AbstractFormatter(DumbWriter()) | ||
90 | 97 | ||
91 | def _PrintSection(self, heading, bodyAttr): | 98 | def _PrintSection(self, heading, bodyAttr): |
92 | try: | 99 | try: |
@@ -96,7 +103,9 @@ Displays detailed usage information about a command. | |||
96 | if body == '' or body is None: | 103 | if body == '' or body is None: |
97 | return | 104 | return |
98 | 105 | ||
99 | self.nl() | 106 | if not self._first: |
107 | self.nl() | ||
108 | self._first = False | ||
100 | 109 | ||
101 | self.heading('%s%s', header_prefix, heading) | 110 | self.heading('%s%s', header_prefix, heading) |
102 | self.nl() | 111 | self.nl() |
@@ -106,7 +115,8 @@ Displays detailed usage information about a command. | |||
106 | body = body.strip() | 115 | body = body.strip() |
107 | body = body.replace('%prog', me) | 116 | body = body.replace('%prog', me) |
108 | 117 | ||
109 | asciidoc_hdr = re.compile(r'^\n?#+ (.+)$') | 118 | # Extract the title, but skip any trailing {#anchors}. |
119 | asciidoc_hdr = re.compile(r'^\n?#+ ([^{]+)(\{#.+\})?$') | ||
110 | for para in body.split("\n\n"): | 120 | for para in body.split("\n\n"): |
111 | if para.startswith(' '): | 121 | if para.startswith(' '): |
112 | self.write('%s', para) | 122 | self.write('%s', para) |
@@ -121,19 +131,21 @@ Displays detailed usage information about a command. | |||
121 | self.nl() | 131 | self.nl() |
122 | continue | 132 | continue |
123 | 133 | ||
124 | self.wrap.add_flowing_data(para) | 134 | lines = textwrap.wrap(para.replace(' ', ' '), width=80, |
125 | self.wrap.end_paragraph(1) | 135 | break_long_words=False, break_on_hyphens=False) |
126 | self.wrap.end_paragraph(0) | 136 | for line in lines: |
137 | self.write('%s', line) | ||
138 | self.nl() | ||
139 | self.nl() | ||
127 | 140 | ||
128 | out = _Out(self.manifest.globalConfig) | 141 | out = _Out(self.client.globalConfig) |
129 | out._PrintSection('Summary', 'helpSummary') | 142 | out._PrintSection('Summary', 'helpSummary') |
130 | cmd.OptionParser.print_help() | 143 | cmd.OptionParser.print_help() |
131 | out._PrintSection('Description', 'helpDescription') | 144 | out._PrintSection('Description', 'helpDescription') |
132 | 145 | ||
133 | def _PrintAllCommandHelp(self): | 146 | def _PrintAllCommandHelp(self): |
134 | for name in sorted(self.commands): | 147 | for name in sorted(all_commands): |
135 | cmd = self.commands[name] | 148 | cmd = all_commands[name](manifest=self.manifest) |
136 | cmd.manifest = self.manifest | ||
137 | self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,)) | 149 | self._PrintCommandHelp(cmd, header_prefix='[%s] ' % (name,)) |
138 | 150 | ||
139 | def _Options(self, p): | 151 | def _Options(self, p): |
@@ -157,12 +169,11 @@ Displays detailed usage information about a command. | |||
157 | name = args[0] | 169 | name = args[0] |
158 | 170 | ||
159 | try: | 171 | try: |
160 | cmd = self.commands[name] | 172 | cmd = all_commands[name](manifest=self.manifest) |
161 | except KeyError: | 173 | except KeyError: |
162 | print("repo: '%s' is not a repo command." % name, file=sys.stderr) | 174 | print("repo: '%s' is not a repo command." % name, file=sys.stderr) |
163 | sys.exit(1) | 175 | sys.exit(1) |
164 | 176 | ||
165 | cmd.manifest = self.manifest | ||
166 | self._PrintCommandHelp(cmd) | 177 | self._PrintCommandHelp(cmd) |
167 | 178 | ||
168 | else: | 179 | else: |