cli: fix builder persistent flag

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
CrazyMax
2021-11-04 18:52:11 +01:00
parent 4c938c77ba
commit eab0e6a8fe
34 changed files with 277 additions and 172 deletions

View File

@@ -41,61 +41,10 @@ require (
)
```
Next, create a file named `docgen.go` inside that directory containing the
following Go code:
Next, create a file named `main.go` inside that directory containing the
following Go code from [`example/main.go`](example/main.go).
```go
package main
import (
"log"
"os"
"path/filepath"
"github.com/docker/buildx/commands"
"github.com/docker/cli/cli/command"
clidocstool "github.com/docker/cli-docs-tool"
"github.com/spf13/cobra"
)
const sourcePath = "docs/"
func main() {
log.SetFlags(0)
dockerCLI, err := command.NewDockerCli()
if err != nil {
log.Printf("ERROR: %+v", err)
}
cmd := &cobra.Command{
Use: "docker [OPTIONS] COMMAND [ARG...]",
Short: "The base command for the Docker CLI.",
DisableAutoGenTag: true,
}
cmd.AddCommand(commands.NewRootCmd("buildx", true, dockerCLI))
clidocstool.DisableFlagsInUseLine(cmd)
cwd, _ := os.Getwd()
source := filepath.Join(cwd, sourcePath)
// Make sure "source" folder is created first
if err = os.MkdirAll(source, 0755); err != nil {
log.Printf("ERROR: %+v", err)
}
// Generate Markdown and YAML documentation to "source" folder
if err = clidocstool.GenTree(cmd, source); err != nil {
log.Printf("ERROR: %+v", err)
}
}
```
Here we create a new instance of Docker CLI with `command.NewDockerCli` and a
subcommand `commands.NewRootCmd` for `buildx`.
Finally, we generate Markdown and YAML documentation with `clidocstool.GenTree`.
Running this example should produce the following output:
```console
$ go run main.go