diff --git a/cmd/build.go b/cmd/build.go index d275f86e9..b6fbf8063 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -36,6 +36,8 @@ gopm build `, } func runBuild(ctx *cli.Context) { + log.PureMode = ctx.GlobalBool("ide") + if !ctx.Bool("remote") { // Get GOPATH. installGopath = com.GetGOPATHs()[0] diff --git a/cmd/gen.go b/cmd/gen.go index 0b01cccc7..d6f1ad0ae 100644 --- a/cmd/gen.go +++ b/cmd/gen.go @@ -41,6 +41,8 @@ Make sure you run this command in the root path of a go project.`, // scan a directory and gen a gopm file func runGen(ctx *cli.Context) { + log.PureMode = ctx.GlobalBool("ide") + if !com.IsExist(".gopmfile") { os.Create(".gopmfile") } diff --git a/cmd/get.go b/cmd/get.go index 8d88fbcb9..455138a47 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -68,6 +68,8 @@ func init() { } func runGet(ctx *cli.Context) { + log.PureMode = ctx.GlobalBool("ide") + // Check conflicts. if ctx.Bool("gopath") && ctx.Bool("remote") { log.Error("get", "Command options have conflicts") diff --git a/cmd/install.go b/cmd/install.go index 35491e581..61474bda5 100644 --- a/cmd/install.go +++ b/cmd/install.go @@ -42,6 +42,8 @@ If no argument is supplied, then gopmfile must be present`, } func runInstall(ctx *cli.Context) { + log.PureMode = ctx.GlobalBool("ide") + var target string switch len(ctx.Args()) { diff --git a/cmd/run.go b/cmd/run.go index bc2c775f5..4abf9dde0 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -32,6 +32,8 @@ gopm run `, } func runRun(ctx *cli.Context) { + log.PureMode = ctx.GlobalBool("ide") + if !ctx.Bool("remote") { // Get GOPATH. installGopath = com.GetGOPATHs()[0] diff --git a/gopm.go b/gopm.go index 49112581e..77e337c38 100644 --- a/gopm.go +++ b/gopm.go @@ -29,7 +29,7 @@ import ( // Test that go1.1 tag above is included in builds. main.go refers to this definition. const go11tag = true -const APP_VER = "0.5.7.1205.4" +const APP_VER = "0.5.7.1205.5" // //cmd.CmdSearch, // cmdClean, @@ -61,5 +61,6 @@ func main() { //cmd.CmdUpdate, //cmd.CmdTest, } + app.Flags = append(app.Flags, cli.BoolFlag{"ide, i", "IDE mode"}) app.Run(os.Args) } diff --git a/log/log.go b/log/log.go index 2b1f1c9f0..0cf9d3932 100644 --- a/log/log.go +++ b/log/log.go @@ -25,6 +25,10 @@ import ( ) func Error(hl, msg string) { + if PureMode { + errorP(hl, msg) + } + if len(hl) > 0 { hl = " " + brush.Red(hl).String() } @@ -32,26 +36,50 @@ func Error(hl, msg string) { } func Fatal(hl, msg string) { + if PureMode { + fatal(hl, msg) + } + Error(hl, msg) os.Exit(2) } func Warn(format string, args ...interface{}) { + if PureMode { + warn(format, args...) + return + } + fmt.Printf("gopm %s %s\n", brush.Purple("WARN"), fmt.Sprintf(format, args...)) } func Log(format string, args ...interface{}) { + if PureMode { + log(format, args...) + return + } + fmt.Printf("gopm %s %s\n", brush.White("INFO"), fmt.Sprintf(format, args...)) } func Trace(format string, args ...interface{}) { + if PureMode { + trace(format, args...) + return + } + fmt.Printf("gopm %s %s\n", brush.Blue("TRAC"), fmt.Sprintf(format, args...)) } func Success(title, hl, msg string) { + if PureMode { + success(title, hl, msg) + return + } + if len(hl) > 0 { hl = " " + brush.Green(hl).String() } @@ -59,6 +87,11 @@ func Success(title, hl, msg string) { } func Message(hl, msg string) { + if PureMode { + message(hl, msg) + return + } + if len(hl) > 0 { hl = " " + brush.Yellow(hl).String() } @@ -66,6 +99,10 @@ func Message(hl, msg string) { } func Help(format string, args ...interface{}) { + if PureMode { + help(format, atgs...) + } + fmt.Printf("gopm %s %s\n", brush.Cyan("HELP"), fmt.Sprintf(format, args...)) os.Exit(2) diff --git a/log/logP.go b/log/logP.go new file mode 100644 index 000000000..61b88fe16 --- /dev/null +++ b/log/logP.go @@ -0,0 +1,65 @@ +// Copyright 2013 gopm authors. +// +// 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 log + +import ( + "fmt" + "os" +) + +var PureMode = false + +func errorP(hl, msg string) { + if len(hl) > 0 { + hl = " " + hl + } + fmt.Printf("gopm ERR!%s %s\n", hl, msg) +} + +func fatal(hl, msg string) { + Error(hl, msg) + os.Exit(2) +} + +func warn(format string, args ...interface{}) { + fmt.Printf("gopm WARN %s\n", fmt.Sprintf(format, args...)) +} + +func log(format string, args ...interface{}) { + fmt.Printf("gopm INFO %s\n", fmt.Sprintf(format, args...)) +} + +func trace(format string, args ...interface{}) { + fmt.Printf("gopm TRAC %s\n", fmt.Sprintf(format, args...)) +} + +func success(title, hl, msg string) { + if len(hl) > 0 { + hl = " " + hl + } + fmt.Printf("gopm %s%s %s\n", title, hl, msg) +} + +func message(hl, msg string) { + if len(hl) > 0 { + hl = " " + hl + } + fmt.Printf("gopm MSG!%s %s\n", hl, msg) +} + +func help(format string, args ...interface{}) { + fmt.Printf("gopm HELP %s\n", fmt.Sprintf(format, args...)) + os.Exit(2) +} diff --git a/log/log_windows.go b/log/log_windows.go index 6d8196d7f..661d5e8d2 100644 --- a/log/log_windows.go +++ b/log/log_windows.go @@ -15,50 +15,34 @@ // Package log provides npm-like style log output. package log -import ( - "fmt" - "os" -) - func Error(hl, msg string) { - if len(hl) > 0 { - hl = " " + hl - } - fmt.Printf("gopm ERR!%s %s\n", hl, msg) + errorP(hl, msg) } func Fatal(hl, msg string) { - Error(hl, msg) - os.Exit(2) + fatal(hl, msg) } func Warn(format string, args ...interface{}) { - fmt.Printf("gopm WARN %s\n", fmt.Sprintf(format, args...)) + warn(format, args...) } func Log(format string, args ...interface{}) { - fmt.Printf("gopm INFO %s\n", fmt.Sprintf(format, args...)) + log(format, args...) } func Trace(format string, args ...interface{}) { - fmt.Printf("gopm TRAC %s\n", fmt.Sprintf(format, args...)) + trace(format, args...) } func Success(title, hl, msg string) { - if len(hl) > 0 { - hl = " " + hl - } - fmt.Printf("gopm %s%s %s\n", title, hl, msg) + success(title, hl, msg) } func Message(hl, msg string) { - if len(hl) > 0 { - hl = " " + hl - } - fmt.Printf("gopm MSG!%s %s\n", hl, msg) + message(hl, msg) } func Help(format string, args ...interface{}) { - fmt.Printf("gopm HELP %s\n", fmt.Sprintf(format, args...)) - os.Exit(2) + help(format, args...) }