Repository: docker/compose
File: docs/examples/provider.go (Go)

Code before:
		Args: cobra.NoArgs,
	})
	return c
}

const lineSeparator = "\n"

func up(_ *cobra.Command, args []string) {
	servicename := args[0]
	fmt.Printf(`{ "type": "debug", "message": "Starting %s" }%s`, servicename, lineSeparator)

	for i := 0; i < 100; i += 10 {
		time.Sleep(1 * time.Second)
		fmt.Printf(`{ "type": "info", "message": "Processing ... %d%%" }%s`, i, lineSeparator)
	}
	fmt.Printf(`{ "type": "setenv", "message": "URL=https://magic.cloud/%s" }%s`, servicename, lineSeparator)
}

func down(_ *cobra.Command, _ []string) {
	fmt.Printf(`{ "type": "error", "message": "Permission error" }%s`, lineSeparator)
}

func metadata(metadataCmd *cobra.Command, _ []string) {
	composeCmd := metadataCmd.Parent()
	metadata := map[string]CommandMetadata{}
	for _, cmd := range composeCmd.Commands() {
		cmdName := cmd.Name()
		if cmdName == "up" || cmdName == "down" {
			cmdMetadata := metadata[cmdName]
			cmd.Flags().VisitAll(func(f *pflag.Flag) {
				_, isRequired := f.Annotations[cobra.BashCompOneRequiredFlag]
				cmdMetadata.Parameters = append(cmdMetadata.Parameters, Metadata{
					Name:        f.Name,
					Description: f.Usage,
					Required:    isRequired,
					Type:        f.Value.Type(),
					Default:     f.DefValue,
				})
			})
			metadata[cmdName] = cmdMetadata
		}
	}
	jsonMetadata, err := json.Marshal(metadata)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(jsonMetadata))
}

type CommandMetadata struct {
	Parameters []Metadata `json:"parameters"`

Review comment (suggestion):
you can use `composeCmd.Find("up")`, or could pass `upCmd` to the metadata command

Code after:
}

const lineSeparator = "\n"

func up(_ *cobra.Command, args []string) {
	servicename := args[0]
	fmt.Printf(`{ "type": "debug", "message": "Starting %s" }%s`, servicename, lineSeparator)

	for i := 0; i < 100; i += 10 {
		time.Sleep(1 * time.Second)
		fmt.Printf(`{ "type": "info", "message": "Processing ... %d%%" }%s`, i, lineSeparator)
	}
	fmt.Printf(`{ "type": "setenv", "message": "URL=https://magic.cloud/%s" }%s`, servicename, lineSeparator)
}

func down(_ *cobra.Command, _ []string) {
	fmt.Printf(`{ "type": "error", "message": "Permission error" }%s`, lineSeparator)
}

func metadataCommand(upCmd, downCmd *cobra.Command) *cobra.Command {
	return &cobra.Command{
		Use: "metadata",
		Run: func(cmd *cobra.Command, _ []string) {
			metadata(upCmd, downCmd)
		},
		Args: cobra.NoArgs,
	}
}

func metadata(upCmd, downCmd *cobra.Command) {
	metadata := ProviderMetadata{}
	metadata.Description = "Manage services on AwesomeCloud"
	metadata.Up = commandParameters(upCmd)
	metadata.Down = commandParameters(downCmd)
	jsonMetadata, err := json.Marshal(metadata)
	if err != nil {
		panic(err)
	}
	fmt.Println(string(jsonMetadata))
}

func commandParameters(cmd *cobra.Command) CommandMetadata {
	cmdMetadata := CommandMetadata{}
	cmd.Flags().VisitAll(func(f *pflag.Flag) {
		_, isRequired := f.Annotations[cobra.BashCompOneRequiredFlag]
		cmdMetadata.Parameters = append(cmdMetadata.Parameters, Metadata{
			Name:        f.Name,
			Description: f.Usage,
			Required:    isRequired,
			Type:        f.Value.Type(),
			Default:     f.DefValue,