Browse Source

Add command config, able to config github client_id and client_secret

pull/103/head
Unknown 11 years ago
parent
commit
59c67597a5
  1. 6
      README.md
  2. 60
      cmd/config.go
  3. 15
      doc/conf.go
  4. 7
      doc/github.go
  5. 8
      doc/utils.go
  6. 3
      gopm.go

6
README.md

@ -14,14 +14,11 @@ Please see **[Documentation](https://github.com/gpmgo/docs)** before you ever st
# Commands # Commands
``` ```
NAME:
gopm - Go Package Manager
USAGE: USAGE:
gopm [global options] command [command options] [arguments...] gopm [global options] command [command options] [arguments...]
VERSION: VERSION:
0.6.2.0125 0.6.3.0220
COMMANDS: COMMANDS:
get fetch remote package(s) and dependencies to local repository get fetch remote package(s) and dependencies to local repository
@ -31,6 +28,7 @@ COMMANDS:
build link dependencies and go build build link dependencies and go build
install link dependencies and go install install link dependencies and go install
update check and update gopm resources including itself 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 help, h Shows a list of commands or help for one command
GLOBAL OPTIONS: GLOBAL OPTIONS:

60
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!")
}

15
doc/conf.go

@ -28,6 +28,7 @@ import (
const ( const (
GOPM_FILE_NAME = ".gopmfile" GOPM_FILE_NAME = ".gopmfile"
GOPM_CONFIG_FILE = "data/gopm.ini"
PKG_NAME_LIST_PATH = "data/pkgname.list" PKG_NAME_LIST_PATH = "data/pkgname.list"
VER_PATH = "data/VERSION.json" VER_PATH = "data/VERSION.json"
RawHomeDir = "~/.gopm" RawHomeDir = "~/.gopm"
@ -37,6 +38,7 @@ var (
HomeDir = "~/.gopm" HomeDir = "~/.gopm"
LocalNodesFile = "/data/localnodes.list" LocalNodesFile = "/data/localnodes.list"
LocalNodes *goconfig.ConfigFile LocalNodes *goconfig.ConfigFile
Cfg *goconfig.ConfigFile
) )
func init() { func init() {
@ -48,6 +50,19 @@ func init() {
HomeDir = strings.Replace(RawHomeDir, "~", hd, -1) 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() LoadLocalNodes()
LoadPkgNameList(path.Join(HomeDir, PKG_NAME_LIST_PATH)) LoadPkgNameList(path.Join(HomeDir, PKG_NAME_LIST_PATH))
} }

7
doc/github.go

@ -35,8 +35,15 @@ var (
githubPattern = regexp.MustCompile(`^github\.com/(?P<owner>[a-z0-9A-Z_.\-]+)/(?P<repo>[a-z0-9A-Z_.\-]+)(?P<dir>/[a-z0-9A-Z_.\-/]*)?$`) githubPattern = regexp.MustCompile(`^github\.com/(?P<owner>[a-z0-9A-Z_.\-]+)/(?P<repo>[a-z0-9A-Z_.\-]+)(?P<dir>/[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. // getGithubDoc downloads tarball from github.com.
func getGithubDoc(client *http.Client, match map[string]string, installRepoPath string, nod *Node, ctx *cli.Context) ([]string, error) { func getGithubDoc(client *http.Client, match map[string]string, installRepoPath string, nod *Node, ctx *cli.Context) ([]string, error) {
match["cred"] = GetGithubCredentials()
// Check downlaod type. // Check downlaod type.
switch nod.Type { switch nod.Type {
case BRANCH: case BRANCH:

8
doc/utils.go

@ -56,7 +56,7 @@ func GetImports(absPath, importPath string, example bool) []string {
} }
} }
fis := GetDirsInfo(absPath) //fis := GetDirsInfo(absPath)
absPath += "/" absPath += "/"
// Load too much, skip for now. // Load too much, skip for now.
@ -73,9 +73,9 @@ func GetImports(absPath, importPath string, example bool) []string {
imports = append(imports, p) imports = append(imports, p)
} }
} }
if len(dirs) > 0 { // if len(dirs) > 0 {
imports = append(imports, GetAllImports(dirs, importPath, example)...) // imports = append(imports, GetAllImports(dirs, importPath, example)...)
} // }
return imports return imports
} }

3
gopm.go

@ -29,7 +29,7 @@ import (
// Test that go1.1 tag above is included in builds. main.go refers to this definition. // Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true const go11tag = true
const APP_VER = "0.6.2.0218" const APP_VER = "0.6.3.0220"
// //cmd.CmdSearch, // //cmd.CmdSearch,
// cmdClean, // cmdClean,
@ -58,6 +58,7 @@ func main() {
cmd.CmdBuild, cmd.CmdBuild,
cmd.CmdInstall, cmd.CmdInstall,
cmd.CmdUpdate, cmd.CmdUpdate,
cmd.CmdConfig,
//cmd.CmdTest, //cmd.CmdTest,
} }
app.Flags = append(app.Flags, []cli.Flag{ app.Flags = append(app.Flags, []cli.Flag{

Loading…
Cancel
Save