diff --git a/README.md b/README.md index d7f624ebc..c4068b4b5 100644 --- a/README.md +++ b/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. diff --git a/conf/gpm.toml b/conf/gpm.toml index 144841e0a..5ccb9e962 100644 --- a/conf/gpm.toml +++ b/conf/gpm.toml @@ -2,4 +2,6 @@ title = "gpm(Go Package Manager)" version = "v0.0.3 Build 0519" +username = "" +password = "" user_language = "en-US" \ No newline at end of file diff --git a/doc/github.go b/doc/github.go index 392439a20..e14854e2c 100644 --- a/doc/github.go +++ b/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 diff --git a/gpm.go b/gpm.go index d2d3cce9b..0020e9ad7 100644 --- a/gpm.go +++ b/gpm.go @@ -28,8 +28,9 @@ var ( ) type tomlConfig struct { - Title, Version string - Lang string `toml:"user_language"` + Title, Version string + Username, Password string + Lang string `toml:"user_language"` } // A Command is an implementation of a go command @@ -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 } diff --git a/i18n/en-US/usage_install.txt b/i18n/en-US/usage_install.txt index 78bf628e7..c11c54e11 100644 --- a/i18n/en-US/usage_install.txt +++ b/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. diff --git a/install.go b/install.go index d3e4d1d1c..afff74734 100644 --- a/install.go +++ b/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 }