![]() The func main() just calls the cmd.Execute() function in the cmd/root.go file. When creating a CLI using cobra, the main.go file simply imports the cmd package. Not much to it, right? That’s on purpose. I used the exact same steps I listed above when creating this project and I will be sharing the contents of the files below showing the important parts of the CLI. In your project, you should have a set of files and a directory that look something like this:įrom this point I’m going to start sharing code from the repo I already created. It’s super simple and all you need to do is run this command: The next step is to use the cobra command-line tool to build the scaffolding of your new CLI tool. Go mod init /YOURGITHUBNAME/YOURMODULENAME - again, replace YOURMODULENAME with the name of the Github repo you created. Next, initialize your project as a go module You can push up your initial commit if you’d like at this point but it’s not required. Creating a Github repo is outside of the scope of this project, but head over to and create your project (likely with the same name as the folder you created above). Now it’s time to create your Github repo to match this project. You can really put this anywhere.Īt this point, you should have an empty directory with git initialized. Create a new directory for your CLI tool’s git repo. BTW, go-cobra is written in Go and we will be writing this CLI in Go, so install that too if you don’t have it. ![]() To get started creating a new CLI tool with go-cobra, you should first install the cobra tool. According to the go-cobra Github page “Cobra is both a library for creating powerful modern CLI applications as well as a program to generate applications and command files”. This tool is written in the Go programming language and is using the go-cobra package. I have written a tool called mediumautopost that is designed to post articles to. Obviously, you will be creating your own tool so the details of mine don’t really matter. The important part that we need here is just the basics of creating a CLI tool and the file layout. I am not going to go really in-depth into the functionality of the tool I created and will instead cover that in another post later on. Since the primary purpose of this article is to show how to distribute a CLI tool with Homebrew, we obviously need to have a CLI tool to distribute! To accomplish this, I will be using a CLI tool that I have already written. Navigating the Apple Ecosystem: A Developer's Journey from Passion to App Store How to Download Files from Github: 4 Easy Methods Step-by-Step: Adding Shared Storage to a Kubernetes Cluster How To Turn Your Old Hardware Into A Kubernetes Cluster Is Gaining Open Source Contributors Really This Easy? Is That Open Source Project Safe To Use? - Here’s How To Know I Made a Local Kubernetes Startup Script So You Don't Have To How to Write a Netlify Post-Deploy Function in Golang Introducing Medium-auto-post | Syndicate your Hugo Content to Secret Developer Career Weapon: Learning to LearnĪuto Generate a REST API Payload to Syndicate Posts with HugoĬreate a Custom CLI Tool and Distribute with HomeBrew Using Goreleaser and Github Actions Underrated: Working for a “Normal” Company Taking Developer Efficiency to the Extreme Two AIs better than One? DALL E + ChatGPT = □ĭoes Low-code / No-Code Really save time and money? Your README is a Dumpster Fire - It's Time to Fix That What even is "the edge"? Fog Compute / Edge Compute ExplainedĭevOps is NOT a Job Title | Why development teams practice DevOps What Is a CDN and How Do They Work? - Content Delivery Networks Explained The (Real) Meaning of "Keep The Lights On" The Unintended Consequences of Cali’s CCPA/CPRAĮvent-driven Architecture - Everything You Need to Know This One Simple Change Can Alter the Velocity of your Tech Career The “10X Developer” Is a Myth - Here’s Why How To Shortcut the Programming Language Learning Curve How to Communicate Effectively as a Web Developer: The Importance of Strong Communication SkillsĦ Little Things That Can Make You Seem Like Less of a Jerk When Reviewing Someone’s CodeĬontributing to Open Source Can Change Your Life - Here’s How to Do ItĪlways Do These Eight Things Before Pushing a Commit Why Multitasking is Impossible and How To Become Really Good at Faking It What's in My Home Office After 10 Years? | These 10 Products Made the Cut
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |