enumgen

package module
v0.0.0-...-e016e08 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2022 License: MIT Imports: 14 Imported by: 0

README

Simple Enumish Generator For Go

Add string or int enums to your project:

package mystuff

type MyString string

const (
    Foo MyString = "foo"
    Bar MyString = "bar"
)

type MyInt int

const (
    Inty MyInt = 1
    Squinty MyInt = 2
)

Add tools.go to your project as per #25922, unless that guidance has changed recently, which is entirely possible. This has nothing to do with enums or this project, it's just how you tell go modules about this tool:

//+build tools

package tools

import _ "go.shabbyrobe.org/enumgen/cmd/enumgen"

Add you some go generate into the same package as your enums (not in tools.go, which is just a bit of "go modules administrativa"):

//go:generate enumgen MyString MyInt

Run you some go generate inside the package with your enums:

$ go generate

And now you can do fun stuff:

var x = Foo
fmt.Println(x.Name()) // "Foo"

var nup MyString = MyString("INVALID")
fmt.Println(nup.IsValid()) // "false"

var fs = flag.NewFlagSet()
var v Foo
fs.Var(&v, "mystring", "Set one of these generated things from a flag")

Documentation

Index

Constants

View Source
const Usage = `` /* 1459-byte string literal not displayed */

Variables

This section is empty.

Functions

func IsUsageError

func IsUsageError(err error) bool

Types

type Command

type Command struct {
	// contains filtered or unexported fields
}

func (*Command) Flags

func (cmd *Command) Flags(flags *flag.FlagSet)

func (*Command) Run

func (cmd *Command) Run(args ...string) error

func (*Command) Synopsis

func (cmd *Command) Synopsis() string

func (*Command) Usage

func (cmd *Command) Usage() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL