adding lock command, generalizing the checkfiletypes function
This commit is contained in:
		@@ -9,7 +9,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
//AddFiles adds files to the repo, inputType specifies file, folder, wildcard or all
 | 
			
		||||
func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error {
 | 
			
		||||
func AddFiles(input string, inputType string, ignore clientconfig.FileTypes) error {
 | 
			
		||||
	err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
@@ -25,7 +25,7 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("unable to add file %s", err)
 | 
			
		||||
		}
 | 
			
		||||
		err = checkIgnores(input, "file", ignore)
 | 
			
		||||
		err = checkFileTypes(input, "file", ignore)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return fmt.Errorf("unable to add file as it (or ext) is on the ignores list %s", input)
 | 
			
		||||
		}
 | 
			
		||||
@@ -49,9 +49,9 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
 | 
			
		||||
				return fmt.Errorf("failure accessing path %s", err)
 | 
			
		||||
			}
 | 
			
		||||
			if info.IsDir() {
 | 
			
		||||
				err = checkIgnores(currentFile, "folder", ignore)
 | 
			
		||||
				err = checkFileTypes(currentFile, "folder", ignore)
 | 
			
		||||
			} else {
 | 
			
		||||
				err = checkIgnores(currentFile, "file", ignore)
 | 
			
		||||
				err = checkFileTypes(currentFile, "file", ignore)
 | 
			
		||||
			}
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
 | 
			
		||||
@@ -72,7 +72,7 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
 | 
			
		||||
		} else {
 | 
			
		||||
			wildcard = input
 | 
			
		||||
		}
 | 
			
		||||
		err := checkIgnores(wildcard, "wildcard", ignore)
 | 
			
		||||
		err := checkFileTypes(wildcard, "wildcard", ignore)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return err
 | 
			
		||||
		}
 | 
			
		||||
@@ -82,9 +82,9 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
 | 
			
		||||
				return fmt.Errorf("failure accessing path %s", err)
 | 
			
		||||
			}
 | 
			
		||||
			if info.IsDir() {
 | 
			
		||||
				err = checkIgnores(currentFile, "folder", ignore)
 | 
			
		||||
				err = checkFileTypes(currentFile, "folder", ignore)
 | 
			
		||||
			} else {
 | 
			
		||||
				err = checkIgnores(currentFile, "file", ignore)
 | 
			
		||||
				err = checkFileTypes(currentFile, "file", ignore)
 | 
			
		||||
			}
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
 | 
			
		||||
@@ -108,9 +108,9 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
 | 
			
		||||
				return fmt.Errorf("failure accessing path %s", err)
 | 
			
		||||
			}
 | 
			
		||||
			if info.IsDir() {
 | 
			
		||||
				err = checkIgnores(currentFile, "folder", ignore)
 | 
			
		||||
				err = checkFileTypes(currentFile, "folder", ignore)
 | 
			
		||||
			} else {
 | 
			
		||||
				err = checkIgnores(currentFile, "file", ignore)
 | 
			
		||||
				err = checkFileTypes(currentFile, "file", ignore)
 | 
			
		||||
			}
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				fmt.Printf("Not adding file %s as it is on the ingores list \n", currentFile)
 | 
			
		||||
@@ -145,48 +145,3 @@ func checkRemotesSlice(name, host string, port int, remotes []clientconfig.Remot
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// AddRemote adds a remote to the config file
 | 
			
		||||
func AddRemote(name string, host string, port int, defaultRemote bool, remotes []clientconfig.Remote) (newRemotes []clientconfig.Remote, err error) {
 | 
			
		||||
	if len(remotes) == 0 { //first remote no need to check for duplicates and will set this remote as default
 | 
			
		||||
		newRemote := clientconfig.Remote{
 | 
			
		||||
			Name:    name,
 | 
			
		||||
			Host:    host,
 | 
			
		||||
			Port:    port,
 | 
			
		||||
			Default: true,
 | 
			
		||||
		}
 | 
			
		||||
		remotes = append(remotes, newRemote)
 | 
			
		||||
		fmt.Printf("Remote added: Name: %s Host: %s, Port: %d, Default: %t", name, host, port, defaultRemote)
 | 
			
		||||
		return remotes, nil
 | 
			
		||||
	}
 | 
			
		||||
	err = checkRemotesSlice(name, host, port, remotes)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return remotes, err
 | 
			
		||||
	}
 | 
			
		||||
	if defaultRemote { // If the new repo was flagged as default, find old default and remove it
 | 
			
		||||
		for i, remote := range remotes {
 | 
			
		||||
			if remote.Default {
 | 
			
		||||
				remotes[i].Default = false
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		newRemote := clientconfig.Remote{
 | 
			
		||||
			Name:    name,
 | 
			
		||||
			Host:    host,
 | 
			
		||||
			Port:    port,
 | 
			
		||||
			Default: true,
 | 
			
		||||
		}
 | 
			
		||||
		remotes = append(remotes, newRemote)
 | 
			
		||||
		fmt.Printf("Remote added: Name: %s Host: %s, Port: %d, Default: %t", name, host, port, defaultRemote)
 | 
			
		||||
		return remotes, nil
 | 
			
		||||
	}
 | 
			
		||||
	// If passes all checks and is not default, create it and add it
 | 
			
		||||
	newRemote := clientconfig.Remote{
 | 
			
		||||
		Name:    name,
 | 
			
		||||
		Host:    host,
 | 
			
		||||
		Port:    port,
 | 
			
		||||
		Default: false,
 | 
			
		||||
	}
 | 
			
		||||
	remotes = append(remotes, newRemote)
 | 
			
		||||
	fmt.Printf("Remote added: Name: %s Host: %s, Port: %d, Default: %t", name, host, port, defaultRemote)
 | 
			
		||||
	return remotes, nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user