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
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@ go install github.com/pubgo/protobuild@latest

## example

[protobuf.yaml](https://github.com/pubgo/lava/blob/master/internal/example/grpc/protobuf.yaml)
[protobuf.yaml](./protobuf.test.yaml)

```yaml
protobuild -f protobuf.yaml vendor
protobuild -f protobuf.yaml gen
```

## lint

protobuild lint -c protobuf.test.yaml

## format

protobuild format -c protobuf.test.yaml
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The indentation for the format command example is inconsistent with the lint command example above it. For better readability and consistency, please align the indentation.

Suggested change
protobuild format -c protobuf.test.yaml
protobuild format -c protobuf.test.yaml


## protoc-gen-[plugin]

- istio.io/tools/cmd/protoc-gen-deepcopy@latest
Expand Down
5 changes: 0 additions & 5 deletions cmd/format/lint.go

This file was deleted.

27 changes: 27 additions & 0 deletions cmd/formatcmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package formatcmd

import (
"context"
"log/slog"
"os/exec"

"github.com/pubgo/protobuild/internal/shutil"
"github.com/urfave/cli/v3"
)

func New(name string) *cli.Command {
return &cli.Command{
Name: name,
Usage: "Format Protobuf files",
Action: func(ctx context.Context, command *cli.Command) error {
bufPath, err := exec.LookPath("buf")
if err != nil {
slog.Info("buf not found, please install https://github.com/bufbuild/buf/releases")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When buf is not found, it's an error condition. Using slog.Error instead of slog.Info would better reflect the severity of the situation and improve log-based monitoring and filtering.

Suggested change
slog.Info("buf not found, please install https://github.com/bufbuild/buf/releases")
slog.Error("buf not found, please install https://github.com/bufbuild/buf/releases")

return err
}

shutil.MustRun(bufPath, "format proto -w")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It's safer to pass command arguments as separate strings rather than a single string. This prevents potential shell injection vulnerabilities and handles arguments with spaces correctly, even though bufPath is unlikely to have spaces here.

Suggested change
shutil.MustRun(bufPath, "format proto -w")
shutil.MustRun(bufPath, "format", "proto", "-w")

return nil
},
}
}
2 changes: 1 addition & 1 deletion cmd/linters/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/samber/lo"
"os"
"strings"
"sync"

"github.com/googleapis/api-linter/lint"
"github.com/jhump/protoreflect/desc/protoparse"
"github.com/pubgo/protobuild/internal/typex"
"github.com/samber/lo"
"github.com/urfave/cli/v3"
"gopkg.in/yaml.v3"
)
Expand Down
2 changes: 1 addition & 1 deletion cmd/linters/rules.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package linters

import (
"github.com/googleapis/api-linter/rules"
"log"
"os"
"sort"

"github.com/googleapis/api-linter/lint"
"github.com/googleapis/api-linter/rules"
)

var (
Expand Down
2 changes: 2 additions & 0 deletions cmd/protobuild/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"github.com/pubgo/funk/pathutil"
"github.com/pubgo/funk/recovery"
"github.com/pubgo/funk/strutil"
"github.com/pubgo/protobuild/cmd/formatcmd"
linters "github.com/pubgo/protobuild/cmd/linters"
"github.com/pubgo/protobuild/internal/modutil"
"github.com/pubgo/protobuild/internal/shutil"
Expand Down Expand Up @@ -568,6 +569,7 @@ func Main() *cli.Command {
return nil
},
},
formatcmd.New("format"),
},
}
return app
Expand Down
142 changes: 0 additions & 142 deletions cmd/protoc-gen-go-jsonshim/main.go

This file was deleted.

54 changes: 0 additions & 54 deletions cmd/protoc-gen-gotag/example/example.proto

This file was deleted.

Loading