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

ponzu add <addon URI> #87

Merged
merged 18 commits into from
Mar 1, 2017
Merged

ponzu add <addon URI> #87

merged 18 commits into from
Mar 1, 2017

Conversation

olliephillips
Copy link
Contributor

@olliephillips olliephillips commented Feb 24, 2017

Reference issue #85. As discussed, this adds a ponzu add command to the CLI. It fetches the addon from its URI by wrapping go get then copies it to the projects local ./addons directory.

There is no switch for automatically installing. Based on the issue discussion that feature needs more thought, so has been omitted.

I've updated the README to include documentation on the command.

It's been tested as per the approach in the README.

@nilslice nilslice self-requested a review February 24, 2017 19:33

// Go get
cmdOptions = append(cmdOptions, "get", addonPath)
get := exec.Command(gocmd, cmdOptions...)
Copy link
Contributor

Choose a reason for hiding this comment

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

good catch to re-use the gocmd variable.. will be very useful when working with future go version betas / release candidates. thank you for being mindful about that!

cmd/ponzu/add.go Outdated
// copy to ./addons folder
// GOPATH can be a list delimited by ":" on Linux or ";" on Windows
// `go get` uses the first, this should parse out the first whatever the OS
gopath := resolveGOPATH()
Copy link
Contributor

Choose a reason for hiding this comment

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

if you don't mind, before we merge this in, could you take a look at #82 and see how it would impact GOPATH resolution in the way you have it?

#82 hasn't been fixed, but the code is pretty much written in the issue... if you felt inclined to add that in I would be grateful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Certainly. I didn't know anything about that. I only upgraded to 1.8 to run Ponzu :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Great -- thank you very much!

@@ -162,6 +162,19 @@ var usageVersion = `

`

var usageAdd = `
[--cli] add, a <addon URI>
Copy link
Contributor

Choose a reason for hiding this comment

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

is [--cli] actually used in the add command? if not, lets clear that so it's not confusing. then in place of , let's say

Copy link
Contributor Author

@olliephillips olliephillips Feb 24, 2017

Choose a reason for hiding this comment

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

It's not in the end PR, I spotted it late and removed it in [this commit] (5fcca31)

Copy link
Contributor

Choose a reason for hiding this comment

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

All good! Thank you. I figured it was a copy/paste thing.. and I appreciate you keeping to the style of the existing commands!

Copy link
Contributor

@nilslice nilslice left a comment

Choose a reason for hiding this comment

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

@olliephillips - this is fantastic. thank you for the work you put here. if you could make the edits as per the comments and lmk what you think about GOPATH resolution since 1.8 changes it will help a lot to get this merged. I am on the road until later tonight, but will be able to check in if you have issues.

@olliephillips
Copy link
Contributor Author

This is what I had in mind for GOPATH resolution

// resolve GOPATH. In 1.8 can be default, or custom. A custom GOPATH can
// also contain multiple paths, in which case 'go get' uses the first
func getGOPATH() (string, error) {
	var gopath string
	gopath = os.Getenv("GOPATH")
	if gopath == "" {
		// not set, find the default
		usr, err := user.Current()
		if err != nil {
			return gopath, err
		}
		gopath = filepath.Join(usr.HomeDir, "go")
	} else {
		// parse out in case of multiple, retain first
		gopaths := strings.Split(gopath, ":") // Linux
		gopath = gopaths[0]
		gopaths = strings.Split(gopath, ";") // Windows
		gopath = gopaths[0]
	}
	return gopath, nil
}

@sirikon
Copy link

sirikon commented Feb 27, 2017

@olliephillips That script could have the same problem I commented you in the code.

@nilslice
Copy link
Contributor

@sirikon - could you link me to the comment / line in the code you mention? I can't find it.

@sirikon
Copy link

sirikon commented Feb 27, 2017

@nilslice
Copy link
Contributor

@sirikon - sorry, I meant the link to your comment that you left about:

That script could have the same problem I commented you in the code.

I don't see any comment there, maybe I'm just missing it..

@sirikon
Copy link

sirikon commented Feb 28, 2017

@nilslice
Copy link
Contributor

@sirikon - odd, this is what I see when clicking your link. No comment from you on the whole PR..
screenshot from 2017-02-28 02 38 40

Would you mind copying the comment you made and the line # you're referencing so I can understand what the issue is?

Thanks & sorry for the inconvenience.. really not sure why I can't see the comment

@sirikon
Copy link

sirikon commented Feb 28, 2017

For god sake Github X_X.

Sorry guys, here it is: Line 62-69 of file add.go
image

@olliephillips
Copy link
Contributor Author

@sirikon That's a good point re : in windows path. Probably this could work without OS check if ; checked first and then branch out - so no second test. I'll look at that.

Before I do could I have comments on the revised func above, which attempts to resolve a default GOPATH.

@sirikon
Copy link

sirikon commented Feb 28, 2017

The rest of the script seems perfect for me :)

@olliephillips
Copy link
Contributor Author

Needed an OS check in end. Hopefully, this should reliably get GOPATH or the default. At least for Windows/Linux/Mac. If agreed I'll update the PR.

// resolve GOPATH. In 1.8 can be default, or custom. A custom GOPATH can
// also contain multiple paths, in which case 'go get' uses the first
func getGOPATH() (string, error) {
	var gopath string
	gopath = os.Getenv("GOPATH")
	if gopath == "" {
		// not set, find the default
		usr, err := user.Current()
		if err != nil {
			return gopath, err
		}
		gopath = filepath.Join(usr.HomeDir, "go")
	} else {
		// parse out in case of multiple, retain first
		if runtime.GOOS == "windows" {
			gopaths := strings.Split(gopath, ";")
			gopath = gopaths[0]
		} else {
			gopaths := strings.Split(gopath, ":")
			gopath = gopaths[0]
		}
	}
	return gopath, nil
}

@sirikon
Copy link

sirikon commented Feb 28, 2017

Seems okay for me :)

@nilslice
Copy link
Contributor

@sirikon - thank you for adding that, sorry it was pending.. not sure how to approve those things

@olliephillips - that looks good to me, go ahead and update the PR at your convenience.

Thanks!

@olliephillips
Copy link
Contributor Author

@nilslice That has been added to the PR. I've run through the ponzu build process again and seems ok to me

cmd/ponzu/add.go Outdated
gopaths = strings.Split(envGOPATH, ";")
gopath = gopaths[0]
return gopath
}
Copy link

Choose a reason for hiding this comment

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

Does this method work correctly?
(Didn't knew GOPATH could be multiple directories by the way, interesting)

Copy link

Choose a reason for hiding this comment

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

I mean... This will only work in Windows, because 'gopath' var is overwritten.

Also, making the split by ":" and by ";" without checking what's the OS Host is tricky, for example, in Windows ":" is used to define drive letters (Like in the path C:\Users\Whatever)

Copy link
Contributor

@nilslice nilslice left a comment

Choose a reason for hiding this comment

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

Thank you! Looks good. Will just run through some tests and merge.

@nilslice
Copy link
Contributor

nilslice commented Mar 1, 2017

@olliephillips, thank you for adding this. I think it will be a really big help to make addons a major component of Ponzu systems.

@sirikon, thank you for your continued involvement and testing!

I really appreciate all of your help.

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