Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d2cli: Accept abspaths again #979

Merged
merged 1 commit into from
Mar 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
#### Improvements 🧹

#### Bugfixes ⛑️

- Accept absolute paths again on the CLI. [#979](https://github.com/terrastruct/d2/pull/979)
nhooyr marked this conversation as resolved.
Show resolved Hide resolved
8 changes: 4 additions & 4 deletions d2cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ func Run(ctx context.Context, ms *xmain.State) (err error) {
}
}
if inputPath != "-" {
inputPath = filepath.Join(ms.PWD, inputPath)
inputPath = ms.AbsPath(inputPath)
d, err := os.Stat(inputPath)
if err == nil && d.IsDir() {
inputPath = filepath.Join(inputPath, "index.d2")
}
}
if outputPath != "-" {
outputPath = filepath.Join(ms.PWD, outputPath)
outputPath = ms.AbsPath(outputPath)
}

match := d2themescatalog.Find(*themeFlag)
Expand Down Expand Up @@ -308,7 +308,7 @@ func compile(ctx context.Context, ms *xmain.State, plugin d2plugin.Plugin, sketc

if filepath.Ext(outputPath) == ".pdf" {
dur := time.Since(start)
ms.Log.Success.Printf("successfully compiled %s to %s in %s", inputPath, outputPath, dur)
ms.Log.Success.Printf("successfully compiled %s to %s in %s", ms.HumanPath(inputPath), ms.HumanPath(outputPath), dur)
}

return svg, true, nil
Expand Down Expand Up @@ -383,7 +383,7 @@ func render(ctx context.Context, ms *xmain.State, compileDur time.Duration, plug
return svg, err
}
dur := compileDur + time.Since(start)
ms.Log.Success.Printf("successfully compiled %s to %s in %s", inputPath, boardOutputPath, dur)
ms.Log.Success.Printf("successfully compiled %s to %s in %s", ms.HumanPath(inputPath), ms.HumanPath(boardOutputPath), dur)
return svg, nil
}

Expand Down
7 changes: 4 additions & 3 deletions d2cli/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type watcherOpts struct {
port string
inputPath string
outputPath string
pwd string
bundle bool
forceAppendix bool
pw png.Playwright
Expand Down Expand Up @@ -216,7 +217,7 @@ func (w *watcher) watchLoop(ctx context.Context) error {
if err != nil {
return err
}
w.ms.Log.Info.Printf("compiling %v...", w.inputPath)
w.ms.Log.Info.Printf("compiling %v...", w.ms.HumanPath(w.inputPath))
w.requestCompile()

eatBurstTimer := time.NewTimer(0)
Expand Down Expand Up @@ -270,7 +271,7 @@ func (w *watcher) watchLoop(ctx context.Context) error {
// misleading error.
eatBurstTimer.Reset(time.Millisecond * 16)
case <-eatBurstTimer.C:
w.ms.Log.Info.Printf("detected change in %v: recompiling...", w.inputPath)
w.ms.Log.Info.Printf("detected change in %v: recompiling...", w.ms.HumanPath(w.inputPath))
w.requestCompile()
case err, ok := <-w.fw.Errors:
if !ok {
Expand Down Expand Up @@ -300,7 +301,7 @@ func (w *watcher) ensureAddWatch(ctx context.Context) (time.Time, error) {
return mt, nil
}
if interval >= time.Second {
w.ms.Log.Error.Printf("failed to watch inputPath %q: %v (retrying in %v)", w.inputPath, err, interval)
w.ms.Log.Error.Printf("failed to watch inputPath %q: %v (retrying in %v)", w.ms.HumanPath(w.inputPath), err, interval)
}

tc.Reset(interval)
Expand Down
10 changes: 10 additions & 0 deletions e2etests-cli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ layers: {
assert.Testdata(t, ".svg", stdout.Bytes())
},
},
{
name: "abspath",
run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {
writeFile(t, dir, "hello-world.d2", `x -> y`)
err := runTestMain(t, ctx, dir, env, filepath.Join(dir, "hello-world.d2"))
assert.Success(t, err)
svg := readFile(t, dir, "hello-world.svg")
assert.Testdata(t, ".svg", svg)
},
},
}

ctx := context.Background()
Expand Down
23 changes: 23 additions & 0 deletions e2etests-cli/testdata/TestCLI_E2E/abspath.exp.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion go.mod

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.