cobra-cli icon indicating copy to clipboard operation
cobra-cli copied to clipboard

[RFC] improve generated boilerplate

Open johnSchnake opened this issue 2 years ago • 8 comments

https://github.com/spf13/cobra/issues/1614#issue-1153386641

Multiple issues in the spf13/cobra repo were regarding the patterns of globals/init methods which made testing and growth difficult.

This linked issue properly points to the method (I think) most people eventually figure out for themselves.

Moved to this repo due to the CLI being split off.

johnSchnake avatar Mar 01 '22 14:03 johnSchnake

https://github.com/spf13/cobra/issues/1290 was also an issue pointing out that data races were detected in that default app. This will be something we need to check when we re-write the sample.

johnSchnake avatar Mar 01 '22 16:03 johnSchnake

#14 is a step forward.

  • I usually do call rootCmd.AddCommand(NewSubCommand()) inside of the constructor NewRootCmd() which would be quite hard to do with generated code. cobra-cli would need to actually parse generated Go code and append lines at specific locations for that to work with sub commands that are added afterwards.

jxsl13 avatar Mar 01 '22 21:03 jxsl13

This issue is being marked as stale due to a long period of inactivity

github-actions[bot] avatar May 01 '22 00:05 github-actions[bot]

This issue is being marked as stale due to a long period of inactivity

github-actions[bot] avatar Sep 27 '22 00:09 github-actions[bot]

I've found this issue and RFC because I was going to open an issue/question about the init() func, and if it was possible to change the docs and user guide, and probably the generator (I've not used it, but I guess that it's going to generate the everything "globally".

I've found a really nice article on how to structure a Cobra application, and this is what I am using as a guidance at the moment: https://carolynvanslyck.com/blog/2020/08/sting-of-the-viper/

  • https://github.com/carolynvs/stingoftheviper
  • https://github.com/enrichman/stegosecrets/blob/main/internal/cli/root.go

Is this RFC going to be implemented? Or what's the state of it? :slightly_smiling_face:

enrichman avatar Nov 21 '22 15:11 enrichman

This issue is being marked as stale due to a long period of inactivity

github-actions[bot] avatar Jan 21 '23 00:01 github-actions[bot]

This issue is being marked as stale due to a long period of inactivity

github-actions[bot] avatar Mar 24 '23 00:03 github-actions[bot]

This issue is being marked as stale due to a long period of inactivity

github-actions[bot] avatar May 24 '23 00:05 github-actions[bot]