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. 19
      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` 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.

2
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
}

6
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"]

5
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 {

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:
-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.

19
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
}

Loading…
Cancel
Save