Skip to content

Commit 1d3c123

Browse files
committed
docs: handle feature flags in doc generation
Signed-off-by: David Karlsson <35727626+dvdksn@users.noreply.github.com>
1 parent 8f08a37 commit 1d3c123

File tree

4 files changed

+29
-6
lines changed

4 files changed

+29
-6
lines changed

Dockerfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
ARG GO_VERSION=1.25.5
44
ARG DOCS_FORMATS="md,yaml"
5+
ARG DOCS_FEATURES=""
56

67
FROM --platform=${BUILDPLATFORM} golangci/golangci-lint:v2.8.0-alpine AS lint-base
78

@@ -20,11 +21,12 @@ FROM base AS docs-build
2021
COPY --from=docs-gen /out/docsgen /usr/bin
2122
ENV DOCKER_CLI_PLUGIN_ORIGINAL_CLI_COMMAND="mcp"
2223
ARG DOCS_FORMATS
24+
ARG DOCS_FEATURES
2325
RUN --mount=target=/context \
2426
--mount=target=.,type=tmpfs <<EOT
2527
set -e
2628
rsync -a /context/. .
27-
docsgen --formats "$DOCS_FORMATS" --source "docs/generator/reference"
29+
docsgen --formats "$DOCS_FORMATS" ${DOCS_FEATURES:+--features "$DOCS_FEATURES"} --source "docs/generator/reference"
2830
mkdir /out
2931
cp -r docs/generator/reference/* /out/
3032
EOT

docker-bake.hcl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ variable "DOCS_FORMATS" {
1313
default = "md,yaml"
1414
}
1515

16+
variable "DOCS_FEATURES" {
17+
default = "profiles"
18+
}
19+
1620
group default {
1721
targets = [
1822
"all",
@@ -97,7 +101,8 @@ target mcp-gateway-dind {
97101
target "validate-docs" {
98102
inherits = ["_common"]
99103
args = {
100-
DOCS_FORMATS = DOCS_FORMATS
104+
DOCS_FORMATS = DOCS_FORMATS
105+
DOCS_FEATURES = DOCS_FEATURES
101106
}
102107
target = "docs-validate"
103108
output = ["type=cacheonly"]
@@ -106,7 +111,8 @@ target "validate-docs" {
106111
target "update-docs" {
107112
inherits = ["_common"]
108113
args = {
109-
DOCS_FORMATS = DOCS_FORMATS
114+
DOCS_FORMATS = DOCS_FORMATS
115+
DOCS_FEATURES = DOCS_FEATURES
110116
}
111117
target = "docs-update"
112118
output = ["./docs/generator/reference"]

docs/generator/generate.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ import (
1919
const defaultSourcePath = "/reference/"
2020

2121
type options struct {
22-
source string
23-
formats []string
22+
source string
23+
formats []string
24+
features []string
2425
}
2526

2627
func gen(opts *options) error {
@@ -36,7 +37,7 @@ func gen(opts *options) error {
3637
DisableAutoGenTag: true,
3738
}
3839

39-
cmd.AddCommand(commands.Root(context.TODO(), "", dockerCLI, features.AllDisabled()))
40+
cmd.AddCommand(commands.Root(context.TODO(), "", dockerCLI, features.WithEnabled(opts.features)))
4041

4142
c, err := clidocstool.New(clidocstool.Options{
4243
Root: cmd,
@@ -71,6 +72,7 @@ func run() error {
7172
flags := pflag.NewFlagSet(os.Args[0], pflag.ContinueOnError)
7273
flags.StringVar(&opts.source, "source", defaultSourcePath, "Docs source folder")
7374
flags.StringSliceVar(&opts.formats, "formats", []string{}, "Format (md, yaml)")
75+
flags.StringSliceVar(&opts.features, "features", []string{}, "Features to enable (e.g. profiles)")
7476
if err := flags.Parse(os.Args[1:]); err != nil {
7577
return err
7678
}

pkg/features/features.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,19 @@ func AllDisabled() Features {
4646
}
4747
}
4848

49+
// WithEnabled returns a Features with only the named features enabled.
50+
// Recognised names: "profiles".
51+
func WithEnabled(names []string) Features {
52+
f := &featuresImpl{}
53+
for _, name := range names {
54+
switch name {
55+
case "profiles":
56+
f.profilesEnabled = true
57+
}
58+
}
59+
return f
60+
}
61+
4962
func (f *featuresImpl) InitError() error {
5063
return f.initErr
5164
}

0 commit comments

Comments
 (0)