Description
I have a pet peeve with the way we need to deal with the "command source files".
I'm talking about the fact that we're handling code that will be wrapped by a function and this fact is not explicit.
Two bad things results from this:
- It's a cognitive load. Something the developer needs to remember. I'm already used to it but when I'm onboarding a new contributor I need to explain this detail.
- It confuses some tools, like linters and LLMs.
example
In a previous conversation @DannyBen mentioned:
you should not shellcheck the partial snippets, but just the final script.
Some points about this:
- I really enjoy having a linter right into the editor, highlighting issues as I type them, exactly where they are, in a way where I can quickly handle them.
- Also, my colleagues are not bash nerds like me. So having shellcheck in their editors is useful for them, as a learning tool
- If I only shellcheck the final script, I need to configure pre-commit git-hooks/CI validation and spend human resources in the PR process
So... What I always end up doing is tweaking a .shellcheckrc and some # shellcheck disable=XXX here and there in order to still use shellcheck in bashly partials.
proposed solution
Note: I'm not taking into consideration the challenge of actually implementing it, just sharing what I think would be ideal as a bashly user.
A "command source file" should explicitly have a function, named with the same pattern it has today: <app>_<subcommand>_command.
What I see as ideal is bashly build automatically validating if the file has a function with the right name, interrupting the build if not.
Description
I have a pet peeve with the way we need to deal with the "command source files".
I'm talking about the fact that we're handling code that will be wrapped by a function and this fact is not explicit.
Two bad things results from this:
example
In a previous conversation @DannyBen mentioned:
Some points about this:
So... What I always end up doing is tweaking a
.shellcheckrcand some# shellcheck disable=XXXhere and there in order to still use shellcheck in bashly partials.proposed solution
Note: I'm not taking into consideration the challenge of actually implementing it, just sharing what I think would be ideal as a bashly user.
A "command source file" should explicitly have a function, named with the same pattern it has today:
<app>_<subcommand>_command.What I see as ideal is
bashly buildautomatically validating if the file has a function with the right name, interrupting the build if not.I have another possible approach that may address the main concerns raised here without introducing a separate command-source mode.
We could allow command partials to optionally use a reserved
bashly_command()envelope:When loading the partial, Bashly would recognize this exact envelope, remove its opening and closing lines, and insert the body into the real generated command function as it does today. The body would be inserted verbatim rather than indented again, since it is already formatted as a function body.
The generated result would remain: