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

cli: Force d2 fmt operate when the input file is stdin #2139

Closed
wants to merge 1 commit into from

Conversation

akirak
Copy link

@akirak akirak commented Oct 5, 2024

This PR fixes #1577.

The change is obvious. Previously, d2 fmt CLI command was no-op when the content is unchanged. However, this check should be skipped if the input file is stdin–because editor integrations would use it for on-the-fly reformatting.

Copy link
Collaborator

@alixander alixander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR but I don't think stdin should be treated any differently.

#1577 (comment)

Following what gofmt would do, d2 fmt ... should output to stdout and d2 fmt -w ... should overwrite the files.

@akirak
Copy link
Author

akirak commented Oct 5, 2024

I don't think stdin should be treated any differently.

We should just conform to what https://pkg.go.dev/cmd/gofmt does.

Is this implemented even now? From the document on gofmt, you see the following description:

Without an explicit path, it processes the standard input.

but d2 fmt requires at least one file argument, as seen in the below example:

01:40 $ d2 fmt < sample.d2
err: failed to fmt: bad usage: fmt must be passed at least one file to be formatted
err: Run with --help to see usage.

The definition of conformance looks vague here.

@akirak
Copy link
Author

akirak commented Oct 5, 2024

Okay, I think d2 fmt should first support zero arguments. Closing this PR anyway.

@akirak akirak closed this Oct 5, 2024
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

Successfully merging this pull request may close these issues.

fmt from stdout should always output the formatted diagram
2 participants