Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basically the same as spf13/cobra#1517 but uses the `Set<field>` naming convention instead of `WithContext` Context setting without execution is important because it means that more design patterns can be achieved. Currently I am using functional options in a project and I can add behaviour through functional options as such: ```go type GrptlOption func(*cobra.Command) error func WithFileDescriptors(descriptors ...protoreflect.FileDescriptor) GrptlOption { return func(cmd *cobra.Command) error { err := CommandFromFileDescriptors(cmd, descriptors...) if err != nil { return err } return nil } } ``` I've got a lot more options and this pattern allows me to have nice abstracted pieces of logic that interact with the cobra command. This Pattern also allows for adding extra information to a call through `PreRun` functions: ```go cmd := &cobra.Command{ Use: "Foobar", PersistentPreRun: func(cmd *cobra.Command, args []string) { err :=cmd.SetContext(metadata.AppendToOutgoingContext(context.Background(), "pre", "run")) }, } ``` This is a veer nice abstraction and allows for these functions to be very modular The issue I'm facing at the moment is that I can't write a nifty option (something like `WithAuthentication`) because that needs access to reading and setting the context. Currently I can only read the context. Needing to use `ExecuteContext` breaks this abstraction because I need to run it right at the end. Merge spf13/cobra#1551 Fixes spf13/cobra#1517 Fixes spf13/cobra#1118 Fixes spf13/cobra#563
- Loading branch information