added server logging to file, added logging and formatting to info and lock commands

This commit is contained in:
2020-06-09 23:22:07 -04:00
parent 441a9ed233
commit 161843f4c8
15 changed files with 126 additions and 66 deletions

View File

@@ -469,6 +469,11 @@ func lockCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
//fmt.Println("Ignoring file: ", file)
err := clientcmd.LockFiles(file, "file", conf)
if err != nil {
fmt.Println("error occurred locking file, attempting to roll back changes...")
err := clientcmd.RemoveLockFiles(file, "file", conf)
if err != nil {
return fmt.Errorf("fatal error: unable to roll back lock file changes, issue with config: %s", err)
}
return err
}
return nil
@@ -477,6 +482,10 @@ func lockCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
fmt.Println("Ignoring contents of folder: ", folder)
err := clientcmd.LockFiles(folder, "folder", conf)
if err != nil {
err := clientcmd.RemoveLockFiles(folder, "folder", conf)
if err != nil {
return fmt.Errorf("fatal error: unable to roll back lock folder changes, issue with config: %s", err)
}
return err
}
return nil
@@ -485,6 +494,10 @@ func lockCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
fmt.Println("Ignoring files with wildcard filter: ", wildcard)
err := clientcmd.LockFiles(wildcard, "wildcard", conf)
if err != nil {
err := clientcmd.RemoveLockFiles(wildcard, "wildcard", conf)
if err != nil {
return fmt.Errorf("fatal error: unable to roll back lock wildcard changes, issue with config: %s", err)
}
return err
}
return nil

View File

@@ -19,7 +19,7 @@ func GetServerInfo(connectionString string, repoName string) error {
}
if resp.IsError() {
if resp.StatusCode() == 404 {
return fmt.Errorf("error: repo was not found on server, 404: %s", resp.Request.URL)
return fmt.Errorf("repo was not found on server, 404: %s", resp.Request.URL)
}
return fmt.Errorf("response not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
}

View File

@@ -36,6 +36,10 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
}
fmt.Println("Adding folder to locked: ", input)
conf.Locked.Folders = append(conf.Locked.Folders, input)
err = SendLockToServer(connectionString, conf.RepoName, "folder", input)
if err != nil {
return fmt.Errorf("error sending lock to server: %s", err)
}
return nil
case "wildcard":
var wildcard string
@@ -50,6 +54,10 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
}
fmt.Println("Adding wildcard to locked: ", wildcard)
conf.Locked.Exts = append(conf.Locked.Exts, wildcard)
err = SendLockToServer(connectionString, conf.RepoName, "wildcard", input)
if err != nil {
return fmt.Errorf("error sending lock to server: %s", err)
}
return nil
}
return fmt.Errorf("This... should not have happened, some kind of internal error on LockFiles function call, switch failure")
@@ -133,7 +141,7 @@ func SendLockToServer(connectionString string, repoName string, fileType string,
if resp.StatusCode() == 404 {
return fmt.Errorf("error: repo was not found on server, 404: %s", resp.Request.URL)
}
return fmt.Errorf("response not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
return fmt.Errorf("%s: response code: %d: %s", resp.Request.URL, resp.StatusCode(), resp)
}
fmt.Println(resp)
return nil

View File

@@ -4,12 +4,14 @@ import (
"fmt"
clientconfig "github.com/deranjer/gvc/client/clientconfig"
"github.com/deranjer/gvc/common"
"github.com/go-resty/resty/v2"
)
// RefreshContent gets all the new file locks and updated pulls from the server (like git fetch)
func RefreshContent(conf *clientconfig.Gvcconfig, repoName string) error { //TODO: need to change command to be able to target user specified servers
connectionString, err := FindServer("", conf.CurrentBranch, conf)
var refreshResult common.RepoRefreshRequest
if err != nil {
return err
}
@@ -18,16 +20,18 @@ func RefreshContent(conf *clientconfig.Gvcconfig, repoName string) error { //TOD
SetPathParams(map[string]string{
"repoName": repoName,
}).
Get(connectionString + "/refresh" + "{repoName}") //creating the full string to get info
SetResult(&refreshResult). // Automatically unmarshal the JSON response to our struct
Get(connectionString + "/refresh/" + "{repoName}") //creating the full string to get info
if err != nil {
return fmt.Errorf("error connecting to server at: %s: error was: %s", connectionString, err)
}
if resp.IsError() {
if resp.StatusCode() == 404 {
return fmt.Errorf("error: repo was not found on server, 404: %s", resp.Request.URL)
return fmt.Errorf("error: repo %s was not found on server, 404: %s", repoName, resp.Request.URL)
}
return fmt.Errorf("reponse not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
return fmt.Errorf("response not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
}
fmt.Println(resp)
fmt.Printf("%+v\n", refreshResult)
return nil
}

View File

@@ -2,23 +2,35 @@ package main
import (
"fmt"
"reflect"
"github.com/deranjer/clir"
"github.com/imdario/mergo"
)
func main() {
// Create new cli
cli := clir.NewCli("Other Args", "A basic example", "v0.0.1")
// Set long description
cli.LongDescription("This app shows positional arguments")
name := cli.NewSubCommand("name", "Shows your name!")
name.Action(func() error {
fmt.Printf("The remaining arguments were: %+v\n", name.OtherArgs())
return nil
})
// Run!
cli.Run()
type Foo struct {
Ignore []string
B int64
}
func main() {
src := Foo{
Ignore: []string{"one", "two", "three"},
B: 2,
}
dest := Foo{
Ignore: []string{"one", "two", "four", "seven"},
}
mergo.Merge(&dest, src, mergo.WithTransformers())
fmt.Println(dest)
// Will print
// {two 2}
}
func MergeStrings(typ reflect.Type) func(dst, src reflect.Value) error {
if typ == reflect.TypeOf([]string{}) {
return func(dst, src reflect.Value) error {
}
}
}