diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 10eb2455f..2a3b66356 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -1,6 +1,6 @@ #### Features 🚀 -- autoformat is supported on the CLI with the `fmt` subcommand. +- Formatting of d2 scripts is supported on the CLI with the `fmt` subcommand. [#292](https://github.com/terrastruct/d2/pull/292) - Latex is now supported. See [docs](https://d2lang.com/tour/text) for more. [#229](https://github.com/terrastruct/d2/pull/229) diff --git a/ci/release/template/man/d2.1 b/ci/release/template/man/d2.1 index 8347bd8fe..275eca9da 100644 --- a/ci/release/template/man/d2.1 +++ b/ci/release/template/man/d2.1 @@ -78,7 +78,7 @@ Lists available layout engine options with short help. .It Ar layout Op Ar name Display long help for a particular layout engine. .It Ar fmt Ar file.d2 -Autoformat +Format .Ar file.d2 .Ns . .El diff --git a/ci/sub b/ci/sub index 702b77122..a39a67857 160000 --- a/ci/sub +++ b/ci/sub @@ -1 +1 @@ -Subproject commit 702b771228f41e5485b5f3f593ce79f6efcb555d +Subproject commit a39a678570a0454d6bf63f9012fb5ec107e24df5 diff --git a/autofmt.go b/fmt.go similarity index 79% rename from autofmt.go rename to fmt.go index 749c07981..49fd5677b 100644 --- a/autofmt.go +++ b/fmt.go @@ -11,14 +11,14 @@ import ( "oss.terrastruct.com/d2/lib/xmain" ) -func autofmt(ctx context.Context, ms *xmain.State) (err error) { - defer xdefer.Errorf(&err, "autofmt failed") +func fmtCmd(ctx context.Context, ms *xmain.State) (err error) { + defer xdefer.Errorf(&err, "failed to fmt") ms.Opts = xmain.NewOpts(ms.Env, ms.Log, ms.Opts.Flags.Args()[1:]) if len(ms.Opts.Args) == 0 { return xmain.UsageErrorf("fmt must be passed the file to be formatted") } else if len(ms.Opts.Args) > 1 { - return xmain.UsageErrorf("fmt only accepts one argument for the file to be formatted") + return xmain.UsageErrorf("fmt accepts only one argument for the file to be formatted") } inputPath := ms.Opts.Args[0] diff --git a/help.go b/help.go index aff1a7219..6f2f93637 100644 --- a/help.go +++ b/help.go @@ -32,13 +32,13 @@ 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 - %[1]s fmt file.d2 - Autoformat file.d2 + %[1]s fmt file.d2 - Format file.d2 See more docs and the source code at https://oss.terrastruct.com/d2 `, filepath.Base(ms.Name), ms.Opts.Defaults()) } -func layoutHelp(ctx context.Context, ms *xmain.State) error { +func layoutCmd(ctx context.Context, ms *xmain.State) error { if len(ms.Opts.Flags.Args()) == 1 { return shortLayoutHelp(ctx, ms) } else if len(ms.Opts.Flags.Args()) == 2 { diff --git a/main.go b/main.go index 34af23f59..29ace7b16 100644 --- a/main.go +++ b/main.go @@ -73,9 +73,9 @@ func run(ctx context.Context, ms *xmain.State) (err error) { if len(ms.Opts.Flags.Args()) > 0 { switch ms.Opts.Flags.Arg(0) { case "layout": - return layoutHelp(ctx, ms) + return layoutCmd(ctx, ms) case "fmt": - return autofmt(ctx, ms) + return fmtCmd(ctx, ms) case "version": if len(ms.Opts.Flags.Args()) > 1 { return xmain.UsageErrorf("version subcommand accepts no arguments")