add(cli): cli interface for push, pull and version

This commit is contained in:
2023-10-26 00:32:25 +02:00
parent 854dafde01
commit 32a389d464
14 changed files with 750 additions and 64 deletions

40
cmd/push.go Normal file
View File

@@ -0,0 +1,40 @@
package cmd
import (
"fmt"
"os"
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/gitea"
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/gitw"
"github.com/spf13/cobra"
)
func init() {
pushCmd.Flags().BoolVarP(&dry_run, "dry-run", "d", false, "Only output changes without applying them")
rootCmd.AddCommand(pushCmd)
}
var pushCmd = &cobra.Command{
Use: "push",
Short: "Push changes from taskwarrior to git repository of current directory",
Long: `Push changes for all taskwarrior tasks related to the repository to the git server identified by the remote url of the current working directory.`,
Run: func(cmd *cobra.Command, args []string) {
server := gitea.NewGitea()
repository, err := gitw.Discover()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
repository, err = server.VerifyRepository(repository)
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
project := gitw.NewProject(server, repository)
fmt.Printf("Push changes to %s\n", repository.Full_name)
if err = project.Push(dry_run); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(-1)
}
},
}