update cli docs

This commit is contained in:
Alexander Wang 2023-02-05 00:34:43 -08:00
parent 3f8e752968
commit bec0332619
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
3 changed files with 13 additions and 3 deletions

View file

@ -64,8 +64,7 @@ Port listening address when used with
.Ar watch .Ar watch
.Ns . .Ns .
.It Fl t , -theme Ar 0 .It Fl t , -theme Ar 0
Set the diagram theme to the passed integer. For a list of available options, see Set the diagram theme ID
.Lk https://oss.terrastruct.com/d2
.Ns . .Ns .
.It Fl s , -sketch Ar false .It Fl s , -sketch Ar false
Renders the diagram to look like it was sketched by hand Renders the diagram to look like it was sketched by hand
@ -92,6 +91,8 @@ Print version information and exit.
Lists available layout engine options with short help. Lists available layout engine options with short help.
.It Ar layout Op Ar name .It Ar layout Op Ar name
Display long help for a particular layout engine, including its configuration options. Display long help for a particular layout engine, including its configuration options.
.It Ar themes
Lists available themes.
.It Ar fmt Ar file.d2 ... .It Ar fmt Ar file.d2 ...
Format all passed files. Format all passed files.
.El .El

View file

@ -12,6 +12,7 @@ import (
"oss.terrastruct.com/util-go/xmain" "oss.terrastruct.com/util-go/xmain"
"oss.terrastruct.com/d2/d2plugin" "oss.terrastruct.com/d2/d2plugin"
"oss.terrastruct.com/d2/d2themes/d2themescatalog"
) )
func help(ms *xmain.State) { func help(ms *xmain.State) {
@ -33,6 +34,7 @@ Flags:
Subcommands: Subcommands:
%[1]s layout - Lists available layout engine options with short help %[1]s layout - Lists available layout engine options with short help
%[1]s layout [name] - Display long help for a particular layout engine, including its configuration options %[1]s layout [name] - Display long help for a particular layout engine, including its configuration options
%[1]s themes - Lists available themes
%[1]s fmt file.d2 ... - Format passed files %[1]s fmt file.d2 ... - Format passed files
See more docs and the source code at https://oss.terrastruct.com/d2. See more docs and the source code at https://oss.terrastruct.com/d2.
@ -51,6 +53,10 @@ func layoutCmd(ctx context.Context, ms *xmain.State, ps []d2plugin.Plugin) error
} }
} }
func themesCmd(ctx context.Context, ms *xmain.State) {
fmt.Fprintf(ms.Stdout, "Available themes:\n%s", d2themescatalog.CLIString())
}
func shortLayoutHelp(ctx context.Context, ms *xmain.State, ps []d2plugin.Plugin) error { func shortLayoutHelp(ctx context.Context, ms *xmain.State, ps []d2plugin.Plugin) error {
var pluginLines []string var pluginLines []string
pinfos, err := d2plugin.ListPluginInfos(ctx, ps) pinfos, err := d2plugin.ListPluginInfos(ctx, ps)

View file

@ -60,7 +60,7 @@ func run(ctx context.Context, ms *xmain.State) (err error) {
return err return err
} }
layoutFlag := ms.Opts.String("D2_LAYOUT", "layout", "l", "dagre", `the layout engine used`) layoutFlag := ms.Opts.String("D2_LAYOUT", "layout", "l", "dagre", `the layout engine used`)
themeFlag, err := ms.Opts.Int64("D2_THEME", "theme", "t", 0, "the diagram theme ID. For a list of available options, see https://oss.terrastruct.com/d2") themeFlag, err := ms.Opts.Int64("D2_THEME", "theme", "t", 0, "the diagram theme ID")
if err != nil { if err != nil {
return err return err
} }
@ -102,6 +102,9 @@ func run(ctx context.Context, ms *xmain.State) (err error) {
return initPlaywright() return initPlaywright()
case "layout": case "layout":
return layoutCmd(ctx, ms, ps) return layoutCmd(ctx, ms, ps)
case "themes":
themesCmd(ctx, ms)
return nil
case "fmt": case "fmt":
return fmtCmd(ctx, ms) return fmtCmd(ctx, ms)
case "version": case "version":