Skip to content

problem: command source files are implicitly wrapped by a function #729

Description

@meleu

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:

  1. 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.
  2. It confuses some tools, like linters and LLMs.
example Image

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.

Pinned by DannyBen

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions