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

feat: Add outputList template function #4255

Merged

Conversation

halostatue
Copy link
Collaborator

Resolves #4253

@halostatue
Copy link
Collaborator Author

halostatue commented Feb 4, 2025

This is mostly a proof of concept, but if the limitations list … | toStrings is acceptable, then I think we're OK. Otherwise, we'll need to essentially implement toStrings internally to outputList.

I’m also not particularly fond of the name. However, I have been able to run the template in #4253 successfully:

$ go run . execute-template \
  '{{- $opts := dict
        "show-help" true
        "ordered" true
        "no-limit" true
        "header" "Choose a movie poison"
        "options" (list "cyanide" "arsenic" "iocaine powder") 
  -}}{{ includeTemplate "multichoice.tmpl" $opts }}'
["arsenic","iocaine powder"]

@halostatue halostatue force-pushed the output-list-template-function branch from d47255a to ce88aac Compare February 4, 2025 01:52
Copy link
Owner

@twpayne twpayne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and I think this feature is necessary -- as you say, there's no way to pass a variable number of arguments to a Go template function.

internal/cmd/templatefuncs.go Outdated Show resolved Hide resolved
@halostatue halostatue force-pushed the output-list-template-function branch 2 times, most recently from f0cc511 to b525b4f Compare February 6, 2025 00:33
@halostatue halostatue force-pushed the output-list-template-function branch from b525b4f to 277d5a4 Compare February 6, 2025 01:02
@halostatue
Copy link
Collaborator Author

I’m going to merge this so it's in the next release. It works and I was able to get it working with gum using that template, so all is good.

I think that this is useful, but think it might be better to incorporate my "multichoice" template as a feature suggested in #4252 (since I want to be able to use it for init, I would rather not have to ensure that gum is installed to init a repo).

@halostatue halostatue merged commit df7d3e5 into twpayne:master Feb 6, 2025
32 checks passed
@halostatue halostatue deleted the output-list-template-function branch February 6, 2025 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

outputList template function
2 participants