working on merging configs, adding branch/switch/pull commands
This commit is contained in:
109
client/client.go
109
client/client.go
@@ -67,6 +67,15 @@ func main() {
|
||||
// Adding the "remote" commands
|
||||
remoteCommands(cli, &conf)
|
||||
|
||||
// Adding the "branch" command
|
||||
branchCommand(cli, &conf)
|
||||
|
||||
// Adding the "switch" command
|
||||
switchCommand(cli, &conf)
|
||||
|
||||
// Adding the "pull" command
|
||||
pullCommand(cli, &conf)
|
||||
|
||||
err = cli.Run()
|
||||
if err != nil {
|
||||
fmt.Printf("Error occurred: %v\n", err)
|
||||
@@ -510,26 +519,26 @@ func lockCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
|
||||
// removeLockCmd removes files/folders/wildcard from the ignore list
|
||||
func removeLockCmd(ignoreCmd *clir.Command, conf *clientconfig.Gvcconfig) {
|
||||
RemoveLockCmd := ignoreCmd.NewSubCommand("remove", "remove from ignores file(s)/folder(s) (recursively for folder) to repo")
|
||||
RemoveLockCmd.LongDescription("You can remove from ignore all: all, a -file (-f): file.txt, or a -folder (-fd): folder, or a -wildcard (-wc): *.txt")
|
||||
removeLockCmd := ignoreCmd.NewSubCommand("remove", "remove from ignores file(s)/folder(s) (recursively for folder) to repo")
|
||||
removeLockCmd.LongDescription("You can remove from 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 := RemoveLockCmd.StringFlag("file", "removes ignored file from config", &file)
|
||||
fileFlag := removeLockCmd.StringFlag("file", "removes ignored file from config", &file)
|
||||
fileFlag.FlagShortCut("file", "f")
|
||||
folderFlag := RemoveLockCmd.StringFlag("folder", "removes ignored folder", &folder)
|
||||
folderFlag := removeLockCmd.StringFlag("folder", "removes ignored folder", &folder)
|
||||
folderFlag.FlagShortCut("folder", "fd")
|
||||
wildCardFlag := RemoveLockCmd.StringFlag("wildcard", "removes wildcard from ignores", &wildcard)
|
||||
wildCardFlag := removeLockCmd.StringFlag("wildcard", "removes wildcard from ignores", &wildcard)
|
||||
wildCardFlag.FlagShortCut("wildcard", "wc")
|
||||
RemoveLockCmd.Action(func() error {
|
||||
removeLockCmd.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(RemoveLockCmd.OtherArgs()) > 0 {
|
||||
RemoveLockCmd.PrintHelp()
|
||||
if len(removeLockCmd.OtherArgs()) > 0 {
|
||||
removeLockCmd.PrintHelp()
|
||||
return fmt.Errorf("incorrect input detected, please fix and retry")
|
||||
}
|
||||
if file != "" { // if the file flag was used it won't be empty
|
||||
@@ -559,3 +568,87 @@ func removeLockCmd(ignoreCmd *clir.Command, conf *clientconfig.Gvcconfig) {
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func branchCommand(cli *clir.Cli, conf *config.Gvcconfig) {
|
||||
branchCommand := cli.NewSubCommand("branch", "creates a new branch off of the current branch")
|
||||
var branchName string
|
||||
nameFlag := branchCommand.StringFlag("name", "name of the branch to create", &branchName)
|
||||
nameFlag.FlagShortCut("name", "n")
|
||||
nameFlag.FlagRequired("name")
|
||||
branchCommand.Action(func() error {
|
||||
isRepo := validateRepo()
|
||||
if !isRepo {
|
||||
fmt.Println("no valid repo found.. please run 'init' to setup a repo first")
|
||||
os.Exit(0)
|
||||
}
|
||||
err := clientcmd.CreateBranch(conf, branchName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func switchCommand(cli *clir.Cli, conf *config.Gvcconfig) {
|
||||
switchCommand := cli.NewSubCommand("switch", "switches (and can create if needed) a new branch to work on")
|
||||
var createBranch bool
|
||||
createFlag := switchCommand.BoolFlag("create", "creates the branch if it does not exist", &createBranch)
|
||||
createFlag.FlagShortCut("create", "c")
|
||||
switchCommand.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 createBranch {
|
||||
if len(switchCommand.OtherArgs()) < 1 {
|
||||
switchCommand.PrintHelp()
|
||||
fmt.Println("branch name required..")
|
||||
os.Exit(0)
|
||||
}
|
||||
branchName := switchCommand.OtherArgs()[0]
|
||||
fmt.Println("attempting to create branch name: ", branchName)
|
||||
err := clientcmd.CreateBranch(conf, branchName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error creating branch: %s", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if len(switchCommand.OtherArgs()) == 0 {
|
||||
switchCommand.PrintHelp()
|
||||
fmt.Println("branch name required..")
|
||||
os.Exit(0)
|
||||
}
|
||||
branchName := switchCommand.OtherArgs()[0]
|
||||
err := clientcmd.SwitchBranch(conf, branchName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to switch branch: %s", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func pullCommand(cli *clir.Cli, conf *config.Gvcconfig) {
|
||||
pullCommand := cli.NewSubCommand("pull", "pulls the latest commit from the server (default if none specified) on your current branch")
|
||||
var createBranch bool
|
||||
createFlag := pullCommand.BoolFlag("create", "creates the branch if it does not exist", &createBranch)
|
||||
createFlag.FlagShortCut("create", "c")
|
||||
pullCommand.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(pullCommand.OtherArgs()) == 0 {
|
||||
pullCommand.PrintHelp()
|
||||
fmt.Println("branch name required..")
|
||||
os.Exit(0)
|
||||
}
|
||||
branchName := pullCommand.OtherArgs()[0]
|
||||
err := clientcmd.SwitchBranch(conf, branchName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to pull branch: %s", err)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user