working on the add command
This commit is contained in:
@@ -1,21 +1,16 @@
|
|||||||
version = 1.0
|
version = "0.1.5"
|
||||||
RootPath = "client"
|
rootPath = "client"
|
||||||
|
|
||||||
[[remote]]
|
[[remote]]
|
||||||
name = "origin"
|
name = "origin"
|
||||||
host = ""
|
host = "testorigin.com"
|
||||||
port = 8694
|
port = 8694
|
||||||
|
|
||||||
[[remote]]
|
[[remote]]
|
||||||
name = "secondOrigin"
|
name = "secondOrigin"
|
||||||
host = ""
|
host = "170.5.95.195"
|
||||||
port = 4253
|
port = 4253
|
||||||
|
|
||||||
[[remote]]
|
|
||||||
name = "my new Remote"
|
|
||||||
host = "hostname.com"
|
|
||||||
port = 1234
|
|
||||||
|
|
||||||
[ignore]
|
[ignore]
|
||||||
files = ["file1.txt", "file2.txt"]
|
files = ["file1.txt", "file2.txt"]
|
||||||
exts = [".jpg", ".png"]
|
exts = [".jpg", ".png"]
|
||||||
|
@@ -32,10 +32,14 @@ func main() {
|
|||||||
|
|
||||||
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)
|
||||||
}
|
}
|
||||||
// After the cli is finished running and writing new values, then validate the input and write it back to the TOML config file
|
// After the cli is finished running and writing new values, then validate the input and write it back to the TOML config file
|
||||||
clientconfig.ValidateConfig(&conf, version)
|
err = clientconfig.ValidateConfig(&conf, version)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error validating config, no changes from the command saved! ", err)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
err = store.Save(".gvcconfigNew.toml", &conf)
|
err = store.Save(".gvcconfigNew.toml", &conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error saving config back to toml file: ", err)
|
fmt.Println("Error saving config back to toml file: ", err)
|
||||||
@@ -75,13 +79,65 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
|||||||
//All the add commands and subcommands
|
//All the add commands and subcommands
|
||||||
//The add subcommand
|
//The add subcommand
|
||||||
addCmd := cli.NewSubCommand("add", "adds file(s)/folder(s) (recursively for folder) to repo")
|
addCmd := cli.NewSubCommand("add", "adds file(s)/folder(s) (recursively for folder) to repo")
|
||||||
addCmd.LongDescription("You can add all: all, a -file: file.txt, or a -folder: folder, or a -wildcard: *.txt")
|
addCmd.LongDescription("You can add all: all, a -file (-f): file.txt, or a -folder (-fd): folder, or a -wildcard (-wc): *.txt")
|
||||||
//File/Folder/Wildcard adding
|
//File/Folder/Wildcard adding
|
||||||
addCmd.Action(clientcmd.AddFiles)
|
var file string
|
||||||
|
var folder string
|
||||||
|
var wildcard string
|
||||||
|
fileFlag := addCmd.StringFlag("file", "tracks a file to add to the repo", &file)
|
||||||
|
fileFlag.FlagShortCut("file", "f")
|
||||||
|
folderFlag := addCmd.StringFlag("folder", "tracks all contents of a folder to add to the repo", &folder)
|
||||||
|
folderFlag.FlagShortCut("folder", "fd")
|
||||||
|
wildCardFlag := addCmd.StringFlag("wildcard", "treats the input as a wildcard and tracks all files that match the wildcard", &wildcard)
|
||||||
|
wildCardFlag.FlagShortCut("wildcard", "wc")
|
||||||
|
addCmd.Action(func() error {
|
||||||
|
if len(addCmd.OtherArgs()) > 0 {
|
||||||
|
addCmd.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("adding file to tracked files: ", file)
|
||||||
|
err := clientcmd.AddFiles(file, "file")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if folder != "" { // if the folder flag was used it won't be empty
|
||||||
|
fmt.Println("adding contents of folder to tracked files: ", folder)
|
||||||
|
err := clientcmd.AddFiles(folder, "folder")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
if wildcard != "" { // if the wildcard flag was used it won't be empty
|
||||||
|
fmt.Println("adding files with wildcard filter: ", wildcard)
|
||||||
|
err := clientcmd.AddFiles(wildcard, "wildcard")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
//Add all files recursively to repo
|
//Add all files recursively to repo
|
||||||
addall := addCmd.NewSubCommand("all", "add all of the file(s)/folders(s) recursively to repo")
|
addall := addCmd.NewSubCommand("all", "add all of the file(s)/folders(s) recursively to repo")
|
||||||
addall.Action(clientcmd.AddAll)
|
addall.Action(func() error {
|
||||||
//The remote command
|
if len(addall.OtherArgs()) > 0 {
|
||||||
|
addCmd.PrintHelp()
|
||||||
|
return fmt.Errorf("the 'all' subcommand does not accept additional arguments")
|
||||||
|
}
|
||||||
|
fmt.Println("adding all files recursively in directory to tracked files")
|
||||||
|
err := clientcmd.AddFiles("", "all")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
//The add remote command
|
||||||
remoteCmd := cli.NewSubCommand("remote", "add/delete/show remotes")
|
remoteCmd := cli.NewSubCommand("remote", "add/delete/show remotes")
|
||||||
var name string
|
var name string
|
||||||
var host string
|
var host string
|
||||||
|
@@ -5,14 +5,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
//AddFiles adds files to the repo
|
//AddFiles adds files to the repo, inputType specifies file, folder, wildcard or all
|
||||||
func AddFiles() error {
|
func AddFiles(input string, inputType string) error {
|
||||||
fmt.Println("File/folder/wildcard to add", os.Args[2])
|
fmt.Println("File/folder/wildcard to add", os.Args[2])
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//AddAll adds all files in working dir
|
|
||||||
func AddAll() error {
|
|
||||||
fmt.Println("Adding all files", os.Args[2])
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@@ -3,7 +3,7 @@ package config
|
|||||||
//Gvcconfig will be the struct that holds the entire client settings
|
//Gvcconfig will be the struct that holds the entire client settings
|
||||||
type Gvcconfig struct {
|
type Gvcconfig struct {
|
||||||
Version string `toml:"version"`
|
Version string `toml:"version"`
|
||||||
RootPath string `toml:rootPath`
|
RootPath string `toml:"rootPath"`
|
||||||
Remotes []Remote `toml:"remote"` //The remote servers for the repo
|
Remotes []Remote `toml:"remote"` //The remote servers for the repo
|
||||||
Ignores Ignore `toml:"ignore"` //These files will be ignored for all add functions
|
Ignores Ignore `toml:"ignore"` //These files will be ignored for all add functions
|
||||||
NoCompress Ignore `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings
|
NoCompress Ignore `toml:"nocompress"` //For binary compression some files should be ignored because the performance hit isn't worth the size savings
|
||||||
|
Reference in New Issue
Block a user