diff --git a/cmd/commands.go b/cmd/commands.go index 1c8f799..cf1a6d4 100644 --- a/cmd/commands.go +++ b/cmd/commands.go @@ -44,7 +44,7 @@ func Add(args []string) error { } filename := filepath.Base(sourcePath) - destinationPath = filepath.Join(config.InitDirectory, filename) + destinationPath = filepath.Join(config.Configuration.InitDirectory, filename) case 2: // set first and second args as source and destination path, get absolute diff --git a/pkg/config/config.go b/pkg/config/config.go index a81a4d5..f7866e8 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -17,9 +17,7 @@ import ( var ( HomeDirectory string - InitDirectory string ConfigPath string - ConfigName string Configuration appConfig ) @@ -33,12 +31,32 @@ type record struct { Paths []string `yaml:"paths"` } +func SetupDirectories() error { + var err error + HomeDirectory, err = os.UserHomeDir() + if err != nil { + return fmt.Errorf("Couldn't get the home directory") + } + + ConfigName := ".linksym.yaml" + ConfigPath = filepath.Join(Configuration.InitDirectory, ConfigName) + + return nil +} + func InitialiseConfig() error { err := SetupDirectories() if err != nil { return fmt.Errorf("Initialising Env: \n%w", err) } + InitDirectory, err := os.Getwd() + if err != nil { + return fmt.Errorf("Couldn't get the current working directory") + } + + InitDirectory = aliasPath(InitDirectory, true) + configuration := appConfig{ InitDirectory: InitDirectory, Records: []record{}, diff --git a/pkg/config/utils.go b/pkg/config/utils.go index a59fbea..0f9c285 100644 --- a/pkg/config/utils.go +++ b/pkg/config/utils.go @@ -4,28 +4,9 @@ import ( "errors" "fmt" "os" - "path/filepath" "strings" ) -func SetupDirectories() error { - var err error - HomeDirectory, err = os.UserHomeDir() - if err != nil { - return errors.New("Couldn't get the home directory") - } - - InitDirectory, err = os.Getwd() - if err != nil { - return errors.New("Couldn't get the current working directory") - } - - ConfigName := ".linksym.yaml" - - ConfigPath = filepath.Join(InitDirectory, ConfigName) - return nil -} - func CheckFile(path string) (bool, os.FileInfo, error) { fileInfo, err := os.Stat(path) if err != nil {