From e6fc1004ad7950692588ff3de916d5efc33c29d8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 18 Feb 2014 08:55:44 -0500 Subject: [PATCH 1/2] Bug fix --- cmd/get.go | 3 +++ doc/utils.go | 13 +++++++------ gopm.go | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/get.go b/cmd/get.go index b50bbcab5..7742d2d2d 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -191,6 +191,9 @@ func copyToGopath(srcPath, destPath string) { // if the commit is empty string, then it downloads all dependencies, // otherwise, it only downloada package with specific commit only. func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { + for _, node := range nodes { + fmt.Println(node) + } // Check all packages, they may be raw packages path. for _, n := range nodes { // Check if local reference diff --git a/doc/utils.go b/doc/utils.go index 7cc054e83..dab7e4b57 100644 --- a/doc/utils.go +++ b/doc/utils.go @@ -59,12 +59,13 @@ func GetImports(absPath, importPath string, example bool) []string { fis := GetDirsInfo(absPath) absPath += "/" - dirs := make([]string, 0) - for _, fi := range fis { - if fi.IsDir() && !strings.Contains(fi.Name(), VENDOR) { - dirs = append(dirs, absPath+fi.Name()) - } - } + // Load too much, skip for now. + // dirs := make([]string, 0) + // for _, fi := range fis { + // if fi.IsDir() && !strings.Contains(fi.Name(), VENDOR) { + // dirs = append(dirs, absPath+fi.Name()) + // } + // } imports := make([]string, 0, len(pkg.Imports)) for _, p := range pkg.Imports { diff --git a/gopm.go b/gopm.go index bb45dc884..8d678d733 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.6.2.0125" +const APP_VER = "0.6.2.0218" // //cmd.CmdSearch, // cmdClean, From 59c67597a5d2e4736c8e024583696545c11ae7d2 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 20 Feb 2014 12:11:58 -0500 Subject: [PATCH 2/2] Add command config, able to config github client_id and client_secret --- README.md | 6 ++---- cmd/config.go | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ doc/conf.go | 15 +++++++++++++ doc/github.go | 7 ++++++ doc/utils.go | 8 +++---- gopm.go | 3 ++- 6 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 cmd/config.go diff --git a/README.md b/README.md index 6ad52bb65..918477308 100644 --- a/README.md +++ b/README.md @@ -14,14 +14,11 @@ Please see **[Documentation](https://github.com/gpmgo/docs)** before you ever st # Commands ``` -NAME: - gopm - Go Package Manager - USAGE: gopm [global options] command [command options] [arguments...] VERSION: - 0.6.2.0125 + 0.6.3.0220 COMMANDS: get fetch remote package(s) and dependencies to local repository @@ -31,6 +28,7 @@ COMMANDS: build link dependencies and go build install link dependencies and go install update check and update gopm resources including itself + config configurate gopm global settings help, h Shows a list of commands or help for one command GLOBAL OPTIONS: diff --git a/cmd/config.go b/cmd/config.go new file mode 100644 index 000000000..28b0f6412 --- /dev/null +++ b/cmd/config.go @@ -0,0 +1,60 @@ +// Copyright 2013-2014 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 cmd + +import ( + "path" + + "github.com/Unknwon/goconfig" + "github.com/codegangsta/cli" + + "github.com/gpmgo/gopm/doc" + "github.com/gpmgo/gopm/log" +) + +var CmdConfig = cli.Command{ + Name: "config", + Usage: "configurate gopm global settings", + Description: `Command config configurates gopm global settings + +gopm config github [client_id] [client_secret] +`, + Action: runConfig, + Flags: []cli.Flag{ + cli.BoolFlag{"verbose, v", "show process details"}, + }, +} + +func runConfig(ctx *cli.Context) { + setup(ctx) + + if len(ctx.Args()) == 0 { + log.Error("config", "Cannot start command:") + log.Fatal("", "\tNo section specified") + } + + switch ctx.Args()[0] { + case "github": + if len(ctx.Args()) < 3 { + log.Error("config", "Cannot config section 'github'") + log.Fatal("", "\tNot enough arguments for client_id and client_secret") + } + doc.Cfg.SetValue("github", "client_id", ctx.Args()[1]) + doc.Cfg.SetValue("github", "client_secret", ctx.Args()[2]) + goconfig.SaveConfigFile(doc.Cfg, path.Join(doc.HomeDir, doc.GOPM_CONFIG_FILE)) + } + + log.Success("SUCC", "config", "Command executed successfully!") +} diff --git a/doc/conf.go b/doc/conf.go index 9f28f0c85..8d46d17cf 100644 --- a/doc/conf.go +++ b/doc/conf.go @@ -28,6 +28,7 @@ import ( const ( GOPM_FILE_NAME = ".gopmfile" + GOPM_CONFIG_FILE = "data/gopm.ini" PKG_NAME_LIST_PATH = "data/pkgname.list" VER_PATH = "data/VERSION.json" RawHomeDir = "~/.gopm" @@ -37,6 +38,7 @@ var ( HomeDir = "~/.gopm" LocalNodesFile = "/data/localnodes.list" LocalNodes *goconfig.ConfigFile + Cfg *goconfig.ConfigFile ) func init() { @@ -48,6 +50,19 @@ func init() { HomeDir = strings.Replace(RawHomeDir, "~", hd, -1) + cfgPath := path.Join(HomeDir, GOPM_CONFIG_FILE) + if !com.IsExist(cfgPath) { + if _, err = os.Create(cfgPath); err != nil { + log.Error("", "Fail to create gopm config file") + log.Fatal("", err.Error()) + } + } + Cfg, err = goconfig.LoadConfigFile(cfgPath) + if _, err = os.Create(cfgPath); err != nil { + log.Error("", "Fail to load gopm config file") + log.Fatal("", err.Error()) + } + LoadLocalNodes() LoadPkgNameList(path.Join(HomeDir, PKG_NAME_LIST_PATH)) } diff --git a/doc/github.go b/doc/github.go index c7885cbd3..ffd7a77ea 100644 --- a/doc/github.go +++ b/doc/github.go @@ -35,8 +35,15 @@ var ( githubPattern = regexp.MustCompile(`^github\.com/(?P[a-z0-9A-Z_.\-]+)/(?P[a-z0-9A-Z_.\-]+)(?P/[a-z0-9A-Z_.\-/]*)?$`) ) +func GetGithubCredentials() string { + return "client_id=" + Cfg.MustValue("github", "client_id") + + "&client_secret=" + Cfg.MustValue("github", "client_secret") +} + // getGithubDoc downloads tarball from github.com. func getGithubDoc(client *http.Client, match map[string]string, installRepoPath string, nod *Node, ctx *cli.Context) ([]string, error) { + match["cred"] = GetGithubCredentials() + // Check downlaod type. switch nod.Type { case BRANCH: diff --git a/doc/utils.go b/doc/utils.go index dab7e4b57..327a29dea 100644 --- a/doc/utils.go +++ b/doc/utils.go @@ -56,7 +56,7 @@ func GetImports(absPath, importPath string, example bool) []string { } } - fis := GetDirsInfo(absPath) + //fis := GetDirsInfo(absPath) absPath += "/" // Load too much, skip for now. @@ -73,9 +73,9 @@ func GetImports(absPath, importPath string, example bool) []string { imports = append(imports, p) } } - if len(dirs) > 0 { - imports = append(imports, GetAllImports(dirs, importPath, example)...) - } + // if len(dirs) > 0 { + // imports = append(imports, GetAllImports(dirs, importPath, example)...) + // } return imports } diff --git a/gopm.go b/gopm.go index 8d678d733..a1b8a7fcf 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.6.2.0218" +const APP_VER = "0.6.3.0220" // //cmd.CmdSearch, // cmdClean, @@ -58,6 +58,7 @@ func main() { cmd.CmdBuild, cmd.CmdInstall, cmd.CmdUpdate, + cmd.CmdConfig, //cmd.CmdTest, } app.Flags = append(app.Flags, []cli.Flag{