Something went wrong. Try again.
An unofficial terminal client for Tangled, optimized for humans and agents. tgcli.wisp.place
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142package cli
import ( "encoding/json" "fmt" "io"
"github.com/alyraffauf/tg/internal/app" "github.com/spf13/cobra")
func renderRecordWarnings(writer io.Writer, warnings []app.RecordWarning) { for _, warning := range warnings { if warning.URI == "" { fmt.Fprintf(writer, "warning: %s\n", warning.Error) continue } fmt.Fprintf(writer, "warning: %s: %s\n", warning.URI, warning.Error) }}
// output dispatches structured data to JSON (when --json is set) or to a// human-readable renderer.func output[T any](cmd *cobra.Command, data T, human func(T)) error { if jsonOutput, _ := cmd.Flags().GetBool("json"); jsonOutput { enc := json.NewEncoder(cmd.OutOrStdout()) enc.SetIndent("", " ") return enc.Encode(data) } if result, ok := any(data).(interface{ MutationWarnings() []string }); ok { for _, warning := range result.MutationWarnings() { fmt.Fprintf(cmd.ErrOrStderr(), "warning: %s\n", warning) } } human(data) return nil}
func outputRecordUpdate(cmd *cobra.Command, rkey string) error { return output(cmd, app.UpdatedRecordResult{Rkey: rkey}, func(app.UpdatedRecordResult) {})}