@@ -71,26 +71,31 @@ const snapctlDebounceWindow = 200 * time.Millisecond
7171// properly organize the hook tasks in the chain of tasks in the change.
7272const finalSeedTask = "mark-seeded"
7373
74+ // ChangeInfo represents the information about a change that is needed for JSON marshaling.
7475// To unmarshal the data needed for `snap tasks`, we need access
7576// to all struct fields that client.Change has. However, Change.data is an
7677// unexported field, so we cannot unmarshal into it directly. There is a
7778// changeAndData struct in the client package with all exported fields, but the
7879// struct itself is not exported.
7980type ChangeInfo struct {
80- ID string `json:"id"`
81- Kind string `json:"kind"`
82- Summary string `json:"summary"`
83- Status string `json:"status"`
81+ ID string `json:"id"`
82+ Kind string `json:"kind"`
83+ Summary string `json:"summary"`
84+ Status string `json:"status"`
8485 Tasks []TaskInfo `json:"tasks,omitempty"`
85- Ready bool `json:"ready"`
86- Err string `json:"err,omitempty"`
86+ Ready bool `json:"ready"`
87+ Err string `json:"err,omitempty"`
8788
8889 SpawnTime time.Time `json:"spawn-time,omitzero"`
8990 ReadyTime * time.Time `json:"ready-time,omitempty"`
9091
9192 Data map [string ]* json.RawMessage `json:"data,omitempty"`
9293}
9394
95+ // TaskInfo represents the information about a task that is needed for JSON marshaling
96+ // for `snap tasks` output. It includes fields such as ID, kind, summary, status, and
97+ // any additional data associated with the task. The Data field is a map of string keys
98+ // to raw JSON messages, allowing for flexible inclusion of task-specific data in the output.
9499type TaskInfo struct {
95100 ID string `json:"id"`
96101 Kind string `json:"kind"`
@@ -105,15 +110,18 @@ type TaskInfo struct {
105110 Data map [string ]* json.RawMessage `json:"data,omitempty"`
106111}
107112
113+ // TaskInfoProgress represents the progress of a task, including a label and the
114+ // amount of work done out of the total. Used in the TaskInfo struct to provide
115+ // progress information for tasks in the `snap tasks` output.
108116type TaskInfoProgress struct {
109117 Label string `json:"label"`
110118 Done int `json:"done"`
111119 Total int `json:"total"`
112120}
113121
114- // To unmarshal the data needed for `snap tasks`, we need access
115- // to all struct fields that client.Change has. However, due to unexported
116- // fields, we use ChangeInfo instead .
122+ // StateChangeToChangeInfo converts a state.Change to a ChangeInfo struct which has all
123+ // the exported fields needed for JSON marshaling for `snap tasks` output. It also extracts
124+ // the "api-data" from the change and includes it in the ChangeInfo.Data field .
117125func StateChangeToChangeInfo (chg * state.Change ) * ChangeInfo {
118126 status := chg .Status ()
119127 chgInfo := & ChangeInfo {
0 commit comments