Improve Python config file template substitution #8
1 changed files with 22 additions and 2 deletions
cmds.projects.CmdCreateFile: Support --search-path
Add --search-path to the list of CmdCreateFile's supported options. Its value is split by ":" and subsequently passed to the tmpl_render()'s search_path argument.
Signed-off-by: Jan Lindemann <jan@janware.com>
commit
01be594103
|
|
@ -5,7 +5,7 @@ from typing import Iterable, TypeAlias
|
|||
from ...lib.log import WARNING, log
|
||||
from .Cmd import Cmd, Parent
|
||||
from .lib.pkg_relations import VersionSyntax, pkg_relations
|
||||
from .lib.templates import tmpl_render
|
||||
from .lib.templates import RenderValues, tmpl_render
|
||||
|
||||
def key_value(s):
|
||||
try:
|
||||
|
|
@ -37,6 +37,21 @@ class CmdCreateFile(Cmd): # export
|
|||
entry.append(val)
|
||||
return ret
|
||||
|
||||
def __render(
|
||||
self,
|
||||
template_name: str,
|
||||
values: list[RenderValues],
|
||||
li_quote = False,
|
||||
li_delimiter = '\n',
|
||||
) -> str:
|
||||
return tmpl_render(
|
||||
template_name,
|
||||
values,
|
||||
li_quote = li_quote,
|
||||
li_delimiter = li_delimiter,
|
||||
search_path = self.app.args.search_path.split(':'),
|
||||
)
|
||||
|
||||
def render_pyright(self, module: str, extra_fields: TupleList) -> str:
|
||||
prereq = pkg_relations(
|
||||
self.app,
|
||||
|
|
@ -64,7 +79,7 @@ class CmdCreateFile(Cmd): # export
|
|||
}
|
||||
self.__update_dict(values, extra_fields)
|
||||
|
||||
return tmpl_render(
|
||||
return self.__render(
|
||||
'pyrightconfig.json', [values], li_quote = True, li_delimiter = ',\n'
|
||||
)
|
||||
|
||||
|
|
@ -80,6 +95,11 @@ class CmdCreateFile(Cmd): # export
|
|||
choices = [fmt.name.lower() for fmt in Fmt],
|
||||
help = 'Output format'
|
||||
)
|
||||
parser.add_argument(
|
||||
'--search-path',
|
||||
default = '/etc/opt/jw-pkg/templates',
|
||||
help = 'Template search path, colon separated',
|
||||
)
|
||||
parser.add_argument(
|
||||
'-f',
|
||||
'--field',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue