cli: Output layers under subdirectory

This commit is contained in:
Anmol Sethi 2023-01-27 11:01:16 -08:00
parent 2d36513e2c
commit d80b2d3842
No known key found for this signature in database
GPG key ID: 25BC68888A99A8BA

View file

@ -5,6 +5,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings" "strings"
@ -323,7 +324,10 @@ func _render(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketc
} }
} }
outputPath = layerOutputPath(outputPath, diagram) err = os.MkdirAll(filepath.Dir(outputPath), 0755)
if err != nil {
return svg, err
}
err = ms.WritePath(outputPath, out) err = ms.WritePath(outputPath, out)
if err != nil { if err != nil {
return svg, err return svg, err
@ -340,7 +344,7 @@ func layerOutputPath(outputPath string, d *d2target.Diagram) string {
} }
ext := filepath.Ext(outputPath) ext := filepath.Ext(outputPath)
outputPath = strings.TrimSuffix(outputPath, ext) outputPath = strings.TrimSuffix(outputPath, ext)
outputPath += "-" + d.Name outputPath += "/" + d.Name
outputPath += ext outputPath += ext
return outputPath return outputPath
} }