From ba330c91c99fc1e5b2fedec6cc5e0a1100e14abe Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 23 May 2013 08:32:26 -0400 Subject: [PATCH] add feature auto-enable flags in configuration file. --- README.md | 1 - build.go | 2 +- conf/gpm.toml | 6 +++++- gpm.go | 5 +++++ i18n/zh-CN/usage_build.txt | 38 +++----------------------------------- install.go | 19 ++++++++++++------- 6 files changed, 26 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index f6527f4d6..af21e78e9 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,6 @@ This application still in experiment, any change could happen, but it doesn't af - Command `install` add flag `-pc` which only downloads source files(including LICENSE and README). - Command `install` and `remove` and `update` backup data(up to 100 records) before executing. - Command `rollback` is for rolling back to certain operation. -- Add configure option for auto-enable feature, like always using `-p` for downloading. - Command `install` add flag `-all` for re-installing everything in GOPATH, usually use this after upgrading Go version. - Command `clean` is for cleaning empty directories. - Keep file modify time for packages from github.com. diff --git a/build.go b/build.go index 653b691f2..443ba790a 100644 --- a/build.go +++ b/build.go @@ -36,7 +36,7 @@ func printBuildPrompt(flag string) { func runBuild(cmd *Command, args []string) { // Check flags. - num := checkFlags(cmd.Flags, args, printBuildPrompt) + num := checkFlags(cmd.Flags, config.AutoEnable.Build, args, printBuildPrompt) if num == -1 { return } diff --git a/conf/gpm.toml b/conf/gpm.toml index 391a4a1fa..11d9fcb84 100644 --- a/conf/gpm.toml +++ b/conf/gpm.toml @@ -1,7 +1,7 @@ # This is a configuration file for gpm with toml format. title = "gpm(Go Package Manager)" -version = "v0.1.5 Build 0523" +version = "v0.1.6 Build 0523" user_language = "en-US" #user_language = "zh-CN" @@ -9,3 +9,7 @@ user_language = "en-US" username = "" password = "" github_access_token = "" + +[auto_enable] +build = ["v", "r"] +install = ["p"] \ No newline at end of file diff --git a/gpm.go b/gpm.go index 03c1ab14e..2331ddd0f 100644 --- a/gpm.go +++ b/gpm.go @@ -42,6 +42,11 @@ type tomlConfig struct { Title, Version string Lang string `toml:"user_language"` Account account + AutoEnable flagEnable `toml:"auto_enable"` +} + +type flagEnable struct { + Build, Install []string } type account struct { diff --git a/i18n/zh-CN/usage_build.txt b/i18n/zh-CN/usage_build.txt index 5e9e1f287..65f922f56 100644 --- a/i18n/zh-CN/usage_build.txt +++ b/i18n/zh-CN/usage_build.txt @@ -15,43 +15,10 @@ name is the base name of the containing directory. The build flags are shared by the build and test commands: - -a - force rebuilding of packages that are already up-to-date. - -n - print the commands but do not run them. - -p n - the number of builds that can be run in parallel. - The default is the number of CPUs available. - -race - enable data race detection. - Supported only on linux/amd64, darwin/amd64 and windows/amd64. -v print the names of packages as they are compiled. - -work - print the name of the temporary work directory and - do not delete it when exiting. - -x - print the commands. - - -ccflags 'arg list' - arguments to pass on each 5c, 6c, or 8c compiler invocation. - -compiler name - name of compiler to use, as in runtime.Compiler (gccgo or gc). - -gccgoflags 'arg list' - arguments to pass on each gccgo compiler/linker invocation. - -gcflags 'arg list' - arguments to pass on each 5g, 6g, or 8g compiler invocation. - -installsuffix suffix - a suffix to use in the name of the package installation directory, - in order to keep output separate from default builds. - If using the -race flag, the install suffix is automatically set to race - or, if set explicitly, has _race appended to it. - -ldflags 'flag list' - arguments to pass on each 5l, 6l, or 8l linker invocation. - -tags 'tag list' - a list of build tags to consider satisfied during the build. - See the documentation for the go/build package for - more information about build tags. + -r + run program after built. The list flags accept a space-separated list of strings. To embed spaces in an element in the list, surround it with either single or double quotes. @@ -59,3 +26,4 @@ in an element in the list, surround it with either single or double quotes. For more about specifying packages, see 'go help packages'. See also: gpm install. + diff --git a/install.go b/install.go index 6c6df4e48..27e4f9c23 100644 --- a/install.go +++ b/install.go @@ -56,7 +56,12 @@ func printInstallPrompt(flag string) { } // checkFlags checks if the flag exists with correct format. -func checkFlags(flags map[string]bool, args []string, print func(string)) int { +func checkFlags(flags map[string]bool, enable []string, args []string, print func(string)) int { + // Check auto-enable. + for _, v := range enable { + flags["-"+v] = true + } + num := 0 // Number of valid flags, use to cut out. for i, f := range args { // Check flag prefix '-'. @@ -66,11 +71,11 @@ func checkFlags(flags map[string]bool, args []string, print func(string)) int { } // Check if it a valid flag. - /* Here we use ok pattern to check it because - this way can avoid same flag appears multiple times.*/ - if _, ok := flags[f]; ok { - flags[f] = true - print(f) + if v, ok := flags[f]; ok { + flags[f] = !v + if v { + print(f) + } } else { fmt.Printf(fmt.Sprintf("%s\n", promptMsg["UnknownFlag"]), f) return -1 @@ -96,7 +101,7 @@ func checkVCSTool() { func runInstall(cmd *Command, args []string) { // Check flags. - num := checkFlags(cmd.Flags, args, printInstallPrompt) + num := checkFlags(cmd.Flags, config.AutoEnable.Install, args, printInstallPrompt) if num == -1 { return }