Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ linters:
main:
deny:
- pkg: 'log'
desc: 'Use logrus for logging instead of the standard log package.'
desc: 'Use github.com/rs/zerolog for logging instead of the standard log package.'
- pkg: 'io/ioutil'
desc: "The io/ioutil package has been deprecated, use 'os' or 'io' directly."
revive:
Expand Down
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Three-layer separation — do not collapse layers for convenience:
`errors.Is` / `errors.As` — never string-match error messages.
- **Concurrency:** use `golang.org/x/sync/errgroup`. Always honor
`context.Context` cancellation.
- **Logging:** use `logrus`, not stdlib `log` (depguard enforces). Stdlib
- **Logging:** use `github.com/rs/zerolog` (via the package-level `log`
global), not stdlib `log` (depguard enforces). Stdlib
`io/ioutil` is denied — use `os` / `io`.
- **CLI reference docs** (`docs/cli/*.md`) have an auto-generated marker block
(`<!---MARKER_GEN_START-->` / `<!---MARKER_GEN_END-->`). **Never edit inside
Expand Down
5 changes: 2 additions & 3 deletions cli/cobra.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,15 @@ import (
"sort"
"strings"

"github.com/fvbommel/sortorder"
"github.com/moby/term"
"github.com/morikuni/aec"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"

"go.wpm.so/cli/cli/command"
"go.wpm.so/cli/cli/command/completion"
cliflags "go.wpm.so/cli/cli/flags"
"go.wpm.so/cli/pkg/sortorder"
)

// setupCommonRootCommand contains the setup common to
Expand Down Expand Up @@ -101,7 +100,7 @@ var helpCommand = &cobra.Command{
RunE: func(c *cobra.Command, args []string) error {
cmd, args, e := c.Root().Find(args)
if cmd == nil || e != nil || len(args) > 0 {
return errors.Errorf("unknown help topic: %v", strings.Join(args, " "))
return fmt.Errorf("unknown help topic: %v", strings.Join(args, " "))
}
helpFunc := cmd.HelpFunc()
helpFunc(cmd, args)
Expand Down
4 changes: 2 additions & 2 deletions cli/command/auth/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package auth

import (
"context"
"errors"
"fmt"

"github.com/morikuni/aec"
"github.com/pkg/errors"
"github.com/spf13/cobra"

"go.wpm.so/cli/cli"
Expand Down Expand Up @@ -53,7 +53,7 @@ func tokenStdinPrompt(ctx context.Context, wpmCli command.Cli, opts *loginOption
wpmCli.Err().WriteString("\n")

if token == "" {
return errors.Errorf("token cannot be empty")
return errors.New("token cannot be empty")
}

opts.token = token
Expand Down
4 changes: 2 additions & 2 deletions cli/command/auth/logout.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package auth

import (
"errors"
"fmt"

"github.com/pkg/errors"
"github.com/spf13/cobra"

"go.wpm.so/cli/cli"
Expand All @@ -25,7 +25,7 @@ func runLogout(wpmCli command.Cli) error {
cfg := wpmCli.ConfigFile()

if cfg.AuthToken == "" {
return errors.Errorf("user must be logged in to perform this action")
return errors.New("user must be logged in to perform this action")
}

cfg.AuthToken = ""
Expand Down
30 changes: 15 additions & 15 deletions cli/command/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package init

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
Expand All @@ -12,7 +13,6 @@ import (

"github.com/Masterminds/semver/v3"
"github.com/morikuni/aec"
"github.com/pkg/errors"
"github.com/spf13/cobra"

"go.wpm.so/cli/cli/command"
Expand Down Expand Up @@ -91,14 +91,14 @@ func NewInitCommand(wpmCli command.Cli) *cobra.Command {
func runNewInit(ctx context.Context, wpmCli command.Cli, opts *initOptions) error {
cwd, err := os.Getwd()
if err != nil {
return errors.Wrap(err, "failed to get current working directory")
return fmt.Errorf("failed to get current working directory: %w", err)
}

wpmConfigFilePath := filepath.Join(cwd, wpmjson.ConfigFile)
if _, err := os.Stat(wpmConfigFilePath); err == nil {
return errors.Errorf("%s already exists in %s", wpmjson.ConfigFile, cwd)
return fmt.Errorf("%s already exists in %s", wpmjson.ConfigFile, cwd)
} else if !os.IsNotExist(err) {
return errors.Wrapf(err, "failed to check for existing %s", wpmjson.ConfigFile)
return fmt.Errorf("failed to check for existing %s: %w", wpmjson.ConfigFile, err)
}

wpmCfg := wpmjson.New()
Expand All @@ -125,7 +125,7 @@ func runNewInit(ctx context.Context, wpmCli command.Cli, opts *initOptions) erro
}

if err := wpmCfg.Write(cwd); err != nil {
return errors.Wrap(err, "failed to write wpm.json")
return fmt.Errorf("failed to write wpm.json: %w", err)
}

_, _ = fmt.Fprintf(wpmCli.Out(), "config created at %s\n", wpmConfigFilePath)
Expand All @@ -143,17 +143,17 @@ func extractPackageHeaders(wpmCli command.Cli, cwd string, opts *initOptions) (m
mainFilePath := filepath.Join(cwd, "style.css")
if _, err := os.Stat(mainFilePath); err != nil {
if os.IsNotExist(err) && opts.version == "" {
return nil, "", errors.Errorf("style.css not found in %s", cwd)
return nil, "", fmt.Errorf("style.css not found in %s", cwd)
}
if !os.IsNotExist(err) {
return nil, "", errors.Wrapf(err, "failed to stat style.css")
return nil, "", fmt.Errorf("failed to stat style.css: %w", err)
}
return nil, "", nil
}
headers, hErr := parser.GetThemeHeaders(mainFilePath)
if hErr != nil {
if opts.version == "" {
return nil, "", errors.Wrapf(hErr, "failed to parse theme headers from style.css")
return nil, "", fmt.Errorf("failed to parse theme headers from style.css: %w", hErr)
}
return nil, "", nil
}
Expand All @@ -162,21 +162,21 @@ func extractPackageHeaders(wpmCli command.Cli, cwd string, opts *initOptions) (m
case "plugin":
dirEntries, dErr := os.ReadDir(cwd)
if dErr != nil {
return nil, "", errors.Wrap(dErr, "failed to read current directory for plugin files")
return nil, "", fmt.Errorf("failed to read current directory for plugin files: %w", dErr)
}

foundPath, headers, fErr := findMainPluginFile(cwd, dirEntries)
if fErr != nil {
if opts.version == "" {
return nil, "", errors.Wrap(fErr, "failed to identify main plugin file")
return nil, "", fmt.Errorf("failed to identify main plugin file: %w", fErr)
}
return nil, "", nil
}
_, _ = fmt.Fprintf(wpmCli.Out(), "main plugin file found: %s\n", foundPath)
return headers, headers.Version, nil

default:
return nil, "", errors.Errorf("unsupported package type for existing project init: %s", opts.packageType)
return nil, "", fmt.Errorf("unsupported package type for existing project init: %s", opts.packageType)
}
}

Expand Down Expand Up @@ -213,7 +213,7 @@ func resolveConfigVersion(wpmCli command.Cli, wpmCfg *wpmjson.Config, opts *init
func runExistingInit(wpmCli command.Cli, opts *initOptions) error {
cwd, err := os.Getwd()
if err != nil {
return errors.Wrap(err, "failed to get current working directory")
return fmt.Errorf("failed to get current working directory: %w", err)
}

baseFiles, err := findExistingProjectFiles(cwd)
Expand All @@ -236,7 +236,7 @@ func runExistingInit(wpmCli command.Cli, opts *initOptions) error {
if baseFiles.readmeTxt != "" {
readmeTxtContent, err := os.ReadFile(baseFiles.readmeTxt)
if err != nil {
return errors.Wrap(err, "failed to read readme.txt")
return fmt.Errorf("failed to read readme.txt: %w", err)
}
readmeParser = parser.NewReadmeParser()
readmeParser.Parse(string(readmeTxtContent))
Expand Down Expand Up @@ -399,7 +399,7 @@ func promptForConfig(ctx context.Context, wpmCli command.Cli, config *wpmjson.Co
for {
val, err := command.PromptForInput(ctx, wpmCli.In(), wpmCli.Out(), fmt.Sprintf("%s (%s): ", pf.Prompt.Msg, pf.Prompt.Default))
if err != nil {
return errors.Wrap(err, "failed to get prompt input")
return fmt.Errorf("failed to get prompt input: %w", err)
}

if err := pf.Prompt.Validate(val); err != nil {
Expand All @@ -416,7 +416,7 @@ func findExistingProjectFiles(cwd string) (existingProjectFiles, error) {
var paths existingProjectFiles
files, err := os.ReadDir(cwd)
if err != nil {
return paths, errors.Wrap(err, "failed to read current directory")
return paths, fmt.Errorf("failed to read current directory: %w", err)
}

for _, file := range files {
Expand Down
14 changes: 7 additions & 7 deletions cli/command/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package install

import (
"context"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
"sync"

"github.com/morikuni/aec"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"golang.org/x/sync/errgroup"

Expand All @@ -31,7 +31,7 @@ type installOptions struct {
networkConcurrency int
}

var runHelp = errors.New("RUN_HELP")
var errRunHelp = errors.New("RUN_HELP")

func NewInstallCommand(wpmCli command.Cli) *cobra.Command {
var opts installOptions
Expand All @@ -48,7 +48,7 @@ func NewInstallCommand(wpmCli command.Cli) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
err := runInstall(cmd.Context(), wpmCli, opts, args)
if err != nil {
if errors.Is(err, runHelp) {
if errors.Is(err, errRunHelp) {
return cmd.Help()
}

Expand Down Expand Up @@ -81,7 +81,7 @@ func NewInstallCommand(wpmCli command.Cli) *cobra.Command {
func runInstall(ctx context.Context, wpmCli command.Cli, opts installOptions, packages []string) error {
cwd, err := os.Getwd()
if err != nil {
return errors.Wrap(err, "failed to get current working directory")
return fmt.Errorf("failed to get current working directory: %w", err)
}

wpmCli.Output().Prettyln(output.Text{
Expand All @@ -101,7 +101,7 @@ func runInstall(ctx context.Context, wpmCli command.Cli, opts installOptions, pa
})
})
if err != nil {
return errors.Wrap(err, "failed to acquire workspace lock")
return fmt.Errorf("failed to acquire workspace lock: %w", err)
}
defer func() {
_ = lock.Release()
Expand All @@ -114,7 +114,7 @@ func runInstall(ctx context.Context, wpmCli command.Cli, opts installOptions, pa

if cfg == nil {
if len(packages) == 0 {
return runHelp
return errRunHelp
}

cfg = wpmjson.New()
Expand Down Expand Up @@ -201,7 +201,7 @@ func addPackages(ctx context.Context, config *wpmjson.Config, wpmCli command.Cli
g.Go(func() error {
manifest, err := client.GetPackageManifest(ctx, name, versionOrTag, true)
if err != nil {
return errors.Wrapf(err, "failed to fetch package %s@%s", name, versionOrTag)
return fmt.Errorf("failed to fetch package %s@%s: %w", name, versionOrTag, err)
}

mu.Lock()
Expand Down
18 changes: 9 additions & 9 deletions cli/command/install/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package install

import (
"context"
"errors"
"fmt"
"maps"
"path/filepath"
"slices"
"strconv"

"github.com/morikuni/aec"
"github.com/pkg/errors"

"go.wpm.so/cli/cli/command"
"go.wpm.so/cli/pkg/output"
Expand Down Expand Up @@ -67,12 +67,12 @@ func Run(ctx context.Context, cwd string, wpmCli command.Cli, opts RunOptions) e
return errors.New("wpm.json config is required")
}
if err := wpmCfg.ValidateDependencyNames(); err != nil {
return errors.Wrap(err, "invalid dependency name in wpm.json")
return fmt.Errorf("invalid dependency name in wpm.json: %w", err)
}

lock, err := wpmlock.Read(cwd)
if err != nil {
return errors.Wrap(err, "failed to read lockfile")
return fmt.Errorf("failed to read lockfile: %w", err)
}
if lock == nil {
lock = wpmlock.New()
Expand All @@ -83,7 +83,7 @@ func Run(ctx context.Context, cwd string, wpmCli command.Cli, opts RunOptions) e

client, err := wpmCli.RegistryClient()
if err != nil {
return errors.Wrap(err, "failed to create registry client")
return fmt.Errorf("failed to create registry client: %w", err)
}

resolver := resolution.New(wpmCfg, lock, client)
Expand All @@ -102,7 +102,7 @@ func Run(ctx context.Context, cwd string, wpmCli command.Cli, opts RunOptions) e
if len(plan) == 0 {
if opts.SaveConfig {
if err := wpmCfg.Write(cwd); err != nil {
return errors.Wrap(err, "failed to save wpm.json")
return fmt.Errorf("failed to save wpm.json: %w", err)
}
}

Expand All @@ -120,12 +120,12 @@ func Run(ctx context.Context, cwd string, wpmCli command.Cli, opts RunOptions) e
wpmCli.Output().ErrorWrite(fmt.Sprintf(format+"\n", args...))
})
if err != nil {
return errors.Wrap(err, "failed to initialize installer")
return fmt.Errorf("failed to initialize installer: %w", err)
}
defer func() { _ = inst.Close() }()

if err := inst.InstallAll(ctx, plan, installerProgress(wpmCli.Output())); err != nil {
return errors.Wrap(err, "installation failed")
return fmt.Errorf("installation failed: %w", err)
}

// @todo: binary linking
Expand All @@ -134,14 +134,14 @@ func Run(ctx context.Context, cwd string, wpmCli command.Cli, opts RunOptions) e

updateLockPackages(lock, resolved)
if err := lock.Write(cwd); err != nil {
return errors.Wrap(err, "failed to save lockfile")
return fmt.Errorf("failed to save lockfile: %w", err)
}

// @todo: run root lifecycle scripts

if opts.SaveConfig {
if err := wpmCfg.Write(cwd); err != nil {
return errors.Wrap(err, "failed to save wpm.json")
return fmt.Errorf("failed to save wpm.json: %w", err)
}
}

Expand Down
6 changes: 3 additions & 3 deletions cli/command/ls/ls.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ls

import (
"errors"
"fmt"
"io"
"maps"
Expand All @@ -9,7 +10,6 @@ import (
"sort"

"github.com/morikuni/aec"
"github.com/pkg/errors"
"github.com/spf13/cobra"

"go.wpm.so/cli/cli"
Expand Down Expand Up @@ -42,7 +42,7 @@ func NewLsCommand(wpmCli command.Cli) *cobra.Command {
func runLs(wpmCli command.Cli, opts lsOptions) error {
cwd, err := os.Getwd()
if err != nil {
return errors.Wrap(err, "failed to get current working directory")
return fmt.Errorf("failed to get current working directory: %w", err)
}

config, err := wpmjson.Read(cwd)
Expand All @@ -55,7 +55,7 @@ func runLs(wpmCli command.Cli, opts lsOptions) error {

lock, err := wpmlock.Read(cwd)
if err != nil {
return errors.Wrap(err, "failed to read lockfile")
return fmt.Errorf("failed to read lockfile: %w", err)
}
if lock == nil {
return errors.New("no wpm.lock found, you need to run `wpm install` first")
Expand Down
Loading