Skip to content

feat: add task name to the json output #2256

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

Merged
merged 1 commit into from
May 20, 2025

Conversation

aleksandersh
Copy link
Contributor

Hi, nice to meet you, and thanks for developing the task tool!

Rationale

I'm implementing the tui client for the task. I have decided that the best way to integrate a user interface is to use the JSON output feature (task --list --json).

All works fine except the labels. If some tasks have the label field, the JSON output will contain it instead of the real name. Since I can't request the execution by the task label, the client is stuck here.

return t.Label

I found the same problem in the vscode plugin (go-task/vscode-task#167) since it is integrated with the task in the same way.

Changes

I assume that it's not right to change the behavior of this field, because there are some tools which can rely on this. Therefore, I decided to add a separate field (task) with the real task name, which can be used exactly for the purpose of executing the task.

The new JSON output will look like below

{
  "tasks": [
    {
      "name": "foobar",
      "task": "foo",
      "desc": "task description",
      "summary": "",
      "aliases": [],
      "up_to_date": false,
      "location": {
        "line": 0,
        "column": 0,
        "taskfile": ""
      }
    }
  ],
  "location": ""
}

@aleksandersh aleksandersh force-pushed the feat/add-task-name-to-json-output branch from bd4065f to c58d59d Compare May 11, 2025 22:51
task_test.go Outdated
Comment on lines 242 to 261
// WithFixtureTemplateData sets up data defined in the golden file using golang
// template. Useful if the golden file can change depending on the test.
// Example template: {{ .Value }}
// Example data definition: struct{ Value string }{Value: "value"}
func WithFixtureTemplateData(data interface{}) TestOption {
return &fixtureTemplateDataTestOption{data: data}
}

type fixtureTemplateDataTestOption struct {
data interface{}
}

func (opt *fixtureTemplateDataTestOption) applyToExecutorTest(t *ExecutorTest) {
t.fixtureTemplateData = opt.data
}

func (opt *fixtureTemplateDataTestOption) applyToFormatterTest(t *FormatterTest) {
t.fixtureTemplateData = opt.data
}

Copy link
Member

Choose a reason for hiding this comment

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

Niceee! I really like this idea. In other tests we use a post-process function to remove absolute paths from the fixtures, but I was never really happy with that solution. This is much cleaner!

I wonder if we should provide a standardised set of variables to all tests for this purpose. No need to do this in this PR though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, Pete! I'm glad you found these changes interesting

Copy link
Member

@pd93 pd93 left a comment

Choose a reason for hiding this comment

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

LGTM once the linting checks pass

@aleksandersh aleksandersh force-pushed the feat/add-task-name-to-json-output branch from c58d59d to e1b6f4b Compare May 12, 2025 17:24
Copy link
Member

@pd93 pd93 left a comment

Choose a reason for hiding this comment

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

🚀 LGTM. Pending a second review

@pd93 pd93 requested review from andreynering and vmaerten May 12, 2025 19:55
Copy link
Member

@vmaerten vmaerten left a comment

Choose a reason for hiding this comment

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

Like @pd93, I like your solution regarding the test !
LGTM

@pd93 pd93 merged commit bb5b045 into go-task:main May 20, 2025
15 checks passed
pd93 added a commit that referenced this pull request May 20, 2025
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.

3 participants