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

cmd: Add --diff option for caddy fmt #4695

Merged
merged 1 commit into from Apr 12, 2022
Merged

cmd: Add --diff option for caddy fmt #4695

merged 1 commit into from Apr 12, 2022

Conversation

francislavoie
Copy link
Member

@francislavoie francislavoie commented Apr 10, 2022

Just thought this might be fun to have.

When using no options or using --overwrite, it can be difficult to find out what was actually "wrong" according to the formatter.

Example output where a couple of the lines had spaces instead of tabs:

  :80 {
  	root * /srv
  	file_server
  
  	handle_errors {
-       @404 {
-           expression {http.error.status_code} == 404
+ 		@404 {
+ 			expression {http.error.status_code} == 404
  		}
  		rewrite @404 /not-found.txt
  	}
  }

@francislavoie francislavoie added the feature ⚙️ New feature or request label Apr 10, 2022
@francislavoie francislavoie added this to the 2.x milestone Apr 10, 2022
@AliAlhajji
Copy link

I'm curious what would be the output if there isn't a new line at the end of the file

@francislavoie
Copy link
Member Author

It'll show it:

  	}
  }
+

@mholt
Copy link
Member

mholt commented Apr 11, 2022

This is cool. I do wonder if it'd be useful to output an actual patch format so that diffing tools can visualize it for the user.

@francislavoie
Copy link
Member Author

francislavoie commented Apr 11, 2022

There's https://github.com/google/go-patchutils that we could use to do that, but it pulls in additional deps, not sure we need the complexity. I don't think we really gain that much from a full-on patch here. If you want a real patch, make it yourself with your machine's diff or w/e, not that difficult. Basically caddy fmt Caddyfile | diff -u Caddyfile - or whatever.

@mholt
Copy link
Member

mholt commented Apr 11, 2022

I see...

Do we really need this at all then? If the pipe to diff can be done anyway nearly just as easily?

@francislavoie
Copy link
Member Author

Piping on Windows is uh, not nice 😁

I wrote this because I was on Windows and wanted a way to compare quickly in environments where I can't easily add random tooling. Some Windows users who see the warning in their logs might appreciate having this too for example. Or people in Docker who don't feel like getting a Caddy binary outside Docker just to compare their fmt.

@AliAlhajji
Copy link

Piping on Windows is uh, not nice 😁

I wrote this because I was on Windows and wanted a way to compare quickly in environments where I can't easily add random tooling. Some Windows users who see the warning in their logs might appreciate having this too for example. Or people in Docker who don't feel like getting a Caddy binary outside Docker just to compare their fmt.

As a Windows user I can relate to your Windows experience. Actually it was the new line at the end that kept causing the warning.

@mholt mholt modified the milestones: 2.x, v2.5.0 Apr 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants