Skip to content

Go Flags

maxlandon edited this page Jan 2, 2023 · 2 revisions

This page is intended for users of jessevdk/go-flags.

Introduction

I originally worked on enhancing this library, but I got to find octago/sflags, which would take a smarter approach at generating flags which were compliant with other battle-tested libraries, such as pflag (the flag library used by cobra).

From there, I got to realize that generating structs directly into cobra commands would exponentially enhance the principles that have been put forward by go-flags, which has had a lot of success. As said in the introduction, resting on cobra command gives many benefits that go-flags could not provide, and it spares everyone the need to maintain two different command/flag/parsing APIs and logic.

It should thus be stressed that one of the main aims of the present library is to allow go-flags users to move to a similar library, but with more modern features out of the box, and while leveraging other libs that have proven their worth, as well as being actively maintained.

I hope that this library will be a success as far as this is concerned.

Differences

However, and despite most of the tags used by go-flags being valid in the present library, the following is a gross (hopefully complete) list of the differences between this library and go-flags:

  • All Command, Option, Parser types from go-flags are not present here.
  • All global parsing options in go-flags have also disappeared. However, it should be noted that cobra has shown that some of those options could be implicitly used without having to specify them.
  • The Completion type has not been ported, and so as to avoid importing go-flags, any go-flags Completer interface satisfier will not be scanned and translated into a flags.Completer.
Clone this wiki locally