From f74e2606248ef4ebc767303eeb9896574162da43 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 17 Mar 2023 20:10:44 -0700 Subject: [PATCH 1/3] browser flag --- ci/release/template/man/d2.1 | 3 +++ d2cli/main.go | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/ci/release/template/man/d2.1 b/ci/release/template/man/d2.1 index ed1b37017..8cc62a472 100644 --- a/ci/release/template/man/d2.1 +++ b/ci/release/template/man/d2.1 @@ -80,6 +80,9 @@ Renders the diagram to look like it was sketched by hand .It Fl -pad Ar 100 Pixels padded around the rendered diagram .Ns . +.It Fl -browser Ar true +Open the browser and go to the address that watch streams updates to +.Ns . .It Fl l , -layout Ar dagre Set the diagram layout engine to the passed string. For a list of available options, run .Ar layout diff --git a/d2cli/main.go b/d2cli/main.go index 5c92efb5e..a65d2a12e 100644 --- a/d2cli/main.go +++ b/d2cli/main.go @@ -83,6 +83,10 @@ func Run(ctx context.Context, ms *xmain.State) (err error) { if err != nil { return err } + browserFlag, err := ms.Opts.Bool("BROWSER", "browser", "", true, "open the browser and go to the address that watch streams updates to") + if err != nil { + return err + } ps, err := d2plugin.ListPlugins(ctx) if err != nil { @@ -126,6 +130,9 @@ func Run(ctx context.Context, ms *xmain.State) (err error) { if *debugFlag { ms.Env.Setenv("DEBUG", "1") } + if !*browserFlag { + ms.Env.Setenv("BROWSER", "0") + } var inputPath string var outputPath string From dc079c676dbba17f1f879d15a521fc3fb3c05d34 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Fri, 17 Mar 2023 20:13:01 -0700 Subject: [PATCH 2/3] changelog --- ci/release/changelogs/next.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 7dc3c7751..32734248a 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -2,6 +2,8 @@ #### Improvements 🧹 +- `--browser` flag on CLI controls `BROWSER` environment variable for not opening browser in watch mode. [#1052](https://github.com/terrastruct/d2/pull/1052) + #### Bugfixes ⛑️ - Fixes fill-pattern replacement in the API. [#1051](https://github.com/terrastruct/d2/pull/1051) From efc85915c68d8939e20dea8cd6aae78f42b9dbd4 Mon Sep 17 00:00:00 2001 From: Alexander Wang Date: Sat, 18 Mar 2023 00:48:18 -0700 Subject: [PATCH 3/3] change flag to string --- ci/release/template/man/d2.1 | 2 +- d2cli/main.go | 9 +++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/ci/release/template/man/d2.1 b/ci/release/template/man/d2.1 index 8cc62a472..0981c0226 100644 --- a/ci/release/template/man/d2.1 +++ b/ci/release/template/man/d2.1 @@ -81,7 +81,7 @@ Renders the diagram to look like it was sketched by hand Pixels padded around the rendered diagram .Ns . .It Fl -browser Ar true -Open the browser and go to the address that watch streams updates to +Browser executable that watch opens. Setting to 0 opens no browser .Ns . .It Fl l , -layout Ar dagre Set the diagram layout engine to the passed string. For a list of available options, run diff --git a/d2cli/main.go b/d2cli/main.go index a65d2a12e..0c5f83fac 100644 --- a/d2cli/main.go +++ b/d2cli/main.go @@ -83,10 +83,7 @@ func Run(ctx context.Context, ms *xmain.State) (err error) { if err != nil { return err } - browserFlag, err := ms.Opts.Bool("BROWSER", "browser", "", true, "open the browser and go to the address that watch streams updates to") - if err != nil { - return err - } + browserFlag := ms.Opts.String("BROWSER", "browser", "", "", "browser executable that watch opens. Setting to 0 opens no browser.") ps, err := d2plugin.ListPlugins(ctx) if err != nil { @@ -130,8 +127,8 @@ func Run(ctx context.Context, ms *xmain.State) (err error) { if *debugFlag { ms.Env.Setenv("DEBUG", "1") } - if !*browserFlag { - ms.Env.Setenv("BROWSER", "0") + if *browserFlag != "" { + ms.Env.Setenv("BROWSER", *browserFlag) } var inputPath string