These are chat archives for nelsam/vidar

11th
Oct 2016
Kvaz1r
@Kvaz1r
Oct 11 2016 16:21
@nelsam , hello. Question about changing PR - maybe would be better make Environ as function than methods. Since this not must depend on the settings of project.
Samuel Nelson
@nelsam
Oct 11 2016 17:27
@Kvaz1r the gopath actually comes from the project; the method I was thinking about was like:
func (p Project) Environ() []string {
    return []string{
        fmt.Sprintf("GOPATH=%s", p.Gopath),
        fmt.Sprintf("PATH=%s%c%s", os.Getenv("PATH"), os.FileListSeparator, filepath.Join(p.Gopath, "bin")),
    }
}
all of the commands that shell out look for the current project first, so they could load the current project's environ when they find it
instead of inspecting the project's gopath
I'm actually wondering ... I think I might know why the current code broke on your system
if you can wait for another hour, I can get you a branch to try out
Kvaz1r
@Kvaz1r
Oct 11 2016 17:46
as far I know any program run in windows get environment which defined for current user.
so code broken as since lacks several value.
Samuel Nelson
@nelsam
Oct 11 2016 17:48
yeah, I understand; I think the reason it's broken has to do with that
I want to try something
but I can't work on it until an hour from now
Kvaz1r
@Kvaz1r
Oct 11 2016 17:54
we're not in a hurry;-)
Samuel Nelson
@nelsam
Oct 11 2016 19:22
blah, I looked in to it - I was thinking maybe I forgot to do this, but it should be fine
Samuel Nelson
@nelsam
Oct 11 2016 19:41
Ideally, we'd load os.Environ() and then add or override GOPATH with project.Gopath in the environment, as well as adding $GOPATH/bin to the PATH. I think we'd want to do something like:
func (p Project) Environ() []string {
    environ := os.Environ()
    if p.Gopath == "" {
        return environ
    }
    path := fmt.Sprintf("%s%c%s", os.Getenv("PATH"), os.FileListSeparator, filepath.Join(p.Gopath, "bin"))
    environ = replaceEnv(environ, "GOPATH", p.Gopath)
    return replaceEnv(environ, "PATH", path)
}

func replaceEnv(environ []string, key, value string) []string {
    envKey := key + "="
    env := envKey + value
    for i, v := range environ {
        if !strings.HasPrefix(v, envKey) {
            continue
        }
        environ[i] = env
        return environ
    }
    return append(environ, env)
}
but I have no way of knowing if that would work on Windows
could you give it a shot, @Kvaz1r ?