cli: share the stop-sessions confirmation prompt · Entire
cli: share the stop-sessions confirmation prompt
62ea674→main·
Soph·2w ago·1 file·+27 added/-28 removed
runStopAll and runStopMultiSelect repeated the confirm-form/cancel/ decLine handling; extract confirmStopSessions. Covered by the existing session stop tests.
Co-Authored-By: Claude Fable 5 noreply@anthropic.com
Sessions
5c2527f62f77View transcript
Changes
1
cmd/entire/cli
Msessions.go+27/-28
758 unmodified lines
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
34 unmodified lines
829
830
831
822
823
824
825
826
827
828
829
830
831
832
833
834
835
832
833
834
835
836
837
758 unmodified lines
}
if !force {
var confirmed bool
form := NewAccessibleForm(
huh.NewGroup(
huh.NewConfirm().
Title(fmt.Sprintf("Stop %d session(s)?", len(activeSessions))).
Value(&confirmed),
),
)
if err := form.Run(); err != nil {
return handleFormCancellation(cmd.OutOrStdout(), "Stop", err)
}
if !confirmed {
fmt.Fprintln(cmd.OutOrStdout(), "Stop cancelled.")
return nil
confirmed, err := confirmStopSessions(cmd, len(activeSessions))
if err != nil || !confirmed {
return err
}
}
return stopSelectedSessions(ctx, cmd, activeSessions)
// confirmStopSessions asks the user to confirm stopping count sessions.
// When declined or cancelled it prints the outcome and returns confirmed=false.
func confirmStopSessions(cmd *cobra.Command, count int) (bool, error) {
var confirmed bool
form := NewAccessibleForm(
huh.NewGroup(
huh.NewConfirm().
Title(fmt.Sprintf("Stop %d session(s)?", count)).
Value(&confirmed),
),
)
if err := form.Run(); err != nil {
return false, handleFormCancellation(cmd.OutOrStdout(), "Stop", err)
}
if !confirmed {
fmt.Fprintln(cmd.OutOrStdout(), "Stop cancelled.")
return false, nil
}
return true, nil
}
// runStopMultiSelect shows a TUI multi-select for multiple active sessions.
func runStopMultiSelect(ctx context.Context, cmd *cobra.Command, activeSessions []*strategy.SessionState, force bool) error {
options := make([]huh.Option[string], len(activeSessions))
// Confirm only if not forcing
if !force {
var confirmed bool
form := NewAccessibleForm(
huh.NewGroup(
huh.NewConfirm().
Title(fmt.Sprintf("Stop %d session(s)?", len(selectedIDs))).
Value(&confirmed),
),
)
if err := form.Run(); err != nil {
return handleFormCancellation(cmd.OutOrStdout(), "Stop", err)
}
if !confirmed {
fmt.Fprintln(cmd.OutOrStdout(), "Stop cancelled.")
return nil
confirmed, err := confirmStopSessions(cmd, len(selectedIDs))
if err != nil || !confirmed {
return err
}
}