Skip to content
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

fix: Remove an unnecessary dependency to sh #145

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ test/lint:
# checks shadowed variables.
go vet -vettool=$(which shadow) ./...
# checks no used assigned value.
ineffassign .
ineffassign ./...
# checks not to ignore the error.
errcheck ./...
# checks unused global variables and constants.
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func doLint(

flags, err := lint.NewFlags(args)
if err != nil {
_, _ = fmt.Fprint(stderr, err)
_, _ = fmt.Fprintln(stderr, err)
Copy link
Owner Author

Choose a reason for hiding this comment

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

[memo] It enables it to properly show an error message when err ends up without a new line.

❯❯❯ ./protolint -plugin ./not_existence _example/proto/
failed client.Client(), err=fork/exec ./plugin/greete: no such file or directory

return osutil.ExitInternalFailure
}
if len(flags.Args()) < 1 {
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/subcmds/pluginFlag.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (f *PluginFlag) BuildPlugins(verbose bool) ([]shared.RuleSet, error) {
client := plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: shared.Handshake,
Plugins: shared.PluginMap,
Cmd: exec.Command("sh", "-c", value),
Cmd: exec.Command(value),
Copy link
Owner Author

Choose a reason for hiding this comment

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

[memo] It works by directly passing an executable.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I remember now that sh -c is necessary when giving flags to a plugin like below:

# it works now but doesn't work after this fix.
$ ./protolint -plugin "./plugin_example -go_style=false" _example/proto/

Copy link
Contributor

@PaulSonOfLars PaulSonOfLars May 24, 2021

Choose a reason for hiding this comment

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

Could you expand the flags such that they are passed as arguments to the command, instead of simply passing value?

Naive approach would be to split on spaces, but that would break in the case of the flags containing quoted arguments containing spaces. Writing a quick parser to support this shouldn't be too difficult.

eg: Currently, value (from your example) is ./plugin_example -go_style=false. The arguments need to be split up for this to work as expected.

My suggestion would be to use exec.Command(value, args...) instead, where value="./plugin_example" and args=[]string{"-go_style=false"}

Of course, this is very naive, and wouldnt support any fancy expansions that sh supports. Is there a go lib to emulate that?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Thank you for your nice suggestion.
I'm interested in that go lib.

As I'm not a Windows user, I've been waiting for others' feedbacks, like #144 (comment). These would be used for considering this fix's priority because I have no enough time.

AllowedProtocols: []plugin.Protocol{
plugin.ProtocolGRPC,
},
Expand Down