Files
ctask/cmd/last.go
T

47 lines
1.1 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
)
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")
rootCmd.AddCommand(lastCmd)
}
func runLast(cmd *cobra.Command, args []string) error {
root := config.ResolveRoot()
best, err := workspace.MostRecentActive(root)
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)
}