Return the script's main help text, as a string.
(self, commands_only=False)
| 208 | self.settings_exception = None |
| 209 | |
| 210 | def main_help_text(self, commands_only=False): |
| 211 | """Return the script's main help text, as a string.""" |
| 212 | if commands_only: |
| 213 | usage = sorted(get_commands()) |
| 214 | else: |
| 215 | usage = [ |
| 216 | "", |
| 217 | "Type '%s help <subcommand>' for help on a specific subcommand." |
| 218 | % self.prog_name, |
| 219 | "", |
| 220 | "Available subcommands:", |
| 221 | ] |
| 222 | commands_dict = defaultdict(lambda: []) |
| 223 | for name, app in get_commands().items(): |
| 224 | if app == "django.core": |
| 225 | app = "django" |
| 226 | else: |
| 227 | app = app.rpartition(".")[-1] |
| 228 | commands_dict[app].append(name) |
| 229 | style = color_style() |
| 230 | for app in sorted(commands_dict): |
| 231 | usage.append("") |
| 232 | usage.append(style.NOTICE("[%s]" % app)) |
| 233 | for name in sorted(commands_dict[app]): |
| 234 | usage.append(" %s" % name) |
| 235 | # Output an extra note if settings are not properly configured |
| 236 | if self.settings_exception is not None: |
| 237 | usage.append( |
| 238 | style.NOTICE( |
| 239 | "Note that only Django core commands are listed " |
| 240 | "as settings are not properly configured (error: %s)." |
| 241 | % self.settings_exception |
| 242 | ) |
| 243 | ) |
| 244 | |
| 245 | return "\n".join(usage) |
| 246 | |
| 247 | def fetch_command(self, subcommand): |
| 248 | """ |
no test coverage detected