minor enhancements for dep init

This commit is contained in:
Marwan Sulaiman 2017-10-10 21:12:38 -04:00 коммит произвёл Ibrahim AshShohail
Родитель 5bdd00bd69
Коммит e9e0d145b3
5 изменённых файлов: 29 добавлений и 26 удалений

Просмотреть файл

@ -56,7 +56,7 @@ type Config struct {
// Run executes a configuration and returns an exit code.
func (c *Config) Run() (exitCode int) {
// Build the list of available commands.
commands := []command{
commands := [...]command{
&initCommand{},
&statusCommand{},
&ensureCommand{},
@ -65,7 +65,7 @@ func (c *Config) Run() (exitCode int) {
&versionCommand{},
}
examples := [][2]string{
examples := [...][2]string{
{
"dep init",
"set up a new project",
@ -94,7 +94,7 @@ func (c *Config) Run() (exitCode int) {
errLogger.Println()
errLogger.Println("Commands:")
errLogger.Println()
w := tabwriter.NewWriter(c.Stderr, 0, 4, 2, ' ', 0)
w := tabwriter.NewWriter(c.Stderr, 0, 0, 2, ' ', 0)
for _, cmd := range commands {
if !cmd.Hidden() {
fmt.Fprintf(w, "\t%s\t%s\n", cmd.Name(), cmd.ShortHelp())
@ -115,7 +115,7 @@ func (c *Config) Run() (exitCode int) {
if exit {
usage()
exitCode = 1
return
return exitCode
}
for _, cmd := range commands {
@ -134,7 +134,7 @@ func (c *Config) Run() (exitCode int) {
if printCommandHelp {
fs.Usage()
exitCode = 1
return
return exitCode
}
// Parse the flags the user gave us.
@ -142,7 +142,7 @@ func (c *Config) Run() (exitCode int) {
// or if '-h' flag provided
if err := fs.Parse(c.Args[2:]); err != nil {
exitCode = 1
return
return exitCode
}
// Set up dep context.
@ -160,18 +160,18 @@ func (c *Config) Run() (exitCode int) {
if err := cmd.Run(ctx, fs.Args()); err != nil {
errLogger.Printf("%v\n", err)
exitCode = 1
return
return exitCode
}
// Easy peasy livin' breezy.
return
return exitCode
}
}
errLogger.Printf("dep: %s: no such command\n", cmdName)
usage()
exitCode = 1
return
return exitCode
}
func resetUsage(logger *log.Logger, fs *flag.FlagSet, name, args, longHelp string) {

Просмотреть файл

@ -97,6 +97,12 @@ func pathDeducerTrie() *deducerTrie {
}
type pathDeducer interface {
// deduceRoot takes an import path such as
// "github.com/some-user/some-package/some-subpackage"
// and returns the root folder to where the version control
// system exists. For example, the root folder where .git exists.
// So the return of the above string would be
// "github.com/some-user/some-package"
deduceRoot(string) (string, error)
deduceSource(string, *url.URL) (maybeSource, error)
}

Просмотреть файл

@ -10,7 +10,7 @@ import "strings"
// part of the standard distribution. For historical reasons we allow people to add
// their own code to $GOROOT instead of using $GOPATH, but we assume that
// code will start with a domain name (dot in the first element).
// This was loving taken from src/cmd/go/pkg.go in Go's code (isStandardImportPath).
// This was lovingly taken from src/cmd/go/pkg.go in Go's code (isStandardImportPath).
func IsStandardImportPath(path string) bool {
i := strings.Index(path, "/")
if i < 0 {

Просмотреть файл

@ -7,6 +7,7 @@ package gps
import (
"context"
"encoding/xml"
"fmt"
"os"
"path/filepath"
"runtime"
@ -37,30 +38,26 @@ func newCtxRepo(s vcs.Type, ustr, path string) (r ctxRepo, err error) {
r, err = getVCSRepo(s, ustr, path)
}
return
return r, err
}
func getVCSRepo(s vcs.Type, ustr, path string) (r ctxRepo, err error) {
switch s {
case vcs.Git:
var repo *vcs.GitRepo
repo, err = vcs.NewGitRepo(ustr, path)
r = &gitRepo{repo}
repo, err := vcs.NewGitRepo(ustr, path)
return &gitRepo{repo}, err
case vcs.Bzr:
var repo *vcs.BzrRepo
repo, err = vcs.NewBzrRepo(ustr, path)
r = &bzrRepo{repo}
repo, err := vcs.NewBzrRepo(ustr, path)
return &bzrRepo{repo}, err
case vcs.Hg:
var repo *vcs.HgRepo
repo, err = vcs.NewHgRepo(ustr, path)
r = &hgRepo{repo}
repo, err := vcs.NewHgRepo(ustr, path)
return &hgRepo{repo}, err
case vcs.Svn:
var repo *vcs.SvnRepo
repo, err = vcs.NewSvnRepo(ustr, path)
r = &svnRepo{repo}
repo, err := vcs.NewSvnRepo(ustr, path)
return &svnRepo{repo}, err
default:
panic(fmt.Sprintf("Unrecognized format: %v", s))
}
return
}
// original implementation of these methods come from

Просмотреть файл

@ -104,7 +104,7 @@ type Project struct {
Lock *Lock // Optional
}
// SetRoot sets the project AbsRoot and ResolvedAbsRoot. If root is a not symlink, ResolvedAbsRoot will be set to root.
// SetRoot sets the project AbsRoot and ResolvedAbsRoot. If root is not a symlink, ResolvedAbsRoot will be set to root.
func (p *Project) SetRoot(root string) error {
rroot, err := filepath.EvalSymlinks(root)
if err != nil {