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

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

Open
gedw99 opened this issue Oct 5, 2024 · 4 comments
Open

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

gedw99 opened this issue Oct 5, 2024 · 4 comments

Comments

@gedw99
Copy link

gedw99 commented Oct 5, 2024

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 gedw99 changed the title what is the stdio flags that a plugin need to support ? what are the stdio flags that a plugin needs to support ? Oct 5, 2024
@gedw99
Copy link
Author

gedw99 commented Oct 5, 2024

I got a Test harness setup but:

treefmt .  --verbose -vv --on-unmatched debug
DEBU format: config-file=/Users/apple/workspace/go/src/numtide__treefmt/.test/dsh/treefmt.toml tree-root=/Users/apple/workspace/go/src/numtide__treefmt/.test/dsh
DEBU cache: formatter '%s' has changed dsh=size 2473522=modTime 2024-10-05 19:16:22.402481699 +1000 AEST=cachedSize 2420530=cachedModTime 2024-10-05 18:28:44.353360791 +1000 AEST="missing value"
DEBU format | dsh: match: /Users/apple/workspace/go/numtide__treefmt/.test/dsh/test-02-sub.dsh
DEBU format | dsh: match: /Users/apple/workspace/go/numtide__treefmt/.test/dsh/test-02.dsh
DEBU format: no formatter for path: test-dsh.toml
DEBU format | dsh: match: /Users/apple/workspace/go/numtide__treefmt/.test/dsh/test.dsh
DEBU format: no formatter for path: treefmt.toml
DEBU cache: finished generating change set in 124.375µs
DEBU format | dsh: executing: /Users/apple/workspace/go/numtide__treefmt/.dep/dshfmt -w test-02-sub.dsh test-02.dsh test.dsh
ERRO format | dsh: failed to apply with options '[-w]': exit status 2
dsh error:
flag provided but not defined: -w
Usage of /Users/apple/workspace/go/src/numtide__treefmt/.bin/dshfmt
  -dump
        dump raw parsed data
  -fsort
        show keyword frequencies
  -i string
        indent (default "\t")
  -ksort
        show keyword counts
  -v    verbose diagnostics

dshfmt is my binary.

Seems it needs -w to be supported and then sub call into one of my current args that are above maybe ?

@zimbatm
Copy link
Member

zimbatm commented Oct 5, 2024

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

@gedw99
Copy link
Author

gedw99 commented Oct 8, 2024

Thanks !!

dshfmt Is golang binary with stdio support .

it only supports a single file at a time being passed in as the arg with no flag .

If you happen to know I am golang example I am look at that .

prefer not to have to use a bank wrapper as then it will not work on all OS ..

1 similar comment
@gedw99
Copy link
Author

gedw99 commented Oct 8, 2024

Thanks !!

dshfmt Is golang binary with stdio support .

it only supports a single file at a time being passed in as the arg with no flag .

If you happen to know I am golang example I am look at that .

prefer not to have to use a bank wrapper as then it will not work on all OS ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants