treefmt icon indicating copy to clipboard operation
treefmt copied to clipboard

what are the stdio flags that a plugin needs to support ?

Open gedw99 opened this issue 1 year ago • 4 comments

Hey,

pretty cool stuff.

I have a file format that is just a text format for a Science Project, and wrote a golang based Fmt thing that parses the file and spits out into via STDOUT.

I had a look at the docs at https://treefmt.com/formatter-spec, but did not see the stdio args needed.

Can you let me know the args for input and output that it needs to support to work with treefmt ?

gedw99 avatar Oct 05 '24 09:10 gedw99

If dshfmt wrapping another formatter?

Try changing it so it takes the list of files to format as an argument, and then writes the result directly to the file if the content has changed.

Here is a small wrapper in case dshfmt is a wrapper

#!/usr/bin/env bash

# Iterate on each file passed as arguments
for file in "$@"; do
  original="$(< "$file")
  # mystdioformatter is the original formatter that only supports stdio 
  new=$(mystdioformatter < "$file")
  # only write back the change if the content has changed, to adhere to the formatter spec
  if [[ $original != $new ]]; then
    echo -n "$new" > "$file"
  fi
done

zimbatm avatar Oct 05 '24 10:10 zimbatm