Files

49 lines
1.2 KiB
Go

package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/warrenronsiek/ctask/internal/config"
"github.com/warrenronsiek/ctask/internal/workspace"
)
var lastCmd = &cobra.Command{
Use: "last",
Short: "Resume the most recently updated workspace (task or project)",
Args: cobra.NoArgs,
SilenceUsage: true,
RunE: runLast,
}
var (
lastShell bool
lastAgent string
lastForce bool
lastDirect bool
)
func init() {
lastCmd.Flags().BoolVar(&lastShell, "shell", false, "Open shell instead of agent")
lastCmd.Flags().StringVarP(&lastAgent, "agent", "a", "", "Override agent command")
lastCmd.Flags().BoolVar(&lastForce, "force", false, "Skip active-session and stale-workspace warnings")
lastCmd.Flags().BoolVar(&lastDirect, "direct", false, "Bypass persistent session mode for this command")
rootCmd.AddCommand(lastCmd)
}
func runLast(cmd *cobra.Command, args []string) error {
roots := config.SearchRoots()
best, err := workspace.MostRecentActive(roots)
if err != nil {
return err
}
if best == nil {
fmt.Fprintln(os.Stderr, "No active workspaces found.")
os.Exit(1)
}
return doResume(best.Meta.Slug, false, lastShell, lastForce, lastAgent, lastDirect)
}