Skip to content

Commit

Permalink
Use pkg/cmd not cmd for Cobra commands
Browse files Browse the repository at this point in the history
  • Loading branch information
rwxrob committed Sep 17, 2024
1 parent a35f02e commit 1f8ac74
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
5 changes: 5 additions & 0 deletions docs/2709/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Use `pkg/cmd` not `cmd` for Cobra commands

Everyone---except Cobra---agrees that the `cmd` directory is to contain subdirectories that have `main` packages, you know, *commands* in them. That's the whole fucking point of `cmd`. Cobra decides to ignore this best practice and do whatever the fuck even though it never had to do that. In the process is also forces the creation of unnecessary stuttering (ex: `cmd.AddCmd`) and creating a bunch of completely importable subcommand trees that cannot be combined into other monoliths with an easy import just because it was not initially designed that way.

Well, there's no fucking requirement to do it that way. In fact, one of the best command line tools ever created, the GitHub `gh` tool, decided to ignore Cobra's shitty initializer command and put everything in `pkg/cmd` instead. Thank God a big project has the courage to tell `cobra-cli` to go fuck itself and do the right thing. Unfortunately, that rebellious attitude let the GitHub team to go one step too far and create their own command `Factory` functions for dynamically generating commands in ways they they specifically want. That's fine, but why. Why not use `pkg/cmd` as Go gods intended for things like `pkg/cmd/kt/cmd.go` or `pkg/cmd/kt.go`. Using this method the directory structure can mirror that of the sub-trees as well.
25 changes: 13 additions & 12 deletions docs/dex/changes.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
* 2024-09-17 13:48:38Z [Use `pkg/cmd` not `cmd` for Cobra commands](../2709)
* 2024-09-17 13:21:37Z [Option to install Cobra commands as command trees instead](../2708)
* 2024-09-17 08:28:31Z [Bonzai and Cobra in same repo?](../2707)
* 2024-09-17 08:18:40Z [Always separate business logic from tools that use it](../2706)
Expand Down Expand Up @@ -123,19 +124,19 @@
* 2024-06-27 07:32:25Z [Food](../2574)
* 2024-06-27 05:49:40Z [Light beer for active people](../2573)
* 2024-06-27 05:38:24Z [I think I'm dropping my coffee habit (on the road)](../2572)
* 2024-06-26 11:47:00Z [Is living out of car (Subaru Outback) sustainable?](../2390)
* 2024-06-26 11:47:00Z [Install RedHat Ansible Configuration Manager](../2571)
* 2024-06-26 11:47:00Z [Is living out of car (Subaru Outback) sustainable?](../2390)
* 2024-06-14 03:07:02Z [Don't Depend on `jq`, Learn Builtin Alternatives](../7)
* 2024-06-14 03:07:02Z [Streaming Content Categories](../193)
* 2024-06-14 03:07:02Z [Hotel and tent KOA costs aren't really that bad for a digital nomad](../2391)
* 2024-06-14 03:07:02Z [Syncing Cobra Version with GitHub tagged version](../2551)
* 2024-06-14 03:07:02Z [Planning IRL Streaming and Digital Nomad Life](../19)
* 2024-06-14 03:07:02Z ["I didn't know what you guys wanted me to do?"](../23)
* 2024-06-14 03:07:02Z [Don't Depend on `jq`, Learn Builtin Alternatives](../7)
* 2024-06-14 03:07:01Z [Things to Learn in 2022 to Get Best Tech Jobs](../1409)
* 2024-06-14 03:07:02Z [Planning IRL Streaming and Digital Nomad Life](../19)
* 2024-06-14 03:07:01Z [Most Important Tech Areas to Learn](../1528)
* 2024-06-14 03:07:01Z [Installing Harbor Into VM](../1286)
* 2024-06-14 03:07:01Z [Use nmcli to Manage Network on Modern Linux](../1456)
* 2024-06-14 03:07:01Z [Weekly Streaming Schedule](../1118)
* 2024-06-14 03:07:01Z [Things to Learn in 2022 to Get Best Tech Jobs](../1409)
* 2024-05-25 19:30:19Z [📞 What is PEGN and why use it?](../1847)
* 2024-05-24 12:15:26Z [Must I really eat other animals?](../2569)
* 2024-05-24 11:42:08Z [Yoga, journaling, and meditation](../2568)
Expand All @@ -157,8 +158,7 @@
* 2024-04-29 16:06:14Z [Just discovered Wails, alternative to Electron](../2554)
* 2024-04-28 15:45:42Z [Go Major Version Path Syncing](../839)
* 2024-04-18 15:55:37Z [GHES vs GHEC](../2550)
* 2024-04-18 15:21:26Z [Kubernetes Demands Skills of a Full IT Department](../734)
* 2024-04-18 15:21:26Z [Another Reason to Use Plain Vim Line Numbers](../897)
* 2024-04-18 15:21:26Z [🖼️ Kernels: Mono, Micro, Hybred](../735)
* 2024-04-18 15:21:26Z [Use iotop to Check IO Bottlenecks](../898)
* 2024-04-18 15:21:26Z [Boost Will Focus on VirtualBox Ubuntu Server](../899)
* 2024-04-18 15:21:26Z [GitHub API versus CLI `gh` Tool?](../9)
Expand Down Expand Up @@ -323,8 +323,8 @@
* 2024-04-18 15:21:26Z [Bonzai AI for CLI, Remove Diseased GetOpt Brain](../863)
* 2024-04-18 15:21:26Z [Avoid K9S for Kubernetes (for now)](../881)
* 2024-04-18 15:21:26Z [Boost Badges: Level Five, Mastery](../893)
* 2024-04-18 15:21:26Z [Cloud-Native and Kubernetes Colearning, Oct 16, 2021](../896)
* 2024-04-18 15:21:26Z [🖼️ Kernels: Mono, Micro, Hybred](../735)
* 2024-04-18 15:21:26Z [Kubernetes Demands Skills of a Full IT Department](../734)
* 2024-04-18 15:21:26Z [Another Reason to Use Plain Vim Line Numbers](../897)
* 2024-04-18 15:21:26Z [Why not Windows 11?](../736)
* 2024-04-18 15:21:26Z [Usage, Synopsis, Help, or What?](../737)
* 2024-04-18 15:21:26Z [The Pareto Rule](../738)
Expand Down Expand Up @@ -1954,7 +1954,7 @@
* 2024-04-18 15:21:26Z [Practical Learning About Virtualization](../1483)
* 2024-04-18 15:21:26Z [Use `jq -s ` to Combine Multiple JSON Objects](../1186)
* 2024-04-18 15:21:26Z [Use diskbench to Measure IOPS](../1185)
* 2024-04-18 15:21:26Z [Getting Raped for "Free" Knowledge, But It's Fine](../1480)
* 2024-04-18 15:21:26Z [Replace `api.github.com` with `[host]/api/v3`](../1184)
* 2024-04-18 15:21:26Z [Don't Get Mad, Get Busy ...](../148)
* 2024-04-18 15:21:26Z [Just Use Docker Desktop](../1479)
* 2024-04-18 15:21:26Z [Cloud-Native and Kubernetes Colearning, Oct 17, 2021](../1478)
Expand Down Expand Up @@ -2279,7 +2279,7 @@
* 2024-04-18 15:21:26Z [Best Tutorials for Golang Gin](../890)
* 2024-04-18 15:21:26Z [Personal Bonzai Utility Monolith (z)](../891)
* 2024-04-18 15:21:26Z [GitHub Zettelkasten Live Commit Notifications](../894)
* 2024-04-18 15:21:26Z [Microsoft's Ultrafast Supercomputer Runs Linux](../895)
* 2024-04-18 15:21:26Z [Cloud-Native and Kubernetes Colearning, Oct 16, 2021](../896)
* 2024-04-18 15:21:26Z [Limit to 72 max cols/width in vim/whatever (if you are going limit)](../1183)
* 2024-04-18 15:21:26Z [Stop Putting Comments in JSON](../1182)
* 2024-04-18 15:21:26Z [Bash is Like JavaScript, But for Adults](../1181)
Expand Down Expand Up @@ -2601,7 +2601,8 @@
* 2024-04-18 15:21:26Z [Stop Using Single Brackets in bash!](../1187)
* 2024-04-18 15:21:26Z [Personal Go "Awesome" List](../1482)
* 2024-04-18 15:21:26Z [Sample With Tags](../1481)
* 2024-04-18 15:21:26Z [Replace `api.github.com` with `[host]/api/v3`](../1184)
* 2024-04-18 15:21:26Z [Getting Raped for "Free" Knowledge, But It's Fine](../1480)
* 2024-04-18 15:21:26Z [Microsoft's Ultrafast Supercomputer Runs Linux](../895)
* 2024-04-18 11:21:26Z [Fix "cannot evict pod as it would violate pod disruption budget"](../2287)
* 2024-04-18 11:21:26Z [Proposed "telemetry" in Go will force a fork if approved](../2024)
* 2024-04-18 11:21:26Z [Rediscovering Solarized Dark theme](../2497)
* 2024-04-18 11:21:26Z [Fix "cannot evict pod as it would violate pod disruption budget"](../2287)
1 change: 1 addition & 0 deletions docs/dex/nodes.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -2605,3 +2605,4 @@
2706 2024-09-17 08:18:40Z Always separate business logic from tools that use it
2707 2024-09-17 08:28:31Z Bonzai and Cobra in same repo?
2708 2024-09-17 13:21:37Z Option to install Cobra commands as command trees instead
2709 2024-09-17 13:48:38Z Use `pkg/cmd` not `cmd` for Cobra commands
4 changes: 2 additions & 2 deletions docs/keg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<<<<<<< Updated upstream
updated: 2024-09-17 13:21:37Z
updated: 2024-09-17 13:48:38Z
=======
updated: 2024-09-17 13:21:37Z
updated: 2024-09-17 13:48:38Z
>>>>>>> Stashed changes
kegv: 2023-01

Expand Down

0 comments on commit 1f8ac74

Please sign in to comment.