add(cli): cli interface for push, pull and version
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/gitea"
|
||||
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/gitw"
|
||||
)
|
||||
|
||||
func main() {
|
||||
// TODO: server url may be also be derived from the git configuration?
|
||||
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("Pulling changes from %s\n", repository.Full_name)
|
||||
if err = project.Pull(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
fmt.Printf("Push changes to %s\n", repository.Full_name)
|
||||
if err = project.Push(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
|
||||
// NOTE: this can be used to add / modify tasks
|
||||
// var update_tasks []taskwarrior.Task
|
||||
// task := taskwarrior.NewTask(
|
||||
// "This is a test task from gitwarrior",
|
||||
// "gitwarrior",
|
||||
// "issue",
|
||||
// )
|
||||
// update_tasks = append(update_tasks, task)
|
||||
// taskwarrior.UpdateTasks(update_tasks)
|
||||
|
||||
// necessary configurations (see config file gitw.json)
|
||||
// - access code for gitea
|
||||
// - configuration for taskwarrior settings?
|
||||
|
||||
// cli actions and parameters
|
||||
// - action: diff (i.e. what has changed between the current state of the taskwarrior tasks and the git issues / milestones)
|
||||
// - action: status (are there changes between the taskwarrior tasks and the gitea issues / milestones, that would require a sync)
|
||||
// - action: sync (synch diffs between taskwarrior tasks and gitea issues / milestones)
|
||||
// - parameter: --dry-run (do only show changes that would be applied but do not apply them)
|
||||
}
|
||||
41
cmd/pull.go
Normal file
41
cmd/pull.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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() {
|
||||
pullCmd.Flags().BoolVarP(&dry_run, "dry-run", "d", false, "Only output changes without applying them")
|
||||
rootCmd.AddCommand(pullCmd)
|
||||
}
|
||||
|
||||
var pullCmd = &cobra.Command{
|
||||
Use: "pull",
|
||||
Short: "Pull changes from git repository of current directory",
|
||||
Long: `Pull changes of all issues and milestones from the git server identified by the remote url of the current working directory.
|
||||
In case of merge conflicts $EDITOR is executed to manually edit the changes to resolve the merge conflicts directly.`,
|
||||
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("Pulling changes from %s\n", repository.Full_name)
|
||||
if err = project.Pull(dry_run); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
},
|
||||
}
|
||||
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)
|
||||
}
|
||||
},
|
||||
}
|
||||
38
cmd/root.go
Normal file
38
cmd/root.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var (
|
||||
dry_run bool
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "gitw",
|
||||
Short: "Git issue and milestone integration for taskwarrior",
|
||||
Long: `Gitwarrior is a CLI tool to extend the taskwarrior tasks to synch issues and milestones.
|
||||
Gitwarrior requires requires the following uda's to be defined: last_gitw_update(date), git_number(number), git_type(string), git_comment_ids(string).`,
|
||||
}
|
||||
)
|
||||
|
||||
func Execute() error {
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(initConfig)
|
||||
}
|
||||
|
||||
func initConfig() {
|
||||
viper.SetConfigName("config")
|
||||
viper.SetConfigType("yaml")
|
||||
viper.AddConfigPath("$HOME/.config/gitw")
|
||||
viper.AutomaticEnv()
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Failed to read configuration file: %s\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
21
cmd/task.go
Normal file
21
cmd/task.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package cmd
|
||||
|
||||
import "github.com/spf13/cobra"
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(taskCmd)
|
||||
}
|
||||
|
||||
var taskCmd = &cobra.Command{
|
||||
Use: "task",
|
||||
Short: "Taskwarrior wrapper with automatic context for current git project",
|
||||
Long: `Taskwarrior wrapper with automatic context for current git project.
|
||||
This allows the usage of common taskwarrior commands with appling the context for the current git project,
|
||||
which filters all the tasks automatically for the current project. The context will be disabled as soon as the provided command has been executed.
|
||||
There is no need for the user to disable / enable context specific configurations.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
// TODO: run taskwarrior context enabling (maybe even creating the context)
|
||||
// TODO: run taskwarrior command with provided args
|
||||
// TODO: run taskwarrior context disableing
|
||||
},
|
||||
}
|
||||
20
cmd/version.go
Normal file
20
cmd/version.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
}
|
||||
|
||||
var versionCmd = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print the version of gitwarrior",
|
||||
Long: `All software has versions. This is gitwarrior's`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("v0.1")
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user