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

Do not pollute home dir #21

Merged
merged 3 commits into from
Aug 18, 2023
Merged

Do not pollute home dir #21

merged 3 commits into from
Aug 18, 2023

Conversation

mmlb
Copy link
Member

@mmlb mmlb commented Jul 28, 2023

Lets be good cli folks and not pollute a user's $HOME, instead lets put config files in platform specified config paths. ~/.mctl.yml is used if it exists otherwise we look in dirs provided by xdg package.

@mmlb mmlb marked this pull request as draft July 28, 2023 17:19
@mmlb
Copy link
Member Author

mmlb commented Jul 28, 2023

This is ready to go but I made it draft until #20 is merged as this depends on it.

@mmlb mmlb marked this pull request as ready for review August 14, 2023 15:34
Otherwise use xdg which is smart about giving us the platform specific cache
dir. See https://github.com/adrg/xdg#xdg-base-directory for values used.
joelrebel
joelrebel previously approved these changes Aug 16, 2023
Copy link
Member

@joelrebel joelrebel left a comment

Choose a reason for hiding this comment

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

LGTM

cmd/root.go Outdated
@@ -45,6 +45,6 @@ func Execute() {
}

func init() {
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.mctl.yml)")
RootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $XDG_CACHE_DIR/mctl/config.yml)")
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be $XDG_CONFIG_HOME instead? According to the spec https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html, it's where the user config files should be located. This env var wouldn't be used on a Mac environment, AFAICT.

Copy link
Member Author

Choose a reason for hiding this comment

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

1000% right... will fix

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed, PTAL again thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

This env var wouldn't be used on a Mac environment, AFAICT.

The go package I'm using here basically does the right thing for other platforms too:

Unix-like operating systems

Unix macOS Plan 9
XDG_CONFIG_HOME ~/.config ~/Library/Application Support $home/lib

Microsoft Windows

Known Folder(s) Fallback(s)
XDG_CONFIG_HOME LocalAppData %LOCALAPPDATA%

Copy link
Contributor

Choose a reason for hiding this comment

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

Not quite right still, diff shows $XDG_CONFIG_DIR while it should be $XDG_CONFIG_HOME.

Good to know it works everywhere! Thanks for the fixes!

Copy link
Member Author

Choose a reason for hiding this comment

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

thats what I get when I sed w/o thinking :/

Copy link
Member Author

Choose a reason for hiding this comment

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

@diogomatsubara ptal again, thanks!

@mmlb
Copy link
Member Author

mmlb commented Aug 18, 2023

🎉

@mmlb mmlb merged commit 3b3764f into main Aug 18, 2023
9 checks passed
@mmlb mmlb deleted the do-not-pollute-home-dir branch August 18, 2023 14:46
@mmlb
Copy link
Member Author

mmlb commented Aug 18, 2023

uggh I very much dislike that merge commits aren't allowed in this org

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