MCPcopy
hub / github.com/digitalocean/doctl / CompleteJSON

Method CompleteJSON

doit.go:144–172  ·  view source on GitHub ↗

CompleteJSON is the complete version for doit, formatted as JSON.

(lv LatestVersioner)

Source from the content-addressed store, hash-verified

142
143// CompleteJSON is the complete version for doit, formatted as JSON.
144func (v Version) CompleteJSON(lv LatestVersioner) string {
145 versionInfo := &struct {
146 Version string `json:"version,omitempty"`
147 Commit string `json:"commit,omitempty"`
148 LatestRelease string `json:"latestRelease"`
149 Notification string `json:"notification,omitempty"`
150 }{
151 Version: v.String(),
152 Commit: v.Build,
153 }
154
155 if tagName, err := lv.LatestVersion(); err == nil {
156 versionInfo.LatestRelease = tagName
157
158 v0, err1 := semver.Make(tagName)
159 v1, err2 := semver.Make(v.String())
160
161 if len(v0.Build) == 0 {
162 v0, err1 = semver.Make(tagName + "-release")
163 }
164
165 if err1 == nil && err2 == nil && v0.GT(v1) {
166 versionInfo.Notification = fmt.Sprintf("release %s is available, check it out!", tagName)
167 }
168 }
169
170 data, _ := json.MarshalIndent(versionInfo, "", " ")
171 return string(data)
172}
173
174// LatestVersioner an interface for detecting the latest version.
175type LatestVersioner interface {

Callers 2

TestVersionFunction · 0.80
VersionFunction · 0.80

Calls 3

StringMethod · 0.95
SprintfMethod · 0.80
LatestVersionMethod · 0.65

Tested by 1

TestVersionFunction · 0.64