Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subcommand-style callable enhancements #10

Open
dgw opened this issue Mar 19, 2024 · 1 comment
Open

Subcommand-style callable enhancements #10

dgw opened this issue Mar 19, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@dgw
Copy link
Member

dgw commented Mar 19, 2024

Sopel 8's documentation for @plugin.command suggests a couple different ways to do "subcommands", which can be pretty great. One way is to have .command sub1, .command sub2, ..., .command (the final definition providing a default action or showing usage) on a single callable, as proposed for .tmask in sopel-irc/sopel#2601. The implementation ends up pretty clean, with the only stylistic downside (IMO) being an extra level of indentation on the code to handle each subcommand. (In less trivial cases, each subcommand naturally lends itself to being a separate helper function anyway, so I don't think this is that big of a drawback in practice.)

However: I'm not super happy with the tools available to plugin authors for writing help to go with this style. The single callable naturally has only a single docstring, which can be confusingly long if it attempts to explain the full range of options available, which is made worse by the help plugin's naïve line-splitting:

16:29:20 <dgw> .help tmask
16:29:21 <SopelGitpod> Set, get, or clear the current channel's topic mask.
16:29:21 <SopelGitpod> Recognized subcommands are 'set', 'get', and 'clear'. A plain 'tmask'
16:29:21 <SopelGitpod> command with no arguments is equivalent to 'tmask get'.
16:29:23 <SopelGitpod> This mask is used by the 'topic' command. `{}` allows interpolating a chunk
16:29:24 <SopelGitpod> of text within the topic mask template.
16:29:25 <SopelGitpod> e.g. .tmask set My {} topic mask!, .tmask get or .tmask clear

At the moment, I'm afraid I don't have any concrete ideas for making this better. The goal right now is to simply recognize that it's a problem—if other people also think the above is clunky—and then we can brainstorm how to improve things independently of Sopel's release cycle because this plugin is separate now. 😸

@dgw
Copy link
Member Author

dgw commented Mar 19, 2024

Oh, and maybe the aforementioned line-splitting behavior should be its own issue? It should be possible now to detect paragraph breaks in callable docstrings and rewrap the text using the value from bot.safe_text_length(recipient) so it will fit in the minimum number of IRC lines instead of blindly following line breaks in the plugin's source code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants