Documentation
¶
Index ¶
- Variables
- func NewClientForCmd(cmd *cobra.Command, cfg *config.AppConfig) (*git.Client, error)
- func NewMainClientForCmd(cmd *cobra.Command, cfg *config.AppConfig) (mainClient *git.Client, invokedFrom string, err error)
- func RunMenu(cmd *cobra.Command, title string, subs []*cobra.Command, p MenuPrompter) error
- type MenuPrompter
Constants ¶
This section is empty.
Variables ¶
ErrMenuUnavailable is returned by a MenuPrompter when there is no interactive terminal to draw the menu on (piped stdin, CI, cron).
Functions ¶
func NewClientForCmd ¶
NewClientForCmd builds a git.Client wired to cmd's IO streams and pins the remote from cfg when configured.
func NewMainClientForCmd ¶ added in v0.15.2
func NewMainClientForCmd( cmd *cobra.Command, cfg *config.AppConfig, ) (mainClient *git.Client, invokedFrom string, err error)
NewMainClientForCmd opens the repository like NewClientForCmd and re-anchors the client on the main working tree when the command was typed inside a linked worktree. invokedFrom is the working-tree root of the directory the command was typed in, so callers can tell whether a worktree they remove is the one the user's shell is standing in.
func RunMenu ¶ added in v0.15.1
RunMenu is the RunE body of a command group invoked with no subcommand: it shows a menu of subs and runs the picked one.
The picked subcommand's RunE receives cmd — the parent, currently executing command — rather than itself. cobra v1.1.3 offers no SetContext, and the parent is the only command carrying a live Context and IO streams. Flag reads on the parent tolerate the missing flags (pflag reports unknown flags as unchanged; pushflow.ReadFlags checks Lookup first), so the subcommand runs on its interactive defaults, exactly as branch.runE already dispatches to its own subcommands.
Esc / ctrl+c on the menu exits quietly; a non-interactive stdin prints the group's help instead, so scripts keep the pre-menu behaviour.
Types ¶
type MenuPrompter ¶ added in v0.15.1
type MenuPrompter interface {
// Select shows title above one entry per sub and returns the picked
// sub's Name(). It reports ErrMenuUnavailable when no terminal is
// attached and huh.ErrUserAborted when the user presses Esc / ctrl+c.
Select(ctx context.Context, title string, subs []*cobra.Command) (string, error)
}
MenuPrompter presents a list of subcommands and returns the Name() of the one the user picked. The production implementation opens a huh form; tests substitute a scripted one.
func NewHuhMenuPrompter ¶ added in v0.15.1
func NewHuhMenuPrompter() MenuPrompter
NewHuhMenuPrompter returns the huh-backed MenuPrompter used by the CLI.