Add new version command

This commit is contained in:
Harshavardhana
2015-08-13 20:50:32 -07:00
parent ff27f3a0f3
commit 192518d679
13 changed files with 133 additions and 88 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ gomake-all: build
@mkdir -p $(HOME)/.mc
release: genversion
@echo "Installing minio with new version.go:"
@echo "Installing mc with new version.go:"
@go install github.com/minio/mc
@mkdir -p $(HOME)/.mc
+3 -3
View File
@@ -27,9 +27,9 @@ import (
"net/http/httptest"
"github.com/minio/mc/internal/github.com/minio/cli"
"github.com/minio/mc/internal/github.com/minio/minio/pkg/quick"
. "github.com/minio/mc/internal/gopkg.in/check.v1"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/internal/github.com/minio/minio/pkg/quick"
)
var customConfigDir string
@@ -56,9 +56,9 @@ func (s *CmdTestSuite) SetUpSuite(c *C) {
// For windows the path is slightly different.
if runtime.GOOS == "windows" {
customConfigDir = filepath.Join(tmpDir, mcConfigWindowsDir)
customConfigDir = filepath.Join(tmpDir, globalMCConfigWindowsDir)
} else {
customConfigDir = filepath.Join(tmpDir, mcConfigDir)
customConfigDir = filepath.Join(tmpDir, globalMCConfigDir)
}
setMcConfigDir(customConfigDir)
+1 -1
View File
@@ -157,7 +157,7 @@ func getNewClient(urlStr string, auth hostConfig) (client.Client, *probe.Error)
return auth.SecretAccessKey
}()
s3Config.AppName = "Minio"
s3Config.AppVersion = getVersion()
s3Config.AppVersion = globalMCVersion
s3Config.AppComments = []string{os.Args[0], runtime.GOOS, runtime.GOARCH}
s3Config.HostURL = urlStr
s3Config.Debug = globalDebugFlag
+1 -1
View File
@@ -21,8 +21,8 @@ import (
"github.com/minio/mc/internal/github.com/minio/cli"
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/internal/github.com/minio/minio/pkg/quick"
"github.com/minio/mc/pkg/console"
)
// Configure minio client
+10 -10
View File
@@ -24,8 +24,8 @@ import (
"sync"
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/internal/github.com/minio/minio/pkg/quick"
"github.com/minio/mc/pkg/console"
)
type configV1 struct {
@@ -57,9 +57,9 @@ func getMcConfigDir() (string, *probe.Error) {
// For windows the path is slightly different
switch runtime.GOOS {
case "windows":
return filepath.Join(u.HomeDir, mcConfigWindowsDir), nil
return filepath.Join(u.HomeDir, globalMCConfigWindowsDir), nil
default:
return filepath.Join(u.HomeDir, mcConfigDir), nil
return filepath.Join(u.HomeDir, globalMCConfigDir), nil
}
}
@@ -88,7 +88,7 @@ func getMcConfigPath() (string, *probe.Error) {
if err != nil {
return "", err.Trace()
}
return filepath.Join(dir, mcConfigFile), nil
return filepath.Join(dir, globalMCConfigFile), nil
}
// mustGetMcConfigPath - similar to getMcConfigPath, ignores errors
@@ -181,10 +181,10 @@ func migrateConfigV1ToV101() {
conf = config.Data().(*configV1)
// version is the same return
if conf.Version == mcCurrentConfigVersion {
if conf.Version == globalMCCurrentConfigVersion {
return
}
conf.Version = mcCurrentConfigVersion
conf.Version = globalMCCurrentConfigVersion
localHostConfig := hostConfig{}
localHostConfig.AccessKeyID = ""
@@ -209,13 +209,13 @@ func migrateConfigV1ToV101() {
perr = newConfig.Save(mustGetMcConfigPath())
fatalIf(perr)
console.Infof("Successfully migrated %s from version: %s to version: %s\n", mustGetMcConfigPath(), mcPreviousConfigVersion, mcCurrentConfigVersion)
console.Infof("Successfully migrated %s from version: %s to version: %s\n", mustGetMcConfigPath(), globalMCPreviousConfigVersion, globalMCCurrentConfigVersion)
}
// newConfigV1() - get new config version 1.0.0
func newConfigV1() *configV1 {
conf := new(configV1)
conf.Version = mcPreviousConfigVersion
conf.Version = globalMCPreviousConfigVersion
// make sure to allocate map's otherwise Golang
// exits silently without providing any errors
conf.Hosts = make(map[string]hostConfig)
@@ -226,7 +226,7 @@ func newConfigV1() *configV1 {
// newConfigV101() - get new config version 1.0.1
func newConfigV101() *configV1 {
conf := new(configV1)
conf.Version = mcCurrentConfigVersion
conf.Version = globalMCCurrentConfigVersion
// make sure to allocate map's otherwise Golang
// exits silently without providing any errors
conf.Hosts = make(map[string]hostConfig)
@@ -253,7 +253,7 @@ func newConfigV101() *configV1 {
dlHostConfig.AccessKeyID = ""
dlHostConfig.SecretAccessKey = ""
conf.Hosts[exampleHostURL] = exampleHostConf
conf.Hosts[globalExampleHostURL] = exampleHostConf
conf.Hosts["localhost:*"] = localHostConfig
conf.Hosts["127.0.0.1:*"] = localHostConfig
conf.Hosts["s3*.amazonaws.com"] = s3HostConf
+11 -23
View File
@@ -20,6 +20,7 @@ package main
import (
"fmt"
"net/http"
"os"
"text/template"
"time"
@@ -27,37 +28,17 @@ import (
type Version struct {
Date string
Tag string
}
func writeVersion(version Version) error {
var versionTemplate = `// -------- DO NOT EDIT --------
// this is an autogenerated file
// This file is autogenerated by genversion.go during the release process.
package main
import (
"net/http"
"time"
)
// Version autogenerated
var Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}}
const Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}}
// Tag is of following format
//
// RELEASE.[WeekDay]-[Month]-[Day]-[Hour]-[Min]-[Sec]-GMT-[Year]
//
var Tag = {{if .Tag}}"{{.Tag}}"{{else}}""{{end}}
// getVersion -
func getVersion() string {
t, _ := time.Parse(time.RFC3339Nano, Version)
if t.IsZero() {
return ""
}
return t.Format(http.TimeFormat)
}
`
t := template.Must(template.New("version").Parse(versionTemplate))
versionFile, err := os.OpenFile("version.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
@@ -75,6 +56,10 @@ func getVersion() string {
func genVersion() {
t := time.Now().UTC()
date := t.Format(time.RFC3339Nano)
// Tag is of following format
//
// RELEASE.[WeekDay]-[Month]-[Day]-[Hour]-[Min]-[Sec]-GMT-[Year]
//
tag := fmt.Sprintf(
"RELEASE.%s-%s-%02d-%02d-%02d-%02d-GMT-%d",
t.Weekday().String()[0:3],
@@ -84,12 +69,15 @@ func genVersion() {
t.Minute(),
t.Second(),
t.Year())
version := Version{Date: date, Tag: tag}
fmt.Println("Release-Tag: " + tag)
fmt.Println("Release-Version: " + t.Format(http.TimeFormat))
version := Version{Date: date}
err := writeVersion(version)
if err != nil {
fmt.Print(err)
os.Exit(1)
}
fmt.Println("Successfully generated ‘version.go’")
}
func main() {
+12 -17
View File
@@ -22,32 +22,27 @@ var (
globalMimicFlag = false // Unix flag set via command line
globalJSONFlag = false // Json flag set via command line
globalDebugFlag = false // Debug flag set via command line
mcPreviousConfigVersion = "1.0.0"
mcCurrentConfigVersion = "1.0.1"
)
// mc configuration related constants.
const (
mcConfigDir = ".mc/"
mcConfigWindowsDir = "mc\\"
mcConfigFile = "config.json"
)
globalMCPreviousConfigVersion = "1.0.0"
globalMCCurrentConfigVersion = "1.0.1"
globalMCVersion = Version
// session config related constants
const (
sessionDir = "session"
)
globalMCConfigDir = ".mc/"
globalMCConfigWindowsDir = "mc\\"
globalMCConfigFile = "config.json"
// default access and secret key
const (
// session config related constants
globalSessionDir = "session"
// default access and secret key
// do not pass accesskeyid and secretaccesskey through cli
// users should manually edit them, add a stub entry
globalAccessKeyID = "YOUR-ACCESS-KEY-ID-HERE"
globalSecretAccessKey = "YOUR-SECRET-ACCESS-KEY-HERE"
)
// default host
const (
exampleHostURL = "YOUR-EXAMPLE.COM"
// default host
globalExampleHostURL = "YOUR-EXAMPLE.COM"
)
+18 -5
View File
@@ -18,10 +18,12 @@ package main
import (
"fmt"
"net/http"
"os"
"os/user"
"runtime"
"strconv"
"time"
"github.com/minio/mc/internal/github.com/minio/cli"
"github.com/minio/mc/internal/github.com/minio/pb"
@@ -69,7 +71,6 @@ func getSystemData() map[string]string {
"PLATFORM": platform,
"RUNTIME": goruntime,
"MEM": mem,
"TAG": Tag,
}
}
@@ -102,6 +103,15 @@ func registerBefore(ctx *cli.Context) error {
return nil
}
// getFormattedVersion -
func getFormattedVersion() string {
t, _ := time.Parse(time.RFC3339Nano, Version)
if t.IsZero() {
return ""
}
return t.Format(http.TimeFormat)
}
func registerApp() *cli.App {
// Register all the commands
registerCmd(lsCmd) // List contents of a bucket
@@ -115,6 +125,7 @@ func registerApp() *cli.App {
registerCmd(accessCmd) // set permissions [public, private, readonly, authenticated] for buckets and folders.
registerCmd(configCmd) // generate configuration "/home/harsha/.mc/config.json" file.
registerCmd(updateCmd) // update Check for new software updates
registerCmd(versionCmd) // print version
// register all the flags
registerFlag(configFlag) // path to config folder
@@ -126,9 +137,9 @@ func registerApp() *cli.App {
app := cli.NewApp()
app.Usage = "Minio Client for cloud storage and filesystems"
app.Version = getVersion()
// hide --version flag, version is a command
app.HideVersion = true
app.Commands = commands
app.Compiled = getVersion()
app.Flags = flags
app.Author = "Minio.io"
app.CustomAppHelpTemplate = `NAME:
@@ -144,8 +155,9 @@ GLOBAL FLAGS:
{{range .Flags}}{{.}}
{{end}}{{end}}
VERSION:
{{if .Compiled}}
{{.Compiled}}{{end}}
` + getFormattedVersion() +
`
{{range $key, $value := ExtraInfo}}
{{$key}}:
{{$value}}
@@ -163,6 +175,7 @@ func main() {
app := registerApp()
app.Before = registerBefore
app.ExtraInfo = func() map[string]string {
if globalDebugFlag {
return getSystemData()
+1 -1
View File
@@ -25,8 +25,8 @@ import (
"time"
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/internal/github.com/minio/minio/pkg/quick"
"github.com/minio/mc/pkg/console"
)
type sessionV1 struct {
+1 -1
View File
@@ -25,8 +25,8 @@ import (
"time"
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
"github.com/minio/mc/pkg/console"
"github.com/minio/mc/internal/github.com/minio/minio/pkg/quick"
"github.com/minio/mc/pkg/console"
)
// migrateSessionV1ToV2 migrates all session files from v1 to v2.
+1 -1
View File
@@ -52,7 +52,7 @@ func getSessionDir() string {
if err != nil {
// TODO: revamp error handling -ab. Do not pass errors mindlessly to upper layer for a tool like mc.
}
return filepath.Join(configDir, sessionDir)
return filepath.Join(configDir, globalSessionDir)
}
var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
+71
View File
@@ -0,0 +1,71 @@
/*
* Minio Client (C) 2014, 2015 Minio, Inc.
*
* Licensed 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 main
import (
"encoding/json"
"net/http"
"time"
"github.com/minio/mc/internal/github.com/minio/cli"
"github.com/minio/mc/internal/github.com/minio/minio/pkg/probe"
"github.com/minio/mc/pkg/console"
)
var versionCmd = cli.Command{
Name: "version",
Usage: "Print version",
Action: mainVersion,
CustomHelpTemplate: `NAME:
mc {{.Name}} - {{.Usage}}
USAGE:
mc {{.Name}} {{if .Description}}
DESCRIPTION:
{{.Description}}{{end}}{{if .Flags}}
FLAGS:
{{range .Flags}}{{.}}
{{end}}{{ end }}
EXAMPLES:
`,
}
func mainVersion(ctxx *cli.Context) {
t, _ := time.Parse(time.RFC3339Nano, Version)
if t.IsZero() {
console.Println("")
return
}
type Version struct {
Value time.Time `json:"value"`
Format string `json:"format"`
}
if globalJSONFlag {
tB, err := json.MarshalIndent(struct {
Version Version `json:"version"`
}{Version: Version{t, "RFC3339Nano"}}, "", "\t")
if err != nil {
console.Fatalln(probe.NewError(err))
}
console.Println(console.JSON(string(tB)))
return
}
console.Println(t.Format(http.TimeFormat))
}
+2 -24
View File
@@ -1,29 +1,7 @@
// -------- DO NOT EDIT --------
// this is an autogenerated file
// This file is autogenerated by genversion.go during the release process.
package main
import (
"net/http"
"time"
)
// Version autogenerated
var Version = "2015-06-24T21:56:09.753217354Z"
// Tag is of following format
//
// [STRING]-[EPOCH]
//
// STRING is release string of your choice.
// EPOCH is unix seconds since Jan 1, 1970 UTC.
var Tag = "release-1435182969"
// getVersion -
func getVersion() string {
t, _ := time.Parse(time.RFC3339Nano, Version)
if t.IsZero() {
return ""
}
return t.Format(http.TimeFormat)
}
const Version = "2015-08-14T03:23:47.250240049Z"