From bec0332619b1aec76162ed87c50e0ab72a6c7f6a Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sun, 5 Feb 2023 00:34:43 -0800 Subject: [PATCH] update cli docs --- ci/release/template/man/d2.1 | 5 +++-- help.go | 6 ++++++ main.go | 5 ++++- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ci/release/template/man/d2.1 b/ci/release/template/man/d2.1 index 90a7abec7..d6d3f3cc4 100644 --- a/ci/release/template/man/d2.1 +++ b/ci/release/template/man/d2.1 @@ -64,8 +64,7 @@ Port listening address when used with .Ar watch .Ns . .It Fl t , -theme Ar 0 -Set the diagram theme to the passed integer. For a list of available options, see -.Lk https://oss.terrastruct.com/d2 +Set the diagram theme ID .Ns . .It Fl s , -sketch Ar false 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. .It Ar layout Op Ar name Display long help for a particular layout engine, including its configuration options. +.It Ar themes +Lists available themes. .It Ar fmt Ar file.d2 ... Format all passed files. .El diff --git a/help.go b/help.go index 05be4b4ab..f78369f07 100644 --- a/help.go +++ b/help.go @@ -12,6 +12,7 @@ import ( "oss.terrastruct.com/util-go/xmain" "oss.terrastruct.com/d2/d2plugin" + "oss.terrastruct.com/d2/d2themes/d2themescatalog" ) func help(ms *xmain.State) { @@ -33,6 +34,7 @@ Flags: Subcommands: %[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 themes - Lists available themes %[1]s fmt file.d2 ... - Format passed files 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 { var pluginLines []string pinfos, err := d2plugin.ListPluginInfos(ctx, ps) diff --git a/main.go b/main.go index f2b4bcd82..08673a0cf 100644 --- a/main.go +++ b/main.go @@ -60,7 +60,7 @@ func run(ctx context.Context, ms *xmain.State) (err error) { return err } 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 { return err } @@ -102,6 +102,9 @@ func run(ctx context.Context, ms *xmain.State) (err error) { return initPlaywright() case "layout": return layoutCmd(ctx, ms, ps) + case "themes": + themesCmd(ctx, ms) + return nil case "fmt": return fmtCmd(ctx, ms) case "version":