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

Support vendor imports #18

Merged
merged 1 commit into from
Jun 13, 2017
Merged

Support vendor imports #18

merged 1 commit into from
Jun 13, 2017

Conversation

boz
Copy link
Contributor

@boz boz commented Jun 6, 2017

After putting this together, I noticed that #17 does something similar.

This helps support vendor imports. Defaulting it to $PWD would work for my workflow but I don't know about others.

If this is accepted I'll add support for it in https://github.com/fatih/vim-go

@josharian
Copy link
Owner

Thanks for this. Funny that both PRs should land in one day. This one is closer to the desired final form, so maybe we can iterate on it?

I'd rather use a flag than a positional arg for this, since I think it will be rare. That is: impl [-dir dir] <recv> <iface>. If it is not provided, it should default to os.Getwd(), and if os.Getwd() returns an error, it should default to "" (and not display an error to the user).

@boz
Copy link
Contributor Author

boz commented Jun 6, 2017 via email

@boz boz force-pushed the master branch 2 times, most recently from 2d98cef to 269f090 Compare June 7, 2017 00:19
@boz
Copy link
Contributor Author

boz commented Jun 7, 2017

@josharian take a look. had to add faux filename to make things work correctly.

I'd push up the vim-go change but my fork is a github crash casualty at the moment.

boz added a commit to boz/vim-go that referenced this pull request Jun 7, 2017
  * attempt to use `-dir` argument from josharian/impl#18 if `impl`
    fails.
  * backwards compatible with previous `impl` versions.
impl.go Outdated
fmt.Fprint(os.Stderr, usage)
os.Exit(2)
}
recv, iface := os.Args[1], os.Args[2]

recv, iface := flag.Args()[0], flag.Args()[1]
Copy link
Owner

Choose a reason for hiding this comment

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

flag.Arg(0) and flag.Arg(1)

@@ -34,7 +34,7 @@ func TestFindInterface(t *testing.T) {
}

for _, tt := range cases {
path, id, err := findInterface(tt.iface)
path, id, err := findInterface(tt.iface, ".")
Copy link
Owner

Choose a reason for hiding this comment

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

Why "." here but "" below?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Those are the values that were hardcoded before this change. See here and here

The other requested changes have been addressed in my latest commits.

impl.go Outdated
if !validReceiver(recv) {
fatal(fmt.Sprintf("invalid receiver: %q", recv))
}

fns, err := funcs(iface)
if *sourceDirectory == "" {
*sourceDirectory, _ = os.Getwd()
Copy link
Owner

Choose a reason for hiding this comment

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

If err is non-nil, we should ignore the other return value, unless that behavior is specifically documented:

if dir, err := os.Getwd(); err != nil {
  *sourceDirectory = dir
}

Copy link
Contributor

Choose a reason for hiding this comment

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

See #18 (comment). I believe you have a typo in your snippet, it should be err == nil instead of err != nil, since inside the if statement is the success path rather than failure path.

impl.go Outdated

Don't forget the single quotes around the receiver type
to prevent shell globbing.
`

var (
sourceDirectory = flag.String("dir", "", "package source directory")
Copy link
Owner

Choose a reason for hiding this comment

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

Nit: please name this flagSourceDirectory or flagSrcDir. It helps highlight that it is a flag value, even far from its declaration.

If you can, it'd be nice to add a short clause hinting to the reader why/when they would want this, maybe something like "package source directory, useful for vendored code".

@boz boz force-pushed the master branch 3 times, most recently from 6589e61 to 0f159c4 Compare June 13, 2017 22:15
 * allow specifying directory of import
@josharian
Copy link
Owner

Thanks again for doing this.

@josharian josharian merged commit 3fb19c2 into josharian:master Jun 13, 2017
@josharian josharian mentioned this pull request Jun 13, 2017
if !validReceiver(recv) {
fatal(fmt.Sprintf("invalid receiver: %q", recv))
}

fns, err := funcs(iface)
if *flagSrcDir == "" {
if dir, err := os.Getwd(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be err == nil instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, you're right.

Copy link
Contributor

@dmitshur dmitshur Jun 19, 2017

Choose a reason for hiding this comment

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

Are you planning on taking this @boz?

It's been a few days and it's still not fixed, and I'm just trying to figure out whether I need to send a PR or not.

Copy link
Owner

Choose a reason for hiding this comment

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

@shurcooL please send a PR. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

@josharian Ok, sent #19.

josharian pushed a commit that referenced this pull request Jun 19, 2017
The body of the if statement is the success case, so it should run when err == nil.

Fixup for #18 (comment).
boz added a commit to boz/vim-go that referenced this pull request Aug 14, 2017
  * attempt to use `-dir` argument from josharian/impl#18 if `impl`
    fails.
  * backwards compatible with previous `impl` versions.
boz added a commit to boz/vim-go that referenced this pull request Sep 7, 2017
  * attempt to use `-dir` argument from josharian/impl#18 if `impl`
    fails.
  * backwards compatible with previous `impl` versions.
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.

3 participants