From 51dad73b05571f737b6cf401548346e0f55e54f5 Mon Sep 17 00:00:00 2001 From: jichangjun Date: Sun, 26 Jul 2020 17:46:35 +0800 Subject: [PATCH] enhance doc --- pkg/build/build.go | 2 +- pkg/build/build_test.go | 2 +- pkg/build/errors.go | 22 +++++++++++++++------- pkg/build/tmpfolder.go | 2 +- pkg/build/tmpfolder_test.go | 2 +- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/pkg/build/build.go b/pkg/build/build.go index 28ddb28..50b2809 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -110,7 +110,7 @@ func (b *Build) Build() error { // the binary name is always same as the directory name of current directory func (b *Build) determineOutputDir(outputDir string) (string, error) { if b.TmpDir == "" { - return "", fmt.Errorf("can only be called after Build.MvProjectsToTmp(): %w", ErrWrongCallSequence) + return "", fmt.Errorf("can only be called after Build.MvProjectsToTmp(): %w", ErrEmptyTempWorkingDir) } // fix #43 diff --git a/pkg/build/build_test.go b/pkg/build/build_test.go index 7255730..3237277 100644 --- a/pkg/build/build_test.go +++ b/pkg/build/build_test.go @@ -70,7 +70,7 @@ func TestCheckParameters(t *testing.T) { func TestDetermineOutputDir(t *testing.T) { b := &Build{} _, err := b.determineOutputDir("") - assert.Equal(t, errors.Is(err, ErrWrongCallSequence), true, "called before Build.MvProjectsToTmp() should fail") + assert.Equal(t, errors.Is(err, ErrEmptyTempWorkingDir), true, "called before Build.MvProjectsToTmp() should fail") b.TmpDir = "fake" _, err = b.determineOutputDir("xx") diff --git a/pkg/build/errors.go b/pkg/build/errors.go index 6359434..e0376bd 100644 --- a/pkg/build/errors.go +++ b/pkg/build/errors.go @@ -5,12 +5,20 @@ import ( ) var ( - ErrShouldNotReached = errors.New("should never be reached") - ErrGocShouldExecInProject = errors.New("goc not executed in project directory") + // ErrShouldNotReached represents the logic should not be reached in normal flow + ErrShouldNotReached = errors.New("should never be reached") + // ErrGocShouldExecInProject represents goc currently not support for the project + ErrGocShouldExecInProject = errors.New("goc not support for such project directory") + // ErrWrongPackageTypeForInstall represents goc install command only support limited arguments ErrWrongPackageTypeForInstall = errors.New("packages only support \".\" and \"./...\"") - ErrWrongPackageTypeForBuild = errors.New("packages only support \".\"") - ErrTooManyArgs = errors.New("too many args") - ErrInvalidWorkingDir = errors.New("the working directory is invalid") - ErrWrongCallSequence = errors.New("function should be called in a specified sequence") - ErrNoplaceToInstall = errors.New("dont know where to install") + // ErrWrongPackageTypeForBuild represents goc build command only support limited arguments + ErrWrongPackageTypeForBuild = errors.New("packages only support \".\"") + // ErrTooManyArgs represents goc CLI only support limited arguments + ErrTooManyArgs = errors.New("too many args") + // ErrInvalidWorkingDir represents the working directory is invalid + ErrInvalidWorkingDir = errors.New("the working directory is invalid") + // ErrEmptyTempWorkingDir represent the error that temporary working directory is empty + ErrEmptyTempWorkingDir = errors.New("temporary working directory is empty") + // ErrNoPlaceToInstall represents the err that no place to install the generated binary + ErrNoPlaceToInstall = errors.New("don't know where to install") ) diff --git a/pkg/build/tmpfolder.go b/pkg/build/tmpfolder.go index bc40438..9a1a08c 100644 --- a/pkg/build/tmpfolder.go +++ b/pkg/build/tmpfolder.go @@ -172,7 +172,7 @@ func (b *Build) findWhereToInstall() (string, error) { if false == b.IsMod { if b.Root == "" { - return "", ErrNoplaceToInstall + return "", ErrNoPlaceToInstall } return filepath.Join(b.Root, "bin"), nil } diff --git a/pkg/build/tmpfolder_test.go b/pkg/build/tmpfolder_test.go index c730068..07614be 100644 --- a/pkg/build/tmpfolder_test.go +++ b/pkg/build/tmpfolder_test.go @@ -133,7 +133,7 @@ func TestFindWhereToInstall(t *testing.T) { Root: "", } _, err := b.findWhereToInstall() - assert.EqualError(t, err, ErrNoplaceToInstall.Error()) + assert.EqualError(t, err, ErrNoPlaceToInstall.Error()) // if $GOBIN not found // and if $GOPATH not found