Skip to content

add "replace" from sprig to go template functions #11572

Description

@armindarvish

Describe the feature or problem you’d like to solve

I am trying to use the "--template" formatting with gh search issues, and I want to remove newlines from the title of the issues. I tried using {{.title | replace \"\n\" " "}}:

gh search issues --sort updated --include-prs --author @me --json isPullRequest,repository,title,number,labels,updatedAt,state,url,commentsCount --template "{{range .}}{{.isPullRequest}}      {{.repository.nameWithOwner}}      {{.title | replace \"\n\" \" \"}}      {{.number}}      {{.state}}      {{.updatedAt}}      {{.labels}}      {{.url}} \n\n {{end}}" --state open

I get an error saying:

the function "replace" is not defined

There is a replace function available in the "sprig library", but it appears that this is not available in gh.

Proposed solution

Add the replace function from sprig library for go template formatting.

Activity

  1. github-actions commented on Aug 25, 2025

    @github-actions
    Contributor

    Thank you for your issue! We have categorized it as a feature request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.

    Unless you see the help wanted Contributions welcome label, we are not currently looking for external contributions for this feature.

    If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.

  2. BagToad commented on Aug 25, 2025

    @BagToad
    Member

    👋 Hey @armindarvish, thank you for writing this up! ✨

    Sounds reasonable to me! 👍

    Implementation notes:

    We intentionally limit our exposure to all the Sprig functions, so adding this one requires adding replace to this func map.

    Note that this code is in go-gh, so to implement this we need the following, in this order:

    • A PR opened in cli/go-gh to introduce that func.
    • Some testing done by locally building cli/cli with the cli/go-gh changes to demonstrate the new func is included and works as expected.
      • Go workspaces can be helpful for this 👍
    • (maintainers only) A release cut for cli/go-gh
    • A PR opened in cli/cli to upgrade cli/go-gh. Usually, Dependabot does this for us, but it depends on the version bump.

    Intentionally no explicit acceptance criteria - the above should suffice.

  3. added and removed on Aug 25, 2025
  4. iamazeem commented on Aug 27, 2025

    @iamazeem
    Contributor

    @BagToad: PR cli/go-gh#196 opened and it's ready for review. Thanks!

  5. self-assigned this
    on Oct 22, 2025
  6. BagToad commented on Oct 22, 2025

    @BagToad
    Member
  7. BagToad commented on Nov 4, 2025

    @BagToad
    Member

    fixed by #12095

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementa request to improve CLIhelp wantedContributions welcome

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions