add(cli): cli interface for push, pull and version
This commit is contained in:
40
cmd/push.go
Normal file
40
cmd/push.go
Normal 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)
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user