Browse Source

add feature auto-enable flags in configuration file.

pull/103/head
Unknown 12 years ago
parent
commit
ba330c91c9
  1. 1
      README.md
  2. 2
      build.go
  3. 6
      conf/gpm.toml
  4. 5
      gpm.go
  5. 38
      i18n/zh-CN/usage_build.txt
  6. 17
      install.go

1
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` 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 `install` and `remove` and `update` backup data(up to 100 records) before executing.
- Command `rollback` is for rolling back to certain operation. - 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 `install` add flag `-all` for re-installing everything in GOPATH, usually use this after upgrading Go version.
- Command `clean` is for cleaning empty directories. - Command `clean` is for cleaning empty directories.
- Keep file modify time for packages from github.com. - Keep file modify time for packages from github.com.

2
build.go

@ -36,7 +36,7 @@ func printBuildPrompt(flag string) {
func runBuild(cmd *Command, args []string) { func runBuild(cmd *Command, args []string) {
// Check flags. // Check flags.
num := checkFlags(cmd.Flags, args, printBuildPrompt) num := checkFlags(cmd.Flags, config.AutoEnable.Build, args, printBuildPrompt)
if num == -1 { if num == -1 {
return return
} }

6
conf/gpm.toml

@ -1,7 +1,7 @@
# This is a configuration file for gpm with toml format. # This is a configuration file for gpm with toml format.
title = "gpm(Go Package Manager)" title = "gpm(Go Package Manager)"
version = "v0.1.5 Build 0523" version = "v0.1.6 Build 0523"
user_language = "en-US" user_language = "en-US"
#user_language = "zh-CN" #user_language = "zh-CN"
@ -9,3 +9,7 @@ user_language = "en-US"
username = "" username = ""
password = "" password = ""
github_access_token = "" github_access_token = ""
[auto_enable]
build = ["v", "r"]
install = ["p"]

5
gpm.go

@ -42,6 +42,11 @@ type tomlConfig struct {
Title, Version string Title, Version string
Lang string `toml:"user_language"` Lang string `toml:"user_language"`
Account account Account account
AutoEnable flagEnable `toml:"auto_enable"`
}
type flagEnable struct {
Build, Install []string
} }
type account struct { type account struct {

38
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: 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 -v
print the names of packages as they are compiled. print the names of packages as they are compiled.
-work -r
print the name of the temporary work directory and run program after built.
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.
The list flags accept a space-separated list of strings. To embed spaces 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. 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'. For more about specifying packages, see 'go help packages'.
See also: gpm install. See also: gpm install.

17
install.go

@ -56,7 +56,12 @@ func printInstallPrompt(flag string) {
} }
// checkFlags checks if the flag exists with correct format. // 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. num := 0 // Number of valid flags, use to cut out.
for i, f := range args { for i, f := range args {
// Check flag prefix '-'. // 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. // Check if it a valid flag.
/* Here we use ok pattern to check it because if v, ok := flags[f]; ok {
this way can avoid same flag appears multiple times.*/ flags[f] = !v
if _, ok := flags[f]; ok { if v {
flags[f] = true
print(f) print(f)
}
} else { } else {
fmt.Printf(fmt.Sprintf("%s\n", promptMsg["UnknownFlag"]), f) fmt.Printf(fmt.Sprintf("%s\n", promptMsg["UnknownFlag"]), f)
return -1 return -1
@ -96,7 +101,7 @@ func checkVCSTool() {
func runInstall(cmd *Command, args []string) { func runInstall(cmd *Command, args []string) {
// Check flags. // Check flags.
num := checkFlags(cmd.Flags, args, printInstallPrompt) num := checkFlags(cmd.Flags, config.AutoEnable.Install, args, printInstallPrompt)
if num == -1 { if num == -1 {
return return
} }

Loading…
Cancel
Save