Merge pull request #220 from harshavardhana/pr_out_add_extra_information_into_mc_with_debug
This commit is contained in:
Generated
+2
-2
@@ -23,8 +23,8 @@
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio-io/cli",
|
||||
"Comment": "1.2.0-99-g1ee5c11",
|
||||
"Rev": "1ee5c115af7856a16f133e2f2d3d9f91895c2ddb"
|
||||
"Comment": "1.2.0-100-g6d6f8d3",
|
||||
"Rev": "6d6f8d3cc162bfcb60379888e2f37d73ff6a6253"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/minio-io/donut",
|
||||
|
||||
+5
-2
@@ -3,12 +3,13 @@ package cli
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"io/ioutil"
|
||||
"text/tabwriter"
|
||||
"text/template"
|
||||
"time"
|
||||
)
|
||||
|
||||
// App is the main structure of a cli application. It is recomended that
|
||||
@@ -44,6 +45,8 @@ type App struct {
|
||||
CommandNotFound func(context *Context, command string)
|
||||
// Compilation date
|
||||
Compiled time.Time
|
||||
// ExtraInfo pass additional info as a key value map
|
||||
ExtraInfo map[string]string
|
||||
// List of all authors who contributed
|
||||
Authors []Author
|
||||
// Name of Author (Note: Use App.Authors, this is deprecated)
|
||||
|
||||
+6
-3
@@ -14,9 +14,12 @@ USAGE:
|
||||
VERSION:
|
||||
{{.Version}}
|
||||
|
||||
AUTHOR(S):
|
||||
{{range .Authors}}{{ . }} {{end}}
|
||||
|
||||
BUILD:
|
||||
{{.Compiled}}
|
||||
{{range $key, $value := .ExtraInfo}}
|
||||
{{ $key }}:
|
||||
{{ $value }}
|
||||
{{ end }}
|
||||
COMMANDS:
|
||||
{{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}}
|
||||
{{end}}{{if .Flags}}
|
||||
|
||||
@@ -10,10 +10,9 @@ cat > $CONST_FILE <<EOF
|
||||
package main
|
||||
|
||||
const (
|
||||
gitCommitHash = "__GIT_COMMIT_HASH__"
|
||||
mcGitCommitHash = "__GIT_COMMIT_HASH__"
|
||||
)
|
||||
EOF
|
||||
|
||||
commit_id=$(git log --format="%H" -n 1)
|
||||
sed -i "s/__GIT_COMMIT_HASH__/$commit_id/" $CONST_FILE
|
||||
|
||||
|
||||
@@ -17,10 +17,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/user"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
||||
"github.com/cheggaaa/pb"
|
||||
"github.com/minio-io/cli"
|
||||
)
|
||||
|
||||
@@ -47,10 +51,36 @@ func init() {
|
||||
|
||||
}
|
||||
|
||||
// Tries to get os/arch/platform specific information
|
||||
// Returns a map of current os/arch/platform/memstats
|
||||
func getSystemData() map[string]string {
|
||||
host, err := os.Hostname()
|
||||
if err != nil {
|
||||
host = ""
|
||||
}
|
||||
memstats := &runtime.MemStats{}
|
||||
runtime.ReadMemStats(memstats)
|
||||
mem := fmt.Sprintf("Used: %s | Allocated: %s | Used-Heap: %s | Allocated-Heap: %s",
|
||||
pb.FormatBytes(int64(memstats.Alloc)),
|
||||
pb.FormatBytes(int64(memstats.TotalAlloc)),
|
||||
pb.FormatBytes(int64(memstats.HeapAlloc)),
|
||||
pb.FormatBytes(int64(memstats.HeapSys)))
|
||||
platform := fmt.Sprintf("Host: %s | OS: %s | Arch: %s",
|
||||
host,
|
||||
runtime.GOOS,
|
||||
runtime.GOARCH)
|
||||
goruntime := fmt.Sprintf("Version: %s | CPUs: %s", runtime.Version(), strconv.Itoa(runtime.NumCPU()))
|
||||
return map[string]string{
|
||||
"PLATFORM": platform,
|
||||
"RUNTIME": goruntime,
|
||||
"MEM": mem,
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := cli.NewApp()
|
||||
app.Usage = "Minio Client for S3 Compatible Object Storage"
|
||||
app.Version = gitCommitHash
|
||||
app.Version = mcGitCommitHash
|
||||
app.Commands = options
|
||||
app.Flags = flags
|
||||
app.Author = "Minio.io"
|
||||
@@ -58,6 +88,9 @@ func main() {
|
||||
app.Before = func(c *cli.Context) error {
|
||||
globalQuietFlag = c.GlobalBool("quiet")
|
||||
globalDebugFlag = c.GlobalBool("debug")
|
||||
if globalDebugFlag {
|
||||
app.ExtraInfo = getSystemData()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
app.Run(os.Args)
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// This package contains all s3 client specific global variables and constants
|
||||
// Package s3 contains all client specific global variables and constants
|
||||
package s3
|
||||
|
||||
const (
|
||||
|
||||
Reference in New Issue
Block a user