Skip to content

Commit fe43c24

Browse files
committed
fix: apply all downstream requirements
1 parent 2d56036 commit fe43c24

File tree

6 files changed

+56
-16
lines changed

6 files changed

+56
-16
lines changed
Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
# This workflow will generate modular docs and publish to the modular-docs branch
22

3-
name: Modular docs publish
3+
name: Downstream docs publish
44

5+
# on:
6+
# push:
7+
# tags:
8+
# - 'v*'
9+
10+
## For testing
511
on:
612
push:
7-
branches: [ main ]
13+
branches: [ adoc-modular ]
814

915
jobs:
1016
build:
@@ -16,10 +22,10 @@ jobs:
1622
uses: actions/setup-go@v2
1723
with:
1824
go-version: 1.16.x
19-
- run: make generate-modular-docs
20-
name: Generate modular-docs
25+
- run: make generate-downstream-docs
26+
name: Generate generate-downstream-docs
2127
- name: Deploy
2228
uses: JamesIves/github-pages-deploy-action@4.1.8
2329
with:
24-
branch: modular-docs # The branch the action should deploy to.
30+
branch: downstream-docs # The branch the action should deploy to.
2531
folder: dist # The folder the action should deploy.

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,14 @@ check-docs: generate-docs ## Check whether reference documentation needs to be g
8585

8686
generate-docs: ## Generate command-line reference documentation
8787
rm -rf ./docs/commands/*
88-
go run ./cmd/rhoas docs --dir ./docs/commands --file-format adoc
88+
go run ./cmd/rhoas docs --dir ./docs/commands --file-format md
8989
.PHONY: generate-docs
9090

91+
generate-downstream-docs: ## Generate command-line reference documentation in adoc format
92+
rm -rf ./docs/commands/*
93+
go run ./cmd/rhoas docs --dir ./dist --file-format adoc
94+
.PHONY: generate-downstream-docs
95+
9196
lint-lang: ## Lint i18n files
9297
go install github.com/redhat-developer/app-services-go-linter/cmd/app-services-go-linter@latest
9398
app-services-go-linter ./...

internal/doc/GeneratorOptions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ type GeneratorOptions struct {
2020
GenerateIndex bool
2121

2222
// IndexLocation - name and folder of the assembly file (typically ./README.adoc)
23-
IndexLocation string
23+
IndexFile string
2424
}

internal/doc/docs_index.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package doc
22

33
import (
44
"os"
5+
"path"
6+
"path/filepath"
57
"text/template"
68

79
"github.com/pkg/errors"
@@ -64,7 +66,7 @@ func CreateIndexFile(rootCmd *cobra.Command, generationOptions *GeneratorOptions
6466
Groups: groups,
6567
}
6668

67-
output, err := os.Create(generationOptions.IndexLocation)
69+
output, err := os.Create(generationOptions.IndexFile)
6870
if err != nil {
6971
return errors.WithStack(err)
7072
}
@@ -83,6 +85,11 @@ func CreateIndexFile(rootCmd *cobra.Command, generationOptions *GeneratorOptions
8385

8486
func CollectNames(cmd *cobra.Command, options *GeneratorOptions) []string {
8587
filename := options.FileNameGenerator(cmd)
88+
89+
filename, err := filepath.Rel(path.Dir(options.IndexFile), filename)
90+
if err != nil {
91+
panic(err)
92+
}
8693
names := []string{filename}
8794
if cmd.HasSubCommands() {
8895
for _, sub := range cmd.Commands() {

internal/doc/modular_adoc_docs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ func GenAsciidocTree(cmd *cobra.Command, options *GeneratorOptions) error {
322322
return err
323323
}
324324

325-
if options.GenerateIndex && options.IndexLocation != "" {
325+
if options.GenerateIndex && options.IndexFile != "" {
326326
return CreateIndexFile(cmd, options)
327327
}
328328
return nil

pkg/cmd/docs/docs.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ package docs
22

33
import (
44
"fmt"
5+
"os"
6+
"path"
7+
"path/filepath"
58
"time"
69

710
rhoasdoc "github.com/redhat-developer/app-services-cli/internal/doc"
@@ -18,10 +21,10 @@ const (
1821
)
1922

2023
type options struct {
21-
dir string
22-
format string
23-
24-
logger logging.Logger
24+
dir string
25+
format string
26+
filePrefix string
27+
logger logging.Logger
2528
}
2629

2730
// NewDocsCmd creates a new docs command
@@ -42,6 +45,7 @@ func NewDocsCmd(f *factory.Factory) *cobra.Command {
4245

4346
cmd.Flags().StringVar(&opts.format, "file-format", "md", "Output format of the generated documentation. Valid options are: 'md' (markdown), 'adoc' (Asciidoc) and 'man'")
4447
cmd.Flags().StringVar(&opts.dir, "dir", "./docs", "The directory to output the generated documentation files")
48+
cmd.Flags().StringVar(&opts.filePrefix, "file-prefix", "ref-", "Prefix for each documentation file")
4549
return cmd
4650
}
4751

@@ -60,10 +64,28 @@ func runCmd(cmd *cobra.Command, opts *options) (err error) {
6064
}
6165
err = doc.GenManTree(cmd.Root(), header, opts.dir)
6266
case asciidoc:
63-
err = rhoasdoc.GenAsciidocTree(cmd.Root(), &rhoasdoc.GeneratorOptions{
64-
Dir: opts.dir,
67+
docsDir := path.Clean(opts.dir + "/modules")
68+
assembliesDir := path.Clean(opts.dir + "/assemblies")
69+
err = os.MkdirAll(docsDir, 0755)
70+
if err != nil {
71+
return err
72+
}
73+
err = os.MkdirAll(assembliesDir, 0755)
74+
if err != nil {
75+
return err
76+
}
77+
78+
options := rhoasdoc.GeneratorOptions{
79+
Dir: docsDir,
6580
GenerateIndex: true,
66-
IndexLocation: opts.dir + "/README.adoc"})
81+
IndexFile: assembliesDir + "/assembly-cli-command-reference.adoc"}
82+
83+
options.FileNameGenerator = func(c *cobra.Command) string {
84+
basename := opts.filePrefix + rhoasdoc.GetNormalizedCommandPath(c) + ".adoc"
85+
return filepath.Join(options.Dir, basename)
86+
}
87+
88+
err = rhoasdoc.GenAsciidocTree(cmd.Root(), &options)
6789
}
6890

6991
if err != nil {

0 commit comments

Comments
 (0)