Add build-wiki command for isolated wiki generation
- Add BuildWikiWithOptions in native.go for building wiki from pre-existing topdata - Add runBuildWiki and parseBuildWikiArgs in app.go for CLI integration - Add --force flag to force rebuild even when output is current
This commit is contained in:
@@ -88,6 +88,11 @@ var commands = []command{
|
||||
description: "Convert between 2DA and native topdata JSON/module formats.",
|
||||
run: runConvertTopData,
|
||||
},
|
||||
{
|
||||
name: "build-wiki",
|
||||
description: "Build wiki pages from the current topdata state.",
|
||||
run: runBuildWiki,
|
||||
},
|
||||
}
|
||||
|
||||
func Run(args []string) (int, error) {
|
||||
@@ -550,6 +555,46 @@ func runConvertTopData(ctx context) error {
|
||||
return topdata.RunConvertCommand(ctx.args[1:], ctx.stdout)
|
||||
}
|
||||
|
||||
func runBuildWiki(ctx context) error {
|
||||
p, err := loadProject(ctx.cwd)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
opts, err := parseBuildWikiArgs("build-wiki", ctx.args[1:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
result, err := topdata.BuildWikiWithOptions(p, opts, func(message string) {
|
||||
fmt.Fprintf(ctx.stdout, "[build-wiki] %s\n", message)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(ctx.stdout, "project: %s\n", p.Config.Module.Name)
|
||||
fmt.Fprintf(ctx.stdout, "wiki output: %s\n", result.OutputDir)
|
||||
fmt.Fprintf(ctx.stdout, "wiki pages: %d\n", result.PageCount)
|
||||
fmt.Fprintf(ctx.stdout, "wiki status: %s\n", result.Status)
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseBuildWikiArgs(commandName string, args []string) (topdata.BuildWikiOptions, error) {
|
||||
opts := topdata.BuildWikiOptions{}
|
||||
for _, arg := range args {
|
||||
switch arg {
|
||||
case "--force":
|
||||
opts.Force = true
|
||||
case "-h", "--help":
|
||||
return opts, fmt.Errorf("usage: %s [--force]", commandName)
|
||||
default:
|
||||
return opts, fmt.Errorf("unknown %s argument %q", commandName, arg)
|
||||
}
|
||||
}
|
||||
return opts, nil
|
||||
}
|
||||
|
||||
func loadProject(cwd string) (*project.Project, error) {
|
||||
root, err := project.FindRoot(cwd)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user