vgo - strip out unused methods
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by jharshman · committed by Steve Francia · parent 0bb1506 · Browse files · 2 files·+6 added−214 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+6 added−214 removed
- other:+6 added−214 removed
Provenance
- Commit
303a3e5- Tree
c62b0fc- Author
jharshman <joshgreyhat@gmail.com>- Committer
Steve Francia <steve.francia@gmail.com>- Parent
0bb1506
2 files changed+6 added−214 removed
modified:cobra/cmd/project_test.go+1 added-22 removed
1 package cmd2 3-import (4- "testing"5-)6-7-func TestFindExistingPackage(t *testing.T) {8- path := findPackage("github.com/spf13/cobra")9- if path == "" {10- t.Fatal("findPackage didn't find the existing package")11- }12- if !hasGoPathPrefix(path) {13- t.Fatalf("%q is not in GOPATH, but must be", path)14- }15-}16-17-func hasGoPathPrefix(path string) bool {18- for _, srcPath := range srcPaths {19- if filepathHasPrefix(path, srcPath) {20- return true21- }22- }23- return false24-}3+/* todo: write tests */modified:cobra/cmd/project.go+5 added-192 removed
2 unmodified lines3 import (4 "fmt"5 "github.com/spf13/cobra/cobra/tpl"6 "os"7- "path/filepath"8- "runtime"9- "strings"7 "text/template"8 )9 10 // Project contains name, license and paths to projects.5 unmodified lines16 Legal License17 Viper bool18 AppName string19 23- // v124- absPath string25- cmdPath string26- srcPath string27- license License28- name string20+ //absPath string21+ //cmdPath string22+ //srcPath string23+ //license License24+ //name string25 }26 27 type Command struct {28 CmdName string70 unmodified lines99 return err100 }101 return nil102 }107-108-// NewProject returns Project with specified project name.109-func NewProject(projectName string) *Project {110- if projectName == "" {111- er("can't create project with blank name")112- }113-114- p := new(Project)115- p.name = projectName116-117- // 1. Find already created protect.118- p.absPath = findPackage(projectName)119-120- // 2. If there are no created project with this path, and user is in GOPATH,121- // then use GOPATH/src/projectName.122- if p.absPath == "" {123- wd, err := os.Getwd()124- if err != nil {125- er(err)126- }127- for _, srcPath := range srcPaths {128- goPath := filepath.Dir(srcPath)129- if filepathHasPrefix(wd, goPath) {130- p.absPath = filepath.Join(srcPath, projectName)131- break132- }133- }134- }135-136- // 3. If user is not in GOPATH, then use (first GOPATH)/src/projectName.137- if p.absPath == "" {138- p.absPath = filepath.Join(srcPaths[0], projectName)139- }140-141- return p142-}143-144-// findPackage returns full path to existing go package in GOPATHs.145-func findPackage(packageName string) string {146- if packageName == "" {147- return ""148- }149-150- for _, srcPath := range srcPaths {151- packagePath := filepath.Join(srcPath, packageName)152- if exists(packagePath) {153- return packagePath154- }155- }156-157- return ""158-}159-160-// NewProjectFromPath returns Project with specified absolute path to161-// package.162-func NewProjectFromPath(absPath string) *Project {163- if absPath == "" {164- er("can't create project: absPath can't be blank")165- }166- if !filepath.IsAbs(absPath) {167- er("can't create project: absPath is not absolute")168- }169-170- // If absPath is symlink, use its destination.171- fi, err := os.Lstat(absPath)172- if err != nil {173- er("can't read path info: " + err.Error())174- }175- if fi.Mode()&os.ModeSymlink != 0 {176- path, err := os.Readlink(absPath)177- if err != nil {178- er("can't read the destination of symlink: " + err.Error())179- }180- absPath = path181- }182-183- p := new(Project)184- p.absPath = strings.TrimSuffix(absPath, findCmdDir(absPath))185- p.name = filepath.ToSlash(trimSrcPath(p.absPath, p.SrcPath()))186- return p187-}188-189-// trimSrcPath trims at the beginning of absPath the srcPath.190-func trimSrcPath(absPath, srcPath string) string {191- relPath, err := filepath.Rel(srcPath, absPath)192- if err != nil {193- er(err)194- }195- return relPath196-}197-198-// License returns the License object of project.199-func (p *Project) License() License {200- if p.license.Text == "" && p.license.Name != "None" {201- p.license = getLicense()202- }203- return p.license204-}205-206-// Name returns the name of project, e.g. "github.com/spf13/cobra"207-func (p Project) Name() string {208- return p.name209-}210-211-// CmdPath returns absolute path to directory, where all commands are located.212-func (p *Project) CmdPath() string {213- if p.absPath == "" {214- return ""215- }216- if p.cmdPath == "" {217- p.cmdPath = filepath.Join(p.absPath, findCmdDir(p.absPath))218- }219- return p.cmdPath220-}221-222-// findCmdDir checks if base of absPath is cmd dir and returns it or223-// looks for existing cmd dir in absPath.224-func findCmdDir(absPath string) string {225- if !exists(absPath) || isEmpty(absPath) {226- return "cmd"227- }228-229- if isCmdDir(absPath) {230- return filepath.Base(absPath)231- }232-233- files, _ := filepath.Glob(filepath.Join(absPath, "c*"))234- for _, file := range files {235- if isCmdDir(file) {236- return filepath.Base(file)237- }238- }239-240- return "cmd"241-}242-243-// isCmdDir checks if base of name is one of cmdDir.244-func isCmdDir(name string) bool {245- name = filepath.Base(name)246- for _, cmdDir := range []string{"cmd", "cmds", "command", "commands"} {247- if name == cmdDir {248- return true249- }250- }251- return false252-}253-254-// AbsPath returns absolute path of project.255-func (p Project) AbsPath() string {256- return p.absPath257-}258-259-// SrcPath returns absolute path to $GOPATH/src where project is located.260-func (p *Project) SrcPath() string {261- if p.srcPath != "" {262- return p.srcPath263- }264- if p.absPath == "" {265- p.srcPath = srcPaths[0]266- return p.srcPath267- }268-269- for _, srcPath := range srcPaths {270- if filepathHasPrefix(p.absPath, srcPath) {271- p.srcPath = srcPath272- break273- }274- }275-276- return p.srcPath277-}278-279-func filepathHasPrefix(path string, prefix string) bool {280- if len(path) <= len(prefix) {281- return false282- }283- if runtime.GOOS == "windows" {284- // Paths in windows are case-insensitive.285- return strings.EqualFold(path[0:len(prefix)], prefix)286- }287- return path[0:len(prefix)] == prefix288-289-}