coder / serpent

CLI framework for scale and configurability inspired by Cobra
Creative Commons Zero v1.0 Universal
6 stars 1 forks source link

Remove (Cmd).Middleware #5

Open ammario opened 3 months ago

ammario commented 3 months ago

It serves no clear purpose beyond what could be accomplishing by just passing serpent.Chain to the Handler.

mafredri commented 2 months ago

I had a use-case the other day, where I didn't know how to do this.

Essentially, I wanted pre-processing for all commands done on the root command, so that you can expect the correct state.

I would've put this middleware on the root command, but it has no effect: https://github.com/coder/coder/blob/f1ef9fd6737a314c4c55d4870631c8383e80bd49/scripts/release/main.go#L81. I also wouldn't want to wrap each handler that needs this pre-processing.

(PS. I think there's also a bug where you can't easily make serpent output help text if you put a Handler on the command. I ran into a nil pointer panic.)