Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 45d3fa3

Browse files
darkowlzzibrasho
authored andcommitted
fix(status): add marshalJSON()
Add `rawStatus` struct and use `marshalJSON()` to convert `BasicStatus` to `rawStatus`.
1 parent f1aaf31 commit 45d3fa3

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

cmd/dep/status.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,20 @@ func (out *tableOutput) MissingFooter() {
118118

119119
type jsonOutput struct {
120120
w io.Writer
121-
basic []*BasicStatus
121+
basic []*rawStatus
122122
missing []*MissingStatus
123123
}
124124

125125
func (out *jsonOutput) BasicHeader() {
126-
out.basic = []*BasicStatus{}
126+
out.basic = []*rawStatus{}
127127
}
128128

129129
func (out *jsonOutput) BasicFooter() {
130130
json.NewEncoder(out.w).Encode(out.basic)
131131
}
132132

133133
func (out *jsonOutput) BasicLine(bs *BasicStatus) {
134-
bs.JSONConstraint = bs.getConsolidatedConstraint()
135-
bs.JSONVersion = formatVersion(bs.Version)
136-
out.basic = append(out.basic, bs)
134+
out.basic = append(out.basic, bs.marshalJSON())
137135
}
138136

139137
func (out *jsonOutput) MissingHeader() {
@@ -232,6 +230,15 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
232230
return nil
233231
}
234232

233+
type rawStatus struct {
234+
ProjectRoot string
235+
Constraint string
236+
Version string
237+
Revision gps.Revision
238+
Latest gps.Version
239+
PackageCount int
240+
}
241+
235242
// BasicStatus contains all the information reported about a single dependency
236243
// in the summary/list status output mode.
237244
type BasicStatus struct {
@@ -270,6 +277,17 @@ func (bs *BasicStatus) getConsolidatedVersion() string {
270277
return version
271278
}
272279

280+
func (bs *BasicStatus) marshalJSON() *rawStatus {
281+
return &rawStatus{
282+
ProjectRoot: bs.ProjectRoot,
283+
Constraint: bs.getConsolidatedConstraint(),
284+
Version: formatVersion(bs.Version),
285+
Revision: bs.Revision,
286+
Latest: bs.Latest,
287+
PackageCount: bs.PackageCount,
288+
}
289+
}
290+
273291
// MissingStatus contains information about all the missing packages in a project.
274292
type MissingStatus struct {
275293
ProjectRoot string

cmd/dep/status_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TestStatusFormatVersion(t *testing.T) {
3333
}
3434

3535
func TestBasicLine(t *testing.T) {
36-
3736
project := dep.Project{}
3837
aSemverConstraint, _ := gps.NewSemverConstraint("1.2.3")
3938

@@ -140,7 +139,6 @@ func TestBasicLine(t *testing.T) {
140139
}
141140

142141
func TestBasicStatusGetConsolidatedConstraint(t *testing.T) {
143-
144142
aSemverConstraint, _ := gps.NewSemverConstraint("1.2.1")
145143

146144
testCases := []struct {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
[{"ProjectRoot":"github.com/sdboyer/deptest","Children":null,"Revision":"ff2948a2ac8f538c4ecd55962e919d1e13e74baf","Latest":"3f4c3bea144e112a69bbe5d8d01c1b09a544253f","PackageCount":1,"Constraint":"^0.8.0","Version":"v0.8.0"},{"ProjectRoot":"github.com/sdboyer/deptestdos","Children":null,"Revision":"5c607206be5decd28e6263ffffdcee067266015e","Latest":"5c607206be5decd28e6263ffffdcee067266015e","PackageCount":1,"Constraint":"*","Version":"v2.0.0"}]
1+
[{"ProjectRoot":"github.com/sdboyer/deptest","Constraint":"^0.8.0","Version":"v0.8.0","Revision":"ff2948a2ac8f538c4ecd55962e919d1e13e74baf","Latest":"3f4c3bea144e112a69bbe5d8d01c1b09a544253f","PackageCount":1},{"ProjectRoot":"github.com/sdboyer/deptestdos","Constraint":"*","Version":"v2.0.0","Revision":"5c607206be5decd28e6263ffffdcee067266015e","Latest":"5c607206be5decd28e6263ffffdcee067266015e","PackageCount":1}]

0 commit comments

Comments
 (0)