From e9c96986d494b1a31066cfb593fb4c249d831376 Mon Sep 17 00:00:00 2001 From: "alex.stanfield" <13949480+chaptersix@users.noreply.github.com> Date: Fri, 6 Feb 2026 10:48:41 -0600 Subject: [PATCH 1/2] fix: support multiple -input flags in gen-docs --- .github/workflows/ci.yaml | 6 ++---- cmd/gen-docs/main.go | 38 +++++++++++++++++++++++++------------- cmd/gen-docs/main_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 17 deletions(-) create mode 100644 cmd/gen-docs/main_test.go diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 90f2f5265..85c2c83e8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -64,14 +64,12 @@ jobs: - name: Regen code, confirm unchanged if: ${{ matrix.checkGenCommands }} run: | - go run ./cmd/gen-commands -input internal/temporalcli/commands.yaml -pkg temporalcli -context "*CommandContext" > internal/temporalcli/commands.gen.go - go run ./cmd/gen-commands -input cliext/option-sets.yaml -pkg cliext > cliext/flags.gen.go + make gen git diff --exit-code - name: Generate docs, confirm working if: ${{ matrix.checkGenCommands }} - run: | - go run ./cmd/gen-docs -input internal/temporalcli/commands.yaml -input cliext/option-sets.yaml -output dist/docs + run: make gen-docs - name: Test cloud mTLS if: ${{ matrix.cloudTestTarget && env.HAS_SECRETS == 'true' }} diff --git a/cmd/gen-docs/main.go b/cmd/gen-docs/main.go index 72f4ecdec..11ea430e0 100644 --- a/cmd/gen-docs/main.go +++ b/cmd/gen-docs/main.go @@ -10,6 +10,18 @@ import ( "github.com/temporalio/cli/internal/commandsgen" ) +// stringSlice implements flag.Value to support multiple -input flags +type stringSlice []string + +func (s *stringSlice) String() string { + return fmt.Sprintf("%v", *s) +} + +func (s *stringSlice) Set(value string) error { + *s = append(*s, value) + return nil +} + func main() { if err := run(); err != nil { log.Fatal(err) @@ -18,41 +30,41 @@ func main() { func run() error { var ( - outputDir string - inputFile string + outputDir string + inputFiles stringSlice ) - flag.StringVar(&inputFile, "input", "", "Input YAML file (required)") + flag.Var(&inputFiles, "input", "Input YAML file (can be specified multiple times)") flag.StringVar(&outputDir, "output", ".", "Output directory for docs") flag.Parse() - // Read input from file - if inputFile == "" { + if len(inputFiles) == 0 { return fmt.Errorf("-input flag is required") } - yamlBytes, err := os.ReadFile(inputFile) - if err != nil { - return fmt.Errorf("failed reading input: %w", err) + + var yamlInputs [][]byte + for _, inputFile := range inputFiles { + data, err := os.ReadFile(inputFile) + if err != nil { + return fmt.Errorf("failed reading input %s: %w", inputFile, err) + } + yamlInputs = append(yamlInputs, data) } - // Create output directory if err := os.MkdirAll(outputDir, 0755); err != nil { return fmt.Errorf("failed creating output directory: %w", err) } - // Parse YAML - cmds, err := commandsgen.ParseCommands(yamlBytes) + cmds, err := commandsgen.ParseCommands(yamlInputs...) if err != nil { return fmt.Errorf("failed parsing YAML: %w", err) } - // Generate docs docs, err := commandsgen.GenerateDocsFiles(cmds) if err != nil { return fmt.Errorf("failed generating docs: %w", err) } - // Write files for filename, content := range docs { filePath := filepath.Join(outputDir, filename+".mdx") if err := os.WriteFile(filePath, content, 0644); err != nil { diff --git a/cmd/gen-docs/main_test.go b/cmd/gen-docs/main_test.go new file mode 100644 index 000000000..cdd68945c --- /dev/null +++ b/cmd/gen-docs/main_test.go @@ -0,0 +1,39 @@ +package main + +import ( + "os" + "path/filepath" + "testing" +) + +func TestGenDocsMultipleInputs(t *testing.T) { + outputDir := t.TempDir() + + oldArgs := os.Args + defer func() { os.Args = oldArgs }() + + os.Args = []string{ + "gen-docs", + "-input", filepath.Join("..", "..", "internal", "temporalcli", "commands.yaml"), + "-input", filepath.Join("..", "..", "cliext", "option-sets.yaml"), + "-output", outputDir, + } + + if err := run(); err != nil { + t.Fatalf("run() failed: %v", err) + } + + files, err := os.ReadDir(outputDir) + if err != nil { + t.Fatalf("failed to read output dir: %v", err) + } + + if len(files) == 0 { + t.Fatal("no files were generated") + } + + workflowPath := filepath.Join(outputDir, "workflow.mdx") + if _, err := os.Stat(workflowPath); os.IsNotExist(err) { + t.Fatal("workflow.mdx was not generated") + } +} From 641878c3ebdc7d04872c68fc821306f5836ff943 Mon Sep 17 00:00:00 2001 From: "alex.stanfield" <13949480+chaptersix@users.noreply.github.com> Date: Fri, 6 Feb 2026 13:03:56 -0600 Subject: [PATCH 2/2] use go commands --- .github/workflows/ci.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index e3f93cd98..21d8b9ab5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -82,12 +82,13 @@ jobs: - name: Regen code, confirm unchanged if: ${{ matrix.checkGenCommands }} run: | - make gen + go run ./cmd/gen-commands -input internal/temporalcli/commands.yaml -pkg temporalcli -context "*CommandContext" > internal/temporalcli/commands.gen.go + go run ./cmd/gen-commands -input cliext/option-sets.yaml -pkg cliext > cliext/flags.gen.go git diff --exit-code - name: Generate docs, confirm working if: ${{ matrix.checkGenCommands }} - run: make gen-docs + run: go run ./cmd/gen-docs -input internal/temporalcli/commands.yaml -input cliext/option-sets.yaml -output dist/docs - name: Test cloud mTLS if: ${{ matrix.cloudTestTarget && env.HAS_SECRETS == 'true' }}