working on initing a repo, more work on 'add' command

This commit is contained in:
2020-05-27 22:54:02 -04:00
parent 2d743d17c3
commit 9b017f3128
8 changed files with 93 additions and 30 deletions

View File

@@ -3,12 +3,17 @@ package config
import (
"fmt"
"os"
"github.com/deranjer/store"
)
// ConfigPath is the global path to the config that is injected from the main client package.
var ConfigPath string
// ValidateConfig will go through the entire config and do basic sanity checks
func ValidateConfig(conf *Gvcconfig, version string) error {
if conf.Version == "" { // No version found, should we update it?
fmt.Printf("No version found, inputing current client version: %s", version)
fmt.Printf("No version found, inputing current client version: %s\n", version)
conf.Version = version
}
if conf.RootPath == "" {
@@ -16,7 +21,7 @@ func ValidateConfig(conf *Gvcconfig, version string) error {
if err != nil {
return fmt.Errorf("unable to get current working directory, and rootpath of repo is not set: %s", err)
}
fmt.Printf("No root path found, inputting current working directory: %s", path)
fmt.Printf("No root path found, inputting current working directory: %s\n", path)
}
err := validateRemotes(conf)
if err != nil {
@@ -37,9 +42,9 @@ func validateCompress(conf *Gvcconfig) error {
if file == "" {
fmt.Println("empty file in compress files, removing... ")
compress.Files[i] = compress.Files[len(compress.Files)-1]
continue
}
// TODO: write more validation
return nil
}
for i, folder := range compress.Folders {
file, err := os.Stat(folder) // TODO: check to see if it returns ABS or not, might need to convert
@@ -64,6 +69,10 @@ func validateCompress(conf *Gvcconfig) error {
}
// TODO: validate there is a "." in front of the ext, if not add it?
}
err := store.Save(ConfigPath, &conf)
if err != nil {
fmt.Println("Error saving config back to toml file: ", err)
}
return nil
}