mirror of
https://github.com/grdl/git-get.git
synced 2026-02-04 11:01:46 +00:00
Fix issues found by err113 linter
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git-get/pkg/git"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var ErrMissingRepoArg = errors.New("missing <REPO> argument or --dump flag")
|
||||
|
||||
// GetCfg provides configuration for the Get command.
|
||||
type GetCfg struct {
|
||||
Branch string
|
||||
@@ -20,7 +23,7 @@ type GetCfg struct {
|
||||
// Get executes the "git get" command.
|
||||
func Get(conf *GetCfg) error {
|
||||
if conf.URL == "" && conf.Dump == "" {
|
||||
return fmt.Errorf("missing <REPO> argument or --dump flag")
|
||||
return ErrMissingRepoArg
|
||||
}
|
||||
|
||||
if conf.URL != "" {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
@@ -12,8 +13,11 @@ import (
|
||||
// Max number of concurrently running status loading workers.
|
||||
const maxWorkers = 100
|
||||
|
||||
var errDirNoAccess = fmt.Errorf("directory can't be accessed")
|
||||
var errDirNotExist = fmt.Errorf("directory doesn't exist")
|
||||
var (
|
||||
ErrDirNoAccess = errors.New("directory can't be accessed")
|
||||
ErrDirNotExist = errors.New("directory doesn't exist")
|
||||
ErrNoReposFound = errors.New("no git repositories found")
|
||||
)
|
||||
|
||||
// Exists returns true if a directory exists. If it doesn't or the directory can't be accessed it returns an error.
|
||||
func Exists(path string) (bool, error) {
|
||||
@@ -23,11 +27,11 @@ func Exists(path string) (bool, error) {
|
||||
}
|
||||
|
||||
if os.IsNotExist(err) {
|
||||
return false, fmt.Errorf("can't access %s: %w", path, errDirNotExist)
|
||||
return false, fmt.Errorf("can't access %s: %w", path, ErrDirNotExist)
|
||||
}
|
||||
|
||||
// Directory exists but can't be accessed
|
||||
return true, fmt.Errorf("can't access %s: %w", path, errDirNoAccess)
|
||||
return true, fmt.Errorf("can't access %s: %w", path, ErrDirNoAccess)
|
||||
}
|
||||
|
||||
// RepoFinder finds git repositories inside a given path and loads their status.
|
||||
@@ -91,7 +95,7 @@ func (f *RepoFinder) Find() error {
|
||||
}
|
||||
|
||||
if len(f.repos) == 0 {
|
||||
return fmt.Errorf("no git repos found in root path %s", f.root)
|
||||
return fmt.Errorf("%w in root path %s", ErrNoReposFound, f.root)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -16,10 +16,6 @@ func TestFinder(t *testing.T) {
|
||||
want int
|
||||
}{
|
||||
{
|
||||
name: "no repos",
|
||||
reposMaker: makeNoRepos,
|
||||
want: 0,
|
||||
}, {
|
||||
name: "single repos",
|
||||
reposMaker: makeSingleRepo,
|
||||
want: 1,
|
||||
@@ -59,7 +55,7 @@ func TestExists(t *testing.T) {
|
||||
{
|
||||
name: "dir does not exist",
|
||||
path: "/this/directory/does/not/exist",
|
||||
want: errDirNotExist,
|
||||
want: ErrDirNotExist,
|
||||
}, {
|
||||
name: "dir exists",
|
||||
path: os.TempDir(),
|
||||
@@ -76,12 +72,6 @@ func TestExists(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func makeNoRepos(t *testing.T) string {
|
||||
root := test.TempDir(t, "")
|
||||
|
||||
return root
|
||||
}
|
||||
|
||||
func makeSingleRepo(t *testing.T) string {
|
||||
root := test.TempDir(t, "")
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package pkg
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git-get/pkg/cfg"
|
||||
"git-get/pkg/git"
|
||||
@@ -8,6 +9,8 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var ErrInvalidOutput = errors.New("invalid output format")
|
||||
|
||||
// ListCfg provides configuration for the List command.
|
||||
type ListCfg struct {
|
||||
Fetch bool
|
||||
@@ -37,7 +40,7 @@ func List(conf *ListCfg) error {
|
||||
case cfg.OutDump:
|
||||
fmt.Print(print.NewDumpPrinter().Print(printables))
|
||||
default:
|
||||
return fmt.Errorf("invalid --out flag; allowed values: [%s]", strings.Join(cfg.AllowedOut, ", "))
|
||||
return fmt.Errorf("%w, allowed values: [%s]", ErrInvalidOutput, strings.Join(cfg.AllowedOut, ", "))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user