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)
- 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)
- `d2 themes` subcommand to list themes. [#760](https://github.com/terrastruct/d2/pull/760)
#### Bugfixes ⛑️

View file

@ -41,6 +41,15 @@ render anyway to enable iteration on a broken diagram.
.Pp
See more docs, the source code and license at
.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
.Bl -tag -width Fl
.It Fl w , -watch Ar false
@ -55,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
@ -83,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

View file

@ -68,9 +68,9 @@ func (p dagrePlugin) Info(ctx context.Context) (*PluginInfo, error) {
Name: "dagre",
ShortHelp: "The directed graph layout library Dagre",
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:
%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.",
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.
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:
%s

12
help.go
View file

@ -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,9 +34,12 @@ 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
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())
}
@ -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 {
var pluginLines []string
pinfos, err := d2plugin.ListPluginInfos(ctx, ps)
@ -77,7 +85,7 @@ Example:
Subcommands:
%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)
return nil
}

View file

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