mirror of
https://github.com/Aider-AI/aider.git
synced 2025-06-03 19:24:59 +00:00
Added DotEnvFormatter class for formatting .env help text in argparse.
This commit is contained in:
parent
fed0bf55c2
commit
289ab516e9
2 changed files with 75 additions and 1 deletions
|
@ -7,7 +7,7 @@ import sys
|
||||||
import configargparse
|
import configargparse
|
||||||
|
|
||||||
from aider import __version__, models
|
from aider import __version__, models
|
||||||
from aider.args_formatter import MarkdownHelpFormatter, YamlHelpFormatter#, DotEnvFormatter
|
from aider.args_formatter import MarkdownHelpFormatter, YamlHelpFormatter, DotEnvFormatter
|
||||||
|
|
||||||
from .dump import dump # noqa: F401
|
from .dump import dump # noqa: F401
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,80 @@ import argparse
|
||||||
from .dump import dump # noqa: F401
|
from .dump import dump # noqa: F401
|
||||||
|
|
||||||
|
|
||||||
|
class DotEnvFormatter(argparse.HelpFormatter):
|
||||||
|
def start_section(self, heading):
|
||||||
|
res = "\n\n"
|
||||||
|
res += "#" * (len(heading) + 3)
|
||||||
|
res += f"\n# {heading}"
|
||||||
|
super().start_section(res)
|
||||||
|
|
||||||
|
def _format_usage(self, usage, actions, groups, prefix):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def _format_text(self, text):
|
||||||
|
return """
|
||||||
|
##########################################################
|
||||||
|
# Sample .env
|
||||||
|
# This file lists *all* the valid configuration entries.
|
||||||
|
# Place in your home dir, or at the root of your git repo.
|
||||||
|
##########################################################
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def _format_action(self, action):
|
||||||
|
if not action.option_strings:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
parts = [""]
|
||||||
|
|
||||||
|
metavar = action.metavar
|
||||||
|
if not metavar and isinstance(action, argparse._StoreAction):
|
||||||
|
metavar = "VALUE"
|
||||||
|
|
||||||
|
default = action.default
|
||||||
|
if default == argparse.SUPPRESS:
|
||||||
|
default = ""
|
||||||
|
elif isinstance(default, str):
|
||||||
|
pass
|
||||||
|
elif isinstance(default, list) and not default:
|
||||||
|
default = ""
|
||||||
|
elif action.default is not None:
|
||||||
|
default = "true" if default else "false"
|
||||||
|
else:
|
||||||
|
default = ""
|
||||||
|
|
||||||
|
if action.help:
|
||||||
|
parts.append(f"## {action.help}")
|
||||||
|
|
||||||
|
for switch in action.option_strings:
|
||||||
|
if switch.startswith("--"):
|
||||||
|
break
|
||||||
|
switch = switch.lstrip("-")
|
||||||
|
|
||||||
|
if isinstance(action, argparse._StoreTrueAction):
|
||||||
|
default = False
|
||||||
|
elif isinstance(action, argparse._StoreConstAction):
|
||||||
|
default = False
|
||||||
|
|
||||||
|
if default is False:
|
||||||
|
default = "false"
|
||||||
|
if default is True:
|
||||||
|
default = "true"
|
||||||
|
|
||||||
|
if default:
|
||||||
|
parts.append(f"{switch}={default}\n")
|
||||||
|
else:
|
||||||
|
parts.append(f"{switch}=\n")
|
||||||
|
|
||||||
|
return "\n".join(parts) + "\n"
|
||||||
|
|
||||||
|
def _format_action_invocation(self, action):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
def _format_args(self, action, default_metavar):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
|
||||||
class YamlHelpFormatter(argparse.HelpFormatter):
|
class YamlHelpFormatter(argparse.HelpFormatter):
|
||||||
def start_section(self, heading):
|
def start_section(self, heading):
|
||||||
res = "\n\n"
|
res = "\n\n"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue