diff --git a/ci/release/template/man/d2.1 b/ci/release/template/man/d2.1 index 2a72fc4d5..1bb889994 100644 --- a/ci/release/template/man/d2.1 +++ b/ci/release/template/man/d2.1 @@ -80,7 +80,7 @@ Renders the diagram to look like it was sketched by hand .It Fl -center Ar flag Center the SVG in the containing viewbox, such as your browser screen .Ns . -.It Fl -scale Ar fit +.It Fl -scale Ar -1 Set a fixed render scale (e.g. 0.5 to halve rendered size). If none provided, SVG will fit to screen .Ns . .It Fl -font-regular diff --git a/d2cli/main.go b/d2cli/main.go index 90f550b2c..d36e03c4a 100644 --- a/d2cli/main.go +++ b/d2cli/main.go @@ -107,7 +107,10 @@ func Run(ctx context.Context, ms *xmain.State) (err error) { if err != nil { return err } - scaleFlag := ms.Opts.String("SCALE", "scale", "", "fit", "set a fixed render scale (e.g. 0.5 to halve rendered size). If none provided, SVG will fit to screen.") + scaleFlag, err := ms.Opts.Float64("SCALE", "scale", "", -1, "set a fixed render scale (e.g. 0.5 to halve rendered size). If none provided, SVG will fit to screen.") + if err != nil { + return err + } fontRegularFlag := ms.Opts.String("D2_FONT_REGULAR", "font-regular", "", "", "path to .ttf file to use for the regular font. If none provided, Source Sans Pro Regular is used.") fontItalicFlag := ms.Opts.String("D2_FONT_ITALIC", "font-italic", "", "", "path to .ttf file to use for the italic font. If none provided, Source Sans Pro Regular-Italic is used.") @@ -234,12 +237,8 @@ func Run(ctx context.Context, ms *xmain.State) (err error) { ms.Log.Debug.Printf("using dark theme %s (ID: %d)", match.Name, *darkThemeFlag) } var scale *float64 - if scaleFlag != nil && *scaleFlag != "fit" { - f, err := strconv.ParseFloat(*scaleFlag, 64) - if err != nil || f <= 0. { - return xmain.UsageErrorf("-scale must a positive floating point number or \"fit\".") - } - scale = &f + if scaleFlag != nil && *scaleFlag > 0. { + scale = scaleFlag } plugin, err := d2plugin.FindPlugin(ctx, ps, *layoutFlag)