some optimization for add files
This commit is contained in:
@@ -51,6 +51,9 @@ func main() {
|
||||
// Adding all the "add" commands
|
||||
addCommands(cli, &conf)
|
||||
|
||||
// Adding the ignore commands
|
||||
ignoreCommands(cli, &conf)
|
||||
|
||||
err = cli.Run()
|
||||
if err != nil {
|
||||
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
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user