Skip to content

Commit

Permalink
feat: rules file path flag
Browse files Browse the repository at this point in the history
  • Loading branch information
doron-cohen committed Oct 15, 2020
1 parent ccbe740 commit 7f6d912
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion cmd/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var cleanCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
log.Println("Cleaning up!")

_, err := rules.LoadRulesConfig("rules.yaml")
_, err := rules.LoadRulesConfig(rulesFilePath)
if err != nil {
log.Fatalln("Failed to read rules file: ", err)
}
Expand Down
8 changes: 8 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ import (
"os"

"github.com/spf13/cobra"

"github.com/doron-cohen/antidot/internal/utils"
)

var rulesFilePath string

var rootCmd = &cobra.Command{
Use: "antidot",
Short: "Clean your $HOME from those pesky dotfiles",
Run: func(cmd *cobra.Command, args []string) {
},
}

func init() {
rootCmd.PersistentFlags().StringVarP(&rulesFilePath, "rules", "r", utils.GetRulesFilePath(), "Rules file path")
}

func Execute(appVersion string) {
rootCmd.Version = appVersion
if err := rootCmd.Execute(); err != nil {
Expand Down
6 changes: 5 additions & 1 deletion internal/utils/appdirs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ func (a appDirs) DataHome() string {
return filepath.Join(xdg.DataHome, a.AppName)
}

func (a appDirs) GetDataFilePath(fileName string) string {
return filepath.Join(a.DataHome(), fileName)
}

func (a appDirs) GetDataFile(fileName string) (string, error) {
relPath := filepath.Join(a.AppName, fileName)
relPath := a.GetDataFilePath(fileName)
return xdg.DataFile(relPath)
}

Expand Down
4 changes: 4 additions & 0 deletions internal/utils/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ func GetAliasFile() (string, error) {
func GetEnvFile() (string, error) {
return AppDirs.GetDataFile("env.sh")
}

func GetRulesFilePath() string {
return AppDirs.GetDataFilePath("rules.yaml")
}

0 comments on commit 7f6d912

Please sign in to comment.