starting to write the commit functions

This commit is contained in:
2020-06-20 18:48:58 -04:00
parent 47cc65a824
commit 1ec7b436da
9 changed files with 268 additions and 32 deletions

View File

@@ -109,6 +109,9 @@ func main() {
// Adding the "pull" command
pullCommand(cli, &conf)
// Adding the "commit" command
commitCommand(cli, &conf)
err = cli.Run()
if err != nil {
fmt.Printf("Error occurred: %v\n", err)
@@ -685,3 +688,28 @@ func pullCommand(cli *clir.Cli, conf *config.Gvcconfig) {
return nil
})
}
func commitCommand(cli *clir.Cli, conf *config.Gvcconfig) {
commitCommand := cli.NewSubCommand("commit", "commits the changes to the repo")
var commitMessage string
commitMessageFlag := pullCommand.StringFlag("message", "adds a message to a commit", &commitMessage)
commitMessageFlag.FlagShortCut("message", "m")
commitCommand.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(commitCommand.OtherArgs()) == 0 {
commitCommand.PrintHelp()
fmt.Println("branch name required..")
os.Exit(0)
}
branchName := commitCommand.OtherArgs()[0]
err := clientcmd.SwitchBranch(conf, branchName)
if err != nil {
return fmt.Errorf("unable to pull branch: %s", err)
}
return nil
})
}