Commit 34f5709242

34f57092423909f1b7dfb773df32882f62aaa1f2

parent: d8d078535a

Unsigned

Wraient <wraient.911@gmail.com> · 2025-07-23 17:50 UTC

Mod: Make functions public

Layout: unified · split

internal/config.go +10 −10
@@ -110,7 +110,7 @@ func LoadConfig(configPath string) (CurdConfig, error) {
110 } 110 }
111 111
112 // Load the config from file 112 // Load the config from file
113 configMap, err := loadConfigFromFile(configPath) 113 configMap, err := LoadConfigFromFile(configPath)
114 if err != nil { 114 if err != nil {
115 return CurdConfig{}, fmt.Errorf("error loading config file: %v", err) 115 return CurdConfig{}, fmt.Errorf("error loading config file: %v", err)
116 } 116 }
@@ -133,7 +133,7 @@ func LoadConfig(configPath string) (CurdConfig, error) {
133 133
134 // Write updated config back to file only if AddMissingOptions is true 134 // Write updated config back to file only if AddMissingOptions is true
135 if addMissing && updated { 135 if addMissing && updated {
136 if err := saveConfigToFile(configPath, configMap); err != nil { 136 if err := SaveConfigToFile(configPath, configMap); err != nil {
137 return CurdConfig{}, fmt.Errorf("error saving updated config file: %v", err) 137 return CurdConfig{}, fmt.Errorf("error saving updated config file: %v", err)
138 } 138 }
139 } 139 }
@@ -144,7 +144,7 @@ func LoadConfig(configPath string) (CurdConfig, error) {
144 } 144 }
145 145
146 // Populate the CurdConfig struct from the config map 146 // Populate the CurdConfig struct from the config map
147 config := populateConfig(configMap) 147 config := PopulateConfig(configMap)
148 148
149 return config, nil 149 return config, nil
150} 150}
@@ -249,8 +249,8 @@ func ChangeToken(config *CurdConfig, user *User) {
249 WriteTokenToFile(user.Token, tokenPath) 249 WriteTokenToFile(user.Token, tokenPath)
250} 250}
251 251
252// Load config file from disk into a map (key=value format) 252// LoadConfigFromFile loads config file from disk into a map (key=value format)
253func loadConfigFromFile(path string) (map[string]string, error) { 253func LoadConfigFromFile(path string) (map[string]string, error) {
254 file, err := os.Open(path) 254 file, err := os.Open(path)
255 if err != nil { 255 if err != nil {
256 return nil, err 256 return nil, err
@@ -281,8 +281,8 @@ func loadConfigFromFile(path string) (map[string]string, error) {
281 return configMap, nil 281 return configMap, nil
282} 282}
283 283
284// Save updated config map to file in key=value format 284// SaveConfigToFile saves updated config map to file in key=value format
285func saveConfigToFile(path string, configMap map[string]string) error { 285func SaveConfigToFile(path string, configMap map[string]string) error {
286 file, err := os.Create(path) 286 file, err := os.Create(path)
287 if err != nil { 287 if err != nil {
288 return err 288 return err
@@ -299,8 +299,8 @@ func saveConfigToFile(path string, configMap map[string]string) error {
299 return writer.Flush() 299 return writer.Flush()
300} 300}
301 301
302// Populate the CurdConfig struct from a map 302// PopulateConfig populates the CurdConfig struct from a map
303func populateConfig(configMap map[string]string) CurdConfig { 303func PopulateConfig(configMap map[string]string) CurdConfig {
304 config := CurdConfig{} 304 config := CurdConfig{}
305 configValue := reflect.ValueOf(&config).Elem() 305 configValue := reflect.ValueOf(&config).Elem()
306 306
@@ -334,7 +334,7 @@ func populateConfig(configMap map[string]string) CurdConfig {
334 return config 334 return config
335} 335}
336 336
337func getOrderedCategories(userCurdConfig *CurdConfig) map[string]string { 337func getOrderedCategories(userCurdConfig *CurdConfig) []SelectionOption {
338 // Define the default categories and their labels 338 // Define the default categories and their labels
339 defaultOrder := []string{"CURRENT", "ALL", "UNTRACKED", "UPDATE", "CONTINUE_LAST"} 339 defaultOrder := []string{"CURRENT", "ALL", "UNTRACKED", "UPDATE", "CONTINUE_LAST"}
340 defaultLabels := map[string]string{ 340 defaultLabels := map[string]string{