working on lock command
This commit is contained in:
		@@ -5,6 +5,7 @@ import (
 | 
			
		||||
 | 
			
		||||
	clientconfig "github.com/deranjer/gvc/client/clientconfig"
 | 
			
		||||
	"github.com/deranjer/gvc/common"
 | 
			
		||||
	"github.com/go-resty/resty/v2"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
//LockFiles locks file(s)/folder based on name/wildcard, etc
 | 
			
		||||
@@ -14,7 +15,8 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	locked := conf.Locked
 | 
			
		||||
	switch inputType { // TODO: add default case for generic error handling
 | 
			
		||||
	connectionString, err := FindServer("", conf.CurrentBranch, conf) //TODO: Maybe allow user to specify lock server? Seems like they should just use the default server though
 | 
			
		||||
	switch inputType {                                                // TODO: add default case for generic error handling // TODO: there is no user supplied input here, so WHY?
 | 
			
		||||
	case "file":
 | 
			
		||||
		err := common.CheckFileTypes(input, "file", locked)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
@@ -22,6 +24,10 @@ func LockFiles(input string, inputType string, conf *clientconfig.Gvcconfig) err
 | 
			
		||||
		}
 | 
			
		||||
		fmt.Println("Adding file to locked: ", input)
 | 
			
		||||
		conf.Locked.Files = append(conf.Locked.Files, input)
 | 
			
		||||
		err = SendLockToServer(connectionString, conf.RepoName, "file", input)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("error sending lock to server: %s", err)
 | 
			
		||||
		}
 | 
			
		||||
		return nil
 | 
			
		||||
	case "folder":
 | 
			
		||||
		err := common.CheckFileTypes(input, "folder", locked)
 | 
			
		||||
@@ -109,3 +115,26 @@ func RemoveLockFiles(input string, inputType string, conf *clientconfig.Gvcconfi
 | 
			
		||||
	}
 | 
			
		||||
	return fmt.Errorf("This... should not have happened, some kind of internal error on RemoveLockFiles function call, switch failure")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SendLockToServer sends an updated lock file to the server
 | 
			
		||||
func SendLockToServer(connectionString string, repoName string, fileType string, fileName string) error {
 | 
			
		||||
	client := resty.New()
 | 
			
		||||
	resp, err := client.R().
 | 
			
		||||
		SetPathParams(map[string]string{
 | 
			
		||||
			"repoName": repoName,
 | 
			
		||||
			"type":     fileType,
 | 
			
		||||
			"name":     fileName,
 | 
			
		||||
		}).
 | 
			
		||||
		Get(connectionString + "/lock/" + "{repoName}/" + "{type}/" + "{name}") //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("response not a success: %d: connection URL: %s", resp.StatusCode(), resp.Request.URL)
 | 
			
		||||
	}
 | 
			
		||||
	fmt.Println(resp)
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user