-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
version: Extend output to include ECE API Version (#53)
Extends the `ecctl version` output to include a structured output and a series of information which was missing: ```console $ ./bin/ecctl version Version: 1.0.0-rc1-dev Client API Version: 2.4.2 Go version: go1.13.4 Git commit: 8d72808 Built: Fri 15 Nov 09:24:14 2019 OS/Arch: darwin / amd64 ``` Signed-off-by: Marc Lopez <[email protected]>
- Loading branch information
Showing
8 changed files
with
174 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package ecctl | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"runtime" | ||
"strings" | ||
"text/tabwriter" | ||
) | ||
|
||
// VersionInfo contains detailed information about the binary. | ||
type VersionInfo struct { | ||
Version string | ||
APIVersion string | ||
Commit string | ||
Built string | ||
|
||
// Non Displayed fields | ||
Repository string | ||
Organization string | ||
} | ||
|
||
func (v VersionInfo) String() string { | ||
buf := new(bytes.Buffer) | ||
|
||
w := tabwriter.NewWriter(buf, 2, 2, 3, ' ', 0) | ||
|
||
var commit = v.Commit | ||
if len(commit) >= 8 { | ||
commit = commit[:8] | ||
} | ||
|
||
fmt.Fprintln(w, "Version:\t", v.Version) | ||
fmt.Fprintln(w, "Client API Version:\t", v.APIVersion) | ||
fmt.Fprintln(w, "Go version:\t", runtime.Version()) | ||
fmt.Fprintln(w, "Git commit:\t", commit) | ||
fmt.Fprintln(w, "Built:\t", strings.ReplaceAll(v.Built, "_", " ")) | ||
fmt.Fprintln(w, "OS/Arch:\t", runtime.GOOS, "/", runtime.GOARCH) | ||
|
||
w.Flush() | ||
|
||
return buf.String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Licensed to Elasticsearch B.V. under one or more contributor | ||
// license agreements. See the NOTICE file distributed with | ||
// this work for additional information regarding copyright | ||
// ownership. Elasticsearch B.V. licenses this file to you under | ||
// the Apache License, Version 2.0 (the "License"); you may | ||
// not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package ecctl | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
const vTemplate = `Version: 1.0.0 | ||
Client API Version: 2.4.2 | ||
Go version: %s | ||
Git commit: 12345678 | ||
Built: Fri 15 Nov 09:24:14 2019 | ||
OS/Arch: %s / %s | ||
` | ||
|
||
func TestVersionInfo_String(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
fields VersionInfo | ||
want string | ||
}{ | ||
{ | ||
name: "Prints the version", | ||
fields: VersionInfo{ | ||
Version: "1.0.0", | ||
APIVersion: "2.4.2", | ||
Commit: "12345678910", | ||
Built: "Fri_15_Nov_09:24:14_2019", | ||
}, | ||
want: fmt.Sprintf(vTemplate, runtime.Version(), runtime.GOOS, runtime.GOARCH), | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
v := tt.fields | ||
if got := v.String(); got != tt.want { | ||
t.Errorf("VersionInfo.String() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |