Better design about command formatting #1196
Replies: 3 comments 4 replies
-
If you approve this approach, I'd like to write a PR |
Beta Was this translation helpful? Give feedback.
-
I kinda understand the design of Cases like below can be an overuse of it. below case is doable with just python's format and ensure_quoted. It took me quite a while to figure out class FindFilesBase(FactBase):
abstract = True
default = list
type_flag: str
def process(self, output):
return output
def command(self, path, quote_path=True):
return make_formatted_string_command(
"find {0} -type {type_flag} || true",
QuoteString(path) if quote_path else path,
type_flag=self.type_flag,
) |
Beta Was this translation helpful? Give feedback.
-
Maybe the more appreciate use of StringCommand is to pass args, instead of relying on make_formatted_string_command. this way |
Beta Was this translation helpful? Give feedback.
-
I'm working on a few PRs, and found current design of command formatting a bit hard to grasp
Take this for example
Before, path was written as QuoteString, and it's a bit hard to compose args(and understand)
When I track down, QuoteString was handled as a special case in StringCommand
make_formatted_string_command makes the command more complicated. it splits the command then in QuoteString it will be composed again. I don't get this design.
Until now, with direct use of shlex.quote(wrapped directly in QuoteString.str), formatting becomes more controllable.
I'd prefer using vanilla format and QuoteString so it becomes
I'm I losing something?
Beta Was this translation helpful? Give feedback.
All reactions