Browse Source

add flag -e for command install

pull/103/head
Unknown 12 years ago
parent
commit
cb5853dbea
  1. 1
      README.md
  2. 2
      conf/gpm.toml
  3. 7
      doc/github.go
  4. 22
      gpm.go
  5. 2
      i18n/en-US/usage_install.txt
  6. 24
      install.go

1
README.md

@ -8,6 +8,7 @@ gpm(Go Package Manager) is a Go package manage tool for search, install, update
## Todo
- Command `install` add support for downloading code from code.google.com, launchpad.net, bitbucket.org; hopefully, support user sources for downloading tarballs.
- Command `install` installs all packages after downloaded.
- After downloaded all packages in bundles or snapshots, need to check if all dependencies have been downloaded as well.
- Develop user source API server template application to support user sources in bundles.
- Add bundle and snapshot parser code for downloading by bundle or snapshot id.

2
conf/gpm.toml

@ -2,4 +2,6 @@
title = "gpm(Go Package Manager)"
version = "v0.0.3 Build 0519"
username = ""
password = ""
user_language = "en-US"

7
doc/github.go

@ -28,7 +28,7 @@ func SetGithubCredentials(id, secret string) {
}
// GetGithubDoc downloads tarball from github.com.
func GetGithubDoc(client *http.Client, match map[string]string, commit string) (*Package, []string, error) {
func GetGithubDoc(client *http.Client, match map[string]string, commit string, isDownloadEx bool) (*Package, []string, error) {
SetGithubCredentials("1862bcb265171f37f36c", "308d71ab53ccd858416cfceaed52d5d5b7d53c5f")
match["cred"] = githubCred
@ -143,6 +143,11 @@ func GetGithubDoc(client *http.Client, match map[string]string, commit string) (
// Check if need to check imports.
if isCheckImport {
for _, d := range dirs {
// Check if current directory is example.
if !isDownloadEx && strings.Contains(d, "example") {
continue
}
dir, err := os.Open(d)
if err != nil {
return nil, nil, err

22
gpm.go

@ -29,6 +29,7 @@ var (
type tomlConfig struct {
Title, Version string
Username, Password string
Lang string `toml:"user_language"`
}
@ -138,20 +139,35 @@ func loadUsage(lang, appPath string) bool {
return true
}
func main() {
// We don't use init() to initialize
// bacause we need to get execute path in runtime.
func initialize() bool {
// Get application execute path.
if !getAppPath() {
return
return false
}
// Load configuration.
if _, err := toml.DecodeFile(appPath+"conf/gpm.toml", &config); err != nil {
fmt.Println(err)
return
return false
}
// Load usages by language.
if !loadUsage(config.Lang, appPath) {
return false
}
// Create bundle and snapshot directories.
os.MkdirAll(appPath+"bundles", os.ModePerm)
os.MkdirAll(appPath+"snapshots", os.ModePerm)
return true
}
func main() {
// Initialization.
if !initialize() {
return
}

2
i18n/en-US/usage_install.txt

@ -13,6 +13,8 @@ The install flags are:
download without installing packages.
-u
force to update pakcages.
-e
download dependencies for examples.
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.

24
install.go

@ -30,7 +30,8 @@ func init() {
cmdInstall.Flags = map[string]bool{
"-p": false,
"-d": false,
"-u": false,
"-u": false, // Flag for 'go get'.
"-e": false,
}
}
@ -42,6 +43,8 @@ func printPrompt(flag string) {
fmt.Printf("You enabled pure download.\n")
case "-d":
fmt.Printf("You enabled download without installing.\n")
case "-e":
fmt.Printf("You enabled download dependencies in exmaple.\n")
}
}
@ -103,7 +106,7 @@ func runInstall(cmd *Command, args []string) {
// Download packages.
commits := make([]string, len(args))
downloadPackages(args, commits)
downloadPackages(args, commits, cmdInstall.Flags["-e"])
if !cmdInstall.Flags["d"] && cmdInstall.Flags["-p"] {
// Install packages all together.
@ -116,7 +119,7 @@ func runInstall(cmd *Command, args []string) {
// downloadPackages downloads packages with certain commit,
// if the commit is empty string, then it downloads all dependencies,
// otherwise, it only downloada package with specific commit only.
func downloadPackages(pkgs, commits []string) {
func downloadPackages(pkgs, commits []string, isDownloadEx bool) {
// Check all packages, they may be bundles, snapshots or raw packages path.
for i, p := range pkgs {
// Check if it is a bundle or snapshot.
@ -128,11 +131,11 @@ func downloadPackages(pkgs, commits []string) {
case utils.IsValidRemotePath(p):
if !downloadCache[p] {
// Download package.
pkg, imports := downloadPackage(p, commits[i])
pkg, imports := downloadPackage(p, commits[i], isDownloadEx)
if len(imports) > 0 {
// Need to download dependencies.
tags := make([]string, len(imports))
downloadPackages(imports, tags)
downloadPackages(imports, tags, isDownloadEx)
continue
}
@ -152,7 +155,7 @@ func downloadPackages(pkgs, commits []string) {
}
// downloadPackage download package either use version control tools or not.
func downloadPackage(path, commit string) (pkg *doc.Package, imports []string) {
func downloadPackage(path, commit string, isDownloadEx bool) (pkg *doc.Package, imports []string) {
// Check if use version control tools.
switch {
case !cmdInstall.Flags["-p"] &&
@ -173,14 +176,13 @@ func downloadPackage(path, commit string) (pkg *doc.Package, imports []string) {
downloadCache[path] = true
var err error
pkg, imports, err = pureDownload(path, commit)
pkg, imports, err = pureDownload(path, commit, isDownloadEx)
if err != nil {
fmt.Printf("Fail to download package(%s) with error: %s.\n", path, err)
return nil, nil
}
//fmt.Println(pkg)
//fmt.Printf("Downloaded package: %s.\n", path)
return pkg, imports
}
}
@ -202,7 +204,7 @@ func checkGoGetFlags() (args []string) {
type service struct {
pattern *regexp.Regexp
prefix string
get func(*http.Client, map[string]string, string) (*doc.Package, []string, error)
get func(*http.Client, map[string]string, string, bool) (*doc.Package, []string, error)
}
// services is the list of source code control services handled by gopkgdoc.
@ -214,7 +216,7 @@ var services = []*service{
}
// pureDownload downloads package without version control.
func pureDownload(path, commit string) (pinfo *doc.Package, imports []string, err error) {
func pureDownload(path, commit string, isDownloadEx bool) (pinfo *doc.Package, imports []string, err error) {
for _, s := range services {
if s.get == nil || !strings.HasPrefix(path, s.prefix) {
continue
@ -233,7 +235,7 @@ func pureDownload(path, commit string) (pinfo *doc.Package, imports []string, er
match[n] = m[i]
}
}
return s.get(doc.HttpClient, match, commit)
return s.get(doc.HttpClient, match, commit, isDownloadEx)
}
return nil, nil, doc.ErrNoMatch
}

Loading…
Cancel
Save