Merge pull request #760 from alixander/icons

update CLI docs to include themes subcmd and icons link
This commit is contained in:
Alexander Wang 2023-02-05 00:43:46 -08:00 committed by GitHub
commit bb4c09773b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 9 deletions

View file

@ -24,6 +24,7 @@
- Improves package shape dimensions with short height. [#702](https://github.com/terrastruct/d2/pull/702) - Improves package shape dimensions with short height. [#702](https://github.com/terrastruct/d2/pull/702)
- Keeps person shape from becoming too distorted. [#702](https://github.com/terrastruct/d2/pull/702) - Keeps person shape from becoming too distorted. [#702](https://github.com/terrastruct/d2/pull/702)
- Ensures shapes with icons have enough padding for their labels. [#702](https://github.com/terrastruct/d2/pull/702) - Ensures shapes with icons have enough padding for their labels. [#702](https://github.com/terrastruct/d2/pull/702)
- `d2 themes` subcommand to list themes. [#760](https://github.com/terrastruct/d2/pull/760)
#### Bugfixes ⛑️ #### Bugfixes ⛑️

View file

@ -41,6 +41,15 @@ render anyway to enable iteration on a broken diagram.
.Pp .Pp
See more docs, the source code and license at See more docs, the source code and license at
.Lk https://oss.terrastruct.com/d2 .Lk https://oss.terrastruct.com/d2
.Ns .
.Pp
Hosted icons at
.Lk https://icons.terrastruct.com
.Ns .
.Pp
Playground runner at
.Lk https://play.d2lang.com
.Ns .
.Sh OPTIONS .Sh OPTIONS
.Bl -tag -width Fl .Bl -tag -width Fl
.It Fl w , -watch Ar false .It Fl w , -watch Ar false
@ -55,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
@ -83,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

@ -68,9 +68,9 @@ func (p dagrePlugin) Info(ctx context.Context) (*PluginInfo, error) {
Name: "dagre", Name: "dagre",
ShortHelp: "The directed graph layout library Dagre", ShortHelp: "The directed graph layout library Dagre",
LongHelp: fmt.Sprintf(`dagre is a directed graph layout library for JavaScript. LongHelp: fmt.Sprintf(`dagre is a directed graph layout library for JavaScript.
See https://github.com/dagrejs/dagre See https://d2lang.com/tour/dagre for more.
Flags correspond to ones found at https://github.com/dagrejs/dagre/wiki. See dagre's reference for more on each. Flags correspond to ones found at https://github.com/dagrejs/dagre/wiki.
Flags: Flags:
%s %s

View file

@ -89,9 +89,9 @@ func (p elkPlugin) Info(ctx context.Context) (*PluginInfo, error) {
ShortHelp: "Eclipse Layout Kernel (ELK) with the Layered algorithm.", ShortHelp: "Eclipse Layout Kernel (ELK) with the Layered algorithm.",
LongHelp: fmt.Sprintf(`ELK is a layout engine offered by Eclipse. LongHelp: fmt.Sprintf(`ELK is a layout engine offered by Eclipse.
Originally written in Java, it has been ported to Javascript and cross-compiled into D2. Originally written in Java, it has been ported to Javascript and cross-compiled into D2.
See https://github.com/kieler/elkjs for more. See https://d2lang.com/tour/elk for more.
Flags correspond to ones found at https://www.eclipse.org/elk/reference.html. See ELK's reference for more on each. Flags correspond to ones found at https://www.eclipse.org/elk/reference.html.
Flags: Flags:
%s %s

12
help.go
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,9 +34,12 @@ 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.
Hosted icons at https://icons.terrastruct.com.
Playground runner at https://play.d2lang.com.
`, filepath.Base(ms.Name), ms.Opts.Defaults()) `, filepath.Base(ms.Name), ms.Opts.Defaults())
} }
@ -49,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)
@ -77,7 +85,7 @@ Example:
Subcommands: Subcommands:
%s layout [layout name] - Display long help for a particular layout engine, including its configuration options %s layout [layout name] - Display long help for a particular layout engine, including its configuration options
See more docs at https://oss.terrastruct.com/d2 See more docs at https://d2lang.com/tour/layouts
`, strings.Join(pluginLines, "\n"), ms.Name) `, strings.Join(pluginLines, "\n"), ms.Name)
return nil return nil
} }

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":