fix(cli): do not exit after 1st formatted file
This commit is contained in:
parent
83aad90f64
commit
b560e3b263
3 changed files with 18 additions and 1 deletions
|
|
@ -5,3 +5,5 @@
|
||||||
#### Improvements 🧹
|
#### Improvements 🧹
|
||||||
|
|
||||||
#### Bugfixes ⛑️
|
#### Bugfixes ⛑️
|
||||||
|
|
||||||
|
- Fixes `d2 fmt` to format all files passed as arguments rather than first non-formatted only [#1523](https://github.com/terrastruct/d2/issues/1523)
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,9 @@ func fmtCmd(ctx context.Context, ms *xmain.State) (err error) {
|
||||||
|
|
||||||
output := []byte(d2format.Format(m))
|
output := []byte(d2format.Format(m))
|
||||||
if !bytes.Equal(output, input) {
|
if !bytes.Equal(output, input) {
|
||||||
return ms.WritePath(inputPath, output)
|
if err := ms.WritePath(inputPath, output); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -531,6 +531,19 @@ i used to read
|
||||||
assert.Equal(t, "x -> y\n", string(got))
|
assert.Equal(t, "x -> y\n", string(got))
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "fmt-multiple-files",
|
||||||
|
run: func(t *testing.T, ctx context.Context, dir string, env *xos.Env) {
|
||||||
|
writeFile(t, dir, "foo.d2", `a ---> b`)
|
||||||
|
writeFile(t, dir, "bar.d2", `x ---> y`)
|
||||||
|
err := runTestMainPersist(t, ctx, dir, env, "fmt", "foo.d2", "bar.d2")
|
||||||
|
assert.Success(t, err)
|
||||||
|
gotFoo := readFile(t, dir, "foo.d2")
|
||||||
|
gotBar := readFile(t, dir, "bar.d2")
|
||||||
|
assert.Equal(t, "a -> b\n", string(gotFoo))
|
||||||
|
assert.Equal(t, "x -> y\n", string(gotBar))
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue