Skip to content

Custom Renderer

If the custom formatting and layout don't meet you needs, you can simply specify your own rendering function:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// NewRoot returns a root cobra.Command for the whole CLI.
func NewRoot() *cobra.Command {
    cmd := &cobra.Command{
        Use:   "example",
        Short: "An example CLI built with github.com/spf13/cobra",
    }

    opts := []upgrade.Options{
        upgrade.WithRenderer(func(in *upgrade.Info, isSmartTerminal bool) (string, error) {
            return fmt.Sprintf(`
      Version             %q
      New Version         %q
   `, in.Version, in.NewVersion), nil
        }),
    }

    cmd.AddCommand(
        // 1. Register the 'version' command
        extension.NewVersionCobraCmd(
            // 2. Explicitly enable the upgrade notice
            extension.WithUpgradeNotice("mszostok", "codeowners-validator", opts...),
        ),
    )

    return cmd
}
Back to top