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

Conversation

yoheimuta
Copy link
Owner

@@ -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

@@ -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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants