Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ jobs:

- 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: 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' }}
Expand Down
38 changes: 25 additions & 13 deletions cmd/gen-docs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
Expand Down
39 changes: 39 additions & 0 deletions cmd/gen-docs/main_test.go
Original file line number Diff line number Diff line change
@@ -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")
}
}