-
Notifications
You must be signed in to change notification settings - Fork 1
feat: 添加 buf format #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6d25b33
d6ed94a
e710f58
9eb8b70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| 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") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When
Suggested change
|
||||||
| return err | ||||||
| } | ||||||
|
|
||||||
| shutil.MustRun(bufPath, "format proto -w") | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
|
||||||
| return nil | ||||||
| }, | ||||||
| } | ||||||
| } | ||||||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentation for the
formatcommand example is inconsistent with thelintcommand example above it. For better readability and consistency, please align the indentation.