Add deploy-wiki command for native DokuWiki deployment

- Add DeployWikiWithOptions function in new wiki_deploy.go
- Add deploy-wiki command to sow-toolkit CLI
- Supports DOKUWIKI_RPC_* and GITHUB_REF_NAME env vars
- Includes --dry-run, --source-dir, --manifest options
This commit is contained in:
2026-04-18 12:23:24 +02:00
parent c52311ce5f
commit dfde20f679
2 changed files with 586 additions and 0 deletions
+122
View File
@@ -93,6 +93,11 @@ var commands = []command{
description: "Build wiki pages from the current topdata state.",
run: runBuildWiki,
},
{
name: "deploy-wiki",
description: "Deploy wiki pages to DokuWiki.",
run: runDeployWiki,
},
}
func Run(args []string) (int, error) {
@@ -595,6 +600,123 @@ func parseBuildWikiArgs(commandName string, args []string) (topdata.BuildWikiOpt
return opts, nil
}
func runDeployWiki(ctx context) error {
p, err := loadProject(ctx.cwd)
if err != nil {
return err
}
opts, err := parseDeployWikiArgs("deploy-wiki", ctx.args[1:])
if err != nil {
return err
}
result, err := topdata.DeployWikiWithOptions(p, opts, func(message string) {
fmt.Fprintf(ctx.stdout, "[deploy-wiki] %s\n", message)
})
if err != nil {
return err
}
fmt.Fprintf(ctx.stdout, "project: %s\n", p.Config.Module.Name)
fmt.Fprintf(ctx.stdout, "local pages: %d\n", result.LocalPages)
fmt.Fprintf(ctx.stdout, "updated: %d\n", result.Updated)
fmt.Fprintf(ctx.stdout, "skipped: %d\n", result.Skipped)
fmt.Fprintf(ctx.stdout, "deleted: %d\n", result.Deleted)
fmt.Fprintf(ctx.stdout, "manifest: %s\n", result.Manifest)
return nil
}
func parseDeployWikiArgs(commandName string, args []string) (topdata.DeployWikiOptions, error) {
opts := topdata.DeployWikiOptions{}
for i := 0; i < len(args); i++ {
arg := args[i]
switch arg {
case "--source-dir":
i++
if i >= len(args) {
return opts, fmt.Errorf("--source-dir requires a value")
}
opts.SourceDir = args[i]
case "--endpoint":
i++
if i >= len(args) {
return opts, fmt.Errorf("--endpoint requires a value")
}
opts.Endpoint = args[i]
case "--username":
i++
if i >= len(args) {
return opts, fmt.Errorf("--username requires a value")
}
opts.Username = args[i]
case "--password":
i++
if i >= len(args) {
return opts, fmt.Errorf("--password requires a value")
}
opts.Password = args[i]
case "--version":
i++
if i >= len(args) {
return opts, fmt.Errorf("--version requires a value")
}
opts.Version = args[i]
case "--namespace":
i++
if i >= len(args) {
return opts, fmt.Errorf("--namespace requires a value")
}
opts.Namespaces = append(opts.Namespaces, args[i])
case "--manifest":
i++
if i >= len(args) {
return opts, fmt.Errorf("--manifest requires a value")
}
opts.ManifestPath = args[i]
case "--dry-run":
opts.DryRun = true
case "-h", "--help":
return opts, fmt.Errorf("usage: %s [--source-dir <path>] [--endpoint <url>] [--username <user>] [--password <pass>] [--version <ver>] [--namespace <ns> ...] [--manifest <path>] [--dry-run]", commandName)
default:
if strings.HasPrefix(arg, "--source-dir=") {
opts.SourceDir = strings.TrimPrefix(arg, "--source-dir=")
} else if strings.HasPrefix(arg, "--endpoint=") {
opts.Endpoint = strings.TrimPrefix(arg, "--endpoint=")
} else if strings.HasPrefix(arg, "--username=") {
opts.Username = strings.TrimPrefix(arg, "--username=")
} else if strings.HasPrefix(arg, "--password=") {
opts.Password = strings.TrimPrefix(arg, "--password=")
} else if strings.HasPrefix(arg, "--version=") {
opts.Version = strings.TrimPrefix(arg, "--version=")
} else if strings.HasPrefix(arg, "--namespace=") {
opts.Namespaces = append(opts.Namespaces, strings.TrimPrefix(arg, "--namespace="))
} else if strings.HasPrefix(arg, "--manifest=") {
opts.ManifestPath = strings.TrimPrefix(arg, "--manifest=")
} else if arg == "--dry-run" {
opts.DryRun = true
} else {
return opts, fmt.Errorf("unknown %s argument %q", commandName, arg)
}
}
}
if opts.Endpoint == "" {
opts.Endpoint = os.Getenv("DOKUWIKI_RPC_ENDPOINT")
}
if opts.Username == "" {
opts.Username = os.Getenv("DOKUWIKI_RPC_USERNAME")
}
if opts.Password == "" {
opts.Password = os.Getenv("DOKUWIKI_RPC_PASSWORD")
}
if opts.Version == "" {
opts.Version = os.Getenv("GITHUB_REF_NAME")
}
return opts, nil
}
func loadProject(cwd string) (*project.Project, error) {
root, err := project.FindRoot(cwd)
if err != nil {