some optimization for add files
This commit is contained in:
@@ -51,6 +51,9 @@ func main() {
|
|||||||
// Adding all the "add" commands
|
// Adding all the "add" commands
|
||||||
addCommands(cli, &conf)
|
addCommands(cli, &conf)
|
||||||
|
|
||||||
|
// Adding the ignore commands
|
||||||
|
ignoreCommands(cli, &conf)
|
||||||
|
|
||||||
err = cli.Run()
|
err = cli.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Error occurred: %v\n", err)
|
fmt.Printf("Error occurred: %v\n", err)
|
||||||
@@ -181,3 +184,56 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ignoreCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||||
|
//All the ignore commands and subcommands
|
||||||
|
//The ignore subcommand
|
||||||
|
ignoreCmd := cli.NewSubCommand("ignore", "ignores file(s)/folder(s) (recursively for folder) to repo")
|
||||||
|
ignoreCmd.LongDescription("You can ignore all: all, a -file (-f): file.txt, or a -folder (-fd): folder, or a -wildcard (-wc): *.txt")
|
||||||
|
//File/Folder/Wildcard Ignoring
|
||||||
|
var file string
|
||||||
|
var folder string
|
||||||
|
var wildcard string
|
||||||
|
fileFlag := ignoreCmd.StringFlag("file", "adds a file to ignore to the config", &file)
|
||||||
|
fileFlag.FlagShortCut("file", "f")
|
||||||
|
folderFlag := ignoreCmd.StringFlag("folder", "tracks all contents of a folder to ignore", &folder)
|
||||||
|
folderFlag.FlagShortCut("folder", "fd")
|
||||||
|
wildCardFlag := ignoreCmd.StringFlag("wildcard", "treats the input as a wildcard and ignores all files that match the wildcard", &wildcard)
|
||||||
|
wildCardFlag.FlagShortCut("wildcard", "wc")
|
||||||
|
ignoreCmd.Action(func() error {
|
||||||
|
isRepo := validateRepo()
|
||||||
|
if !isRepo {
|
||||||
|
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
if len(ignoreCmd.OtherArgs()) > 0 {
|
||||||
|
ignoreCmd.PrintHelp()
|
||||||
|
return fmt.Errorf("incorrect input detected, please fix and retry")
|
||||||
|
}
|
||||||
|
if file != "" { // if the file flag was used it won't be empty
|
||||||
|
fmt.Println("Ignoring file to tracked files: ", file)
|
||||||
|
err := clientcmd.IgnoreFiles(file, "file", conf.Ignores)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if folder != "" { // if the folder flag was used it won't be empty
|
||||||
|
fmt.Println("Ignoring contents of folder to tracked files: ", folder)
|
||||||
|
err := clientcmd.IgnoreFiles(folder, "folder", conf.Ignores)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if wildcard != "" { // if the wildcard flag was used it won't be empty
|
||||||
|
fmt.Println("Ignoring files with wildcard filter: ", wildcard)
|
||||||
|
err := clientcmd.IgnoreFiles(wildcard, "wildcard", conf.Ignores)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,9 +10,13 @@ import (
|
|||||||
|
|
||||||
//AddFiles adds files to the repo, inputType specifies file, folder, wildcard or all
|
//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.Ignore) error {
|
||||||
|
workingDir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
var trackedFiles []string
|
var trackedFiles []string
|
||||||
switch inputType {
|
switch inputType {
|
||||||
case "file":
|
case "file": // If the -file flag was used, then make sure it is a file, make sure not on ignore list, then add it to tracked files
|
||||||
_, err := os.Stat(input)
|
_, err := os.Stat(input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to add file %s", err)
|
return fmt.Errorf("unable to add file %s", err)
|
||||||
@@ -21,10 +25,6 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to add file as it (or ext) is on the ignores list %s", input)
|
return fmt.Errorf("unable to add file as it (or ext) is on the ignores list %s", input)
|
||||||
}
|
}
|
||||||
workingDir, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
relativePath, err := filepath.Rel(workingDir, input)
|
relativePath, err := filepath.Rel(workingDir, input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to create relative path for file: %s", err)
|
return fmt.Errorf("unable to create relative path for file: %s", err)
|
||||||
@@ -39,10 +39,6 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
|
|||||||
if !folder.IsDir() {
|
if !folder.IsDir() {
|
||||||
return fmt.Errorf("file exists, but is not a folder %s", err)
|
return fmt.Errorf("file exists, but is not a folder %s", err)
|
||||||
}
|
}
|
||||||
workingDir, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
filepath.Walk(input, func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(input, func(path string, info os.FileInfo, err error) error {
|
||||||
currentFile := filepath.Base(path)
|
currentFile := filepath.Base(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -66,7 +62,6 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
case "wildcard":
|
case "wildcard":
|
||||||
fmt.Println("First char, ", input[:1])
|
|
||||||
var wildcard string
|
var wildcard string
|
||||||
if input[:1] == "*" { // Removing the wildcard char since we don't store that or test with that char
|
if input[:1] == "*" { // Removing the wildcard char since we don't store that or test with that char
|
||||||
wildcard = input[1:]
|
wildcard = input[1:]
|
||||||
@@ -77,10 +72,6 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
workingDir, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
|
||||||
currentFile := filepath.Base(path) // Stripping all the pathing so we just get the filename
|
currentFile := filepath.Base(path) // Stripping all the pathing so we just get the filename
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -107,10 +98,6 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
case "all":
|
case "all":
|
||||||
workingDir, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(workingDir, func(path string, info os.FileInfo, err error) error {
|
||||||
currentFile := filepath.Base(path)
|
currentFile := filepath.Base(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -136,8 +123,7 @@ func AddFiles(input string, inputType string, ignore clientconfig.Ignore) error
|
|||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
fmt.Println("Added tracked files", trackedFiles) // Print out all the new tracked files
|
||||||
fmt.Println("Added tracked files", trackedFiles)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,12 @@ package clientcmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
|
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
||||||
)
|
)
|
||||||
|
|
||||||
//IgnoreFiles ignores file(s)/folder based on name/wildcard, etc
|
//IgnoreFiles ignores file(s)/folder based on name/wildcard, etc
|
||||||
func IgnoreFiles() error {
|
func IgnoreFiles(input string, inputType string, ignore clientconfig.Ignore) error {
|
||||||
fmt.Println("File/folder/wildcard to ignore", os.Args[2])
|
fmt.Println("File/folder/wildcard to ignore", os.Args[2])
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user