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

Create ~/.config/afx if not exist #60

Merged
merged 2 commits into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ func (m *metaCmd) init() error {
cfgRoot := filepath.Join(os.Getenv("HOME"), ".config", "afx")
cache := filepath.Join(root, "cache.json")

err := config.CreateDirIfNotExist(cfgRoot)
if err != nil {
return errors.Wrapf(err, "%s: failed to create dir", cfgRoot)
}
files, err := config.WalkDir(cfgRoot)
Copy link
Owner

@babarot babarot May 18, 2023

Choose a reason for hiding this comment

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

Indent looks wrong. Please run go fmt.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I fixed. Sorry for the inconvenience.

if err != nil {
return errors.Wrapf(err, "%s: failed to walk dir", cfgRoot)
Expand Down
10 changes: 10 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ func visitYAML(files *[]string) filepath.WalkFunc {
}
}

func CreateDirIfNotExist(path string) error {
_, err := os.Stat(path)
if os.IsNotExist(err) {
return os.MkdirAll(path, 0755)
} else if err != nil {
return err
}
return nil
}

func resolvePath(path string) (string, bool, error) {
fi, err := os.Lstat(path)
if err != nil {
Expand Down