planetscale/cli

[Feature Request] project level config

robotkutya opened this issue · 7 comments

We can currently set our default org in ~/.config/planetscale/pscale.yml however I did not find a way to set your organization on a project (git repo) level.

It would be cool to have a local setting that takes precedence, similar to how e.g. .nvmrc sets the node version for the directory.

I understand I can use the --org flag, but that's still easy to mix up when working on multiple projects in multiple orgs.

If you use pscale inside a Git repository, we already should do this automatically for you. See also:

// ProjectConfigPath returns the path of a configuration inside a Git
// repository.
func ProjectConfigPath() (string, error) {
basePath, err := RootGitRepoDir()
if err == nil {
return filepath.Join(basePath, projectConfigName), nil
}
return filepath.Join("", projectConfigName), nil
}
func RootGitRepoDir() (string, error) {
tl := []string{"rev-parse", "--show-toplevel"}
out, err := exec.Command("git", tl...).CombinedOutput()
if err != nil {
return "", errors.New("unable to find git root directory")
}
return strings.TrimSuffix(string(out), "\n"), nil
}

Is that not working for you?

Nope :(

Maybe I'm missing something obvious, but can you give me a super stupid example how this would look like?
So if I am in the git repo root, where should I put the config exactly with what path?

@robotkutya You can use the pscale inside the repo to set the default org. So like:

~/project/dir $ pscale org switch <wanted-org>

That will store a .pscale.yml in the ~/project/dir. It looks something like this:

org: <wanted-org>

If you then run pscale org show you'll see the value and where it's stored:

~/project/dir $ pscale org show
<wanted-org> (from file:~/project/dir/.pscale.yml)

@dbussink it works, thank you!

Is this documented anywhere? I tried pscale.yml in my project (notice the missing dot) and that made sense to me since it matches the pattern ~/.config/planetscale/pscale.yml

An extra sentence in the docs here would be really helpful IMHO.

An extra sentence in the docs here would be really helpful IMHO.

Would you be willing to open an issue for this on https://github.com/planetscale/docs/issues? So we can track it there as a documentation improvement? Something along the line of "document per project settings for the CLI"?

Would you be willing to open an issue for this on https://github.com/planetscale/docs/issues? So we can track it there as a documentation improvement? Something along the line of "document per project settings for the CLI"?

Thnx! Closing this one in favor of the docs issue.