// +build ignore /* * 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 ( "bytes" "fmt" "os" "os/exec" "text/template" "time" "github.com/minio/cli" "github.com/minio/mc/pkg/console" ) type Version struct { Date string } func writeVersion(version Version) error { var versionTemplate = `// -------- DO NOT EDIT -------- // this is an autogenerated file package main import "time" // Version autogenerated var Version = {{if .Date}}"{{.Date}}"{{else}}""{{end}} // getVersion - func getVersion() string { t, _ := time.Parse(time.RFC3339Nano, Version) if t.IsZero() { return "" } return t.Format(time.RFC1123) } ` t := template.Must(template.New("version").Parse(versionTemplate)) versionFile, err := os.OpenFile("version.go", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { return err } defer versionFile.Close() err = t.Execute(versionFile, version) if err != nil { return err } return nil } func runGoBuild(ctx *cli.Context) { if ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "build", 1) // last argument is exit code } mcBuild := exec.Command("godep", "go", "build", "-a", "./...") mcTest := exec.Command("godep", "go", "test", "-race", "./...") mcInstall := exec.Command("godep", "go", "install", "-a", "github.com/minio/mc") mcBuildErr := mcBuild.Run() if mcBuildErr != nil { console.Fatalln(mcBuildErr) } var mcTestOut bytes.Buffer mcTest.Stdout = &mcTestOut mcTestErr := mcTest.Run() if mcTestErr != nil { console.Fatalln(mcTestErr) } fmt.Print(mcTestOut.String()) mcInstallErr := mcInstall.Run() if mcInstallErr != nil { console.Fatalln(mcInstallErr) } } func runReleaseCmd(ctx *cli.Context) { if ctx.Args().First() == "help" { cli.ShowCommandHelpAndExit(ctx, "release", 1) // last argument is exit code } version := Version{Date: time.Now().UTC().Format(time.RFC3339Nano)} err := writeVersion(version) if err != nil { console.Fatalln(err) } } func main() { app := cli.NewApp() app.Usage = "Minio Client for object storage and filesystems" app.Commands = []cli.Command{ { Name: "release", Action: runReleaseCmd, }, { Name: "install", Action: runGoBuild, }, } app.Author = "Minio.io" app.RunAndExitOnError() }