58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/gitea"
|
|
"gitea.yves-biener.de/yves-biener/gitwarrior/internal/gitw"
|
|
"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 applying 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. The user will need to configure the context beforehand themselfs.`,
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
var execCmd *exec.Cmd
|
|
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)
|
|
}
|
|
execCmd = exec.Command("task", "context", repository.Name)
|
|
if err := execCmd.Run(); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to execute task command: `task context %s`\n", repository.Name)
|
|
os.Exit(-1)
|
|
}
|
|
execCmd = exec.Command("task", args...)
|
|
execCmd.Stdout = os.Stdout
|
|
execCmd.Stdin = os.Stdin
|
|
execCmd.Stderr = os.Stderr
|
|
if err := execCmd.Run(); err != nil {
|
|
fmt.Fprintf(os.Stderr, "Failed to execute task command: `task %s`\n", strings.Join(args, " "))
|
|
defer os.Exit(-1) // do not exit yet because the context still needs to be removed
|
|
}
|
|
execCmd = exec.Command("task", "context", "none")
|
|
if err := execCmd.Run(); err != nil {
|
|
fmt.Fprintln(os.Stderr, "Failed to execute task command: `task context none`")
|
|
os.Exit(-1)
|
|
}
|
|
},
|
|
}
|