add(cli): taskwarrior context wrapper command

This commit is contained in:
2023-10-26 15:57:46 +02:00
parent 65df4be21c
commit 398122a689

View File

@@ -1,6 +1,15 @@
package cmd package cmd
import "github.com/spf13/cobra" 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() { func init() {
rootCmd.AddCommand(taskCmd) rootCmd.AddCommand(taskCmd)
@@ -10,12 +19,39 @@ var taskCmd = &cobra.Command{
Use: "task", Use: "task",
Short: "Taskwarrior wrapper with automatic context for current git project", Short: "Taskwarrior wrapper with automatic context for current git project",
Long: `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, 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. 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.`, 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) { Run: func(cmd *cobra.Command, args []string) {
// TODO: run taskwarrior context enabling (maybe even creating the context) var execCmd *exec.Cmd
// TODO: run taskwarrior command with provided args server := gitea.NewGitea()
// TODO: run taskwarrior context disableing 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)
}
}, },
} }