Cobra

Using tabwriter to improve on cobra’s help information

2020-02-27

If you’ve been following the blog, you know that I’m a fan of cobra as a CLI library. Let me share how I use tabwriter to compliment cobra’s autogenerated help information. For reference, you can check this post as well. The following code is a copy (not an exact copy) of one of the tools that I use at work. It will look something like this. Trigger a manual run, among other tools.

Cobra · Golang · Tabwriter

1 minute

Using k8s.io/klog together with cobra in golang

2019-02-05

This post is somehow related to a previous article about using glog together with cobra. This time, we will be using klog which is a Kubernetes fork of glog. run the -h command $ ./cobraklog -h Usage of ./cobraklog: -alsologtostderr log to standard error as well as files -log_backtrace_at value when logging hits line file:N, emit a stack trace -log_dir string If non-empty, write log files in this directory -log_file string If non-empty, use this log file -logtostderr log to standard error instead of files -skip_headers If true, avoid header prefixes in the log messages -stderrthreshold value logs at or above this threshold go to stderr (default 2) -v value log level for V logs -vmodule value comma-separated list of pattern=N settings for file-filtered logging # run cobra's help command $ .

Cobra · Golang · Klog

2 minutes

Using glog together with cobra in golang

2017-12-01

If you have been programming with golang, you’ve probably heard of cobra. I use it extensively at work and also in my personal projects. Recently though, I’ve been using glog more and more. And I quite like it. The thing is, it has a couple of flag definitions in its init() function using golang’s builtin flag library. And I wanted to include those flags into cobra’s flag definitions. This is how I did it.

Cobra · Glog · Golang

2 minutes