Skip to content

Commit

Permalink
Change AliasConfig and ExpandConfig functions to methods and update r…
Browse files Browse the repository at this point in the history
…eferences
  • Loading branch information
SwayKh committed Oct 3, 2024
1 parent 0d5e075 commit 8c89c93
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"fmt"
"os"
"path/filepath"
)

Expand Down Expand Up @@ -46,7 +48,7 @@ func (c *AppConfig) RemoveRecord(name string) {
}

// Un-Alias all paths with ~ and $init_directory with full absolute paths
func UnAliasConfig(configuration *AppConfig) {
func (configuration *AppConfig) UnAliasConfig() {
configuration.InitDirectory = ExpandPath(configuration.InitDirectory)

for i, v := range configuration.Records {
Expand All @@ -57,7 +59,7 @@ func UnAliasConfig(configuration *AppConfig) {
}

// Alias all mentions of HomeDirectory and InitDirectory with ~ and $init_directory
func AliasConfig(configuration *AppConfig) {
func (configuration *AppConfig) AliasConfig() {
configuration.InitDirectory = AliasPath(configuration.InitDirectory, true)

// Alias path absolute paths before writing to config file
Expand Down
2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func InitialiseConfig(configPath string) error {
Records: []record{},
}

AliasConfig(&configuration)
configuration.AliasConfig()
data, err := yaml.Marshal(configuration)
if err != nil {
return fmt.Errorf("Error marshalling data from configuration{}: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion io.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func LoadConfig(configPath string) (*AppConfig, error) {

// Write the Configuration struct data to .linksym.yaml file
func WriteConfig(configuration *AppConfig) error {
AliasConfig(configuration)
configuration.AliasConfig()
data, err := yaml.Marshal(configuration)
if err != nil {
return fmt.Errorf("Error marshalling data from configuration{}: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func Update(configuration *AppConfig) error {
// Alias config, to be allow expanding the $init_directory variable with the
// new InitDirectory
AliasConfig(configuration)
configuration.AliasConfig()

VerboseLog("Updating .linksym.yaml file...")

Expand Down

0 comments on commit 8c89c93

Please sign in to comment.