Something went wrong. Try again.
An unofficial terminal client for Tangled, optimized for humans and agents. tgcli.wisp.place
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192package cli
import ( "fmt" "io"
"charm.land/lipgloss/v2" "github.com/alyraffauf/tg/internal/app" "github.com/spf13/cobra")
func newAuthStatusCommand(service *app.Service) *cobra.Command { return &cobra.Command{ Use: "status", Short: "Show the active account", RunE: func(cmd *cobra.Command, args []string) error { result, err := service.AuthStatus(cmd.Context()) if err != nil { return err } return output(cmd, result, func(r *app.AuthStatusResult) { renderAuthStatus(cmd.OutOrStdout(), r) }) }, }}
func renderAuthStatus(writer io.Writer, result *app.AuthStatusResult) { styles := newAuthOutputStyles(isTerminal(writer)) if !result.Authenticated { writeAuthHeading(writer, styles.inactive, "○", "Not logged in") writeAuthDetail(writer, styles, "Action", "tg auth login <handle>") return }
switch result.Status { case app.SessionStatusActive: writeAuthHeading(writer, styles.active, "✓", "Authenticated") writeAuthIdentity(writer, styles, result) writeAuthDetail(writer, styles, "Session", "Active") case app.SessionStatusExpired: writeAuthHeading(writer, styles.warning, "!", "Session expired") writeAuthIdentity(writer, styles, result) writeAuthDetail(writer, styles, "Action", "tg auth login "+result.Handle) case app.SessionStatusUnknown: writeAuthHeading(writer, styles.warning, "?", "Could not verify session") writeAuthIdentity(writer, styles, result) writeAuthDetail(writer, styles, "Reason", "Network error") writeAuthDetail(writer, styles, "Retry", "tg auth status") }}
type authOutputStyles struct { active lipgloss.Style inactive lipgloss.Style warning lipgloss.Style label lipgloss.Style value lipgloss.Style dim lipgloss.Style}
func newAuthOutputStyles(colorEnabled bool) authOutputStyles { styles := authOutputStyles{} if !colorEnabled { return styles } styles.active = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Green) styles.inactive = lipgloss.NewStyle().Faint(true) styles.warning = lipgloss.NewStyle().Bold(true).Foreground(lipgloss.Yellow) styles.label = lipgloss.NewStyle().Faint(true) styles.value = lipgloss.NewStyle().Bold(true) styles.dim = lipgloss.NewStyle().Faint(true) return styles}
func writeAuthHeading(writer io.Writer, style lipgloss.Style, icon, text string) { fmt.Fprintf(writer, "%s %s\n", style.Render(icon), style.Render(text))}
func writeAuthIdentity(writer io.Writer, styles authOutputStyles, result *app.AuthStatusResult) { if result.Handle != "" { writeAuthDetail(writer, styles, "Account", styles.value.Render(result.Handle)) } if result.DID != "" { writeAuthDetail(writer, styles, "DID", styles.dim.Render(result.DID)) }}
func writeAuthDetail(writer io.Writer, styles authOutputStyles, label, value string) { fmt.Fprintf(writer, " %s %s\n", styles.label.Render(label), value)}