package main import ( "context" "fmt" "io" "ucl.lmika.dev/repl" "ucl.lmika.dev/ucl" ) type FancyType struct { Foo string Bar string } var newFancyDoc = repl.Doc{ Brief: "returns something fancy", Detailed: ` This will create and return something fancy. `, } func newFancy(ctx context.Context, args ucl.CallArgs) (any, error) { return FancyType{Foo: "is foo", Bar: "is bar"}, nil } func manyFancies(ctx context.Context, args ucl.CallArgs) (any, error) { return []FancyType{ {Foo: "foo 1", Bar: "bar 1"}, {Foo: "foo 2", Bar: "bar 2"}, {Foo: "foo 3", Bar: "bar 3"}, }, nil } func displayFancy(w io.Writer, f FancyType, concise bool) error { if concise { _, err := fmt.Fprintf(w, "%s:%s", f.Foo, f.Bar) return err } fmt.Fprintf(w, "Foo.. %s\n", f.Foo) fmt.Fprintf(w, "Bar.. %s\n", f.Bar) return nil } func displayFancies(w io.Writer, fs []FancyType, concise bool) error { if concise { _, err := fmt.Fprintf(w, "%d fancies", len(fs)) return err } fmt.Fprintln(w, "FOO\tBAR") for _, f := range fs { fmt.Fprintf(w, "%v\t%v\n", f.Foo, f.Bar) } return nil }