mkenum

command
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 21, 2024 License: MIT Imports: 13 Imported by: 0

README

mkenum generates enum method for comparable constants

$ mkenum -h
Usage: mkenum [OPTIONS] [FILE]

Options
    -t, --types : ""
        CSV list of types

    -w, --write-file : ""
    -a, --append-file : ""
    -h, --help

Example

Having

package main

//go:generate mkenum -t Weekday .
type Weekday string

const (
        Monday    Weekday = "Monday"
        Tuesday   Weekday = "Tuesday"
        Wednesday Weekday = "Wednesday"
        Thursday  Weekday = "Thursday"
        Friday    Weekday = "Friday"
        Saturday  Weekday = "Saturday"
        Sunday    Weekday = "Sunday"
)

will result in

// GENERATED, DO NOT EDIT!

package main

func (Weekday) Enum() []any {
        return []any{
                Monday,
                Tuesday,
                Wednesday,
                Thursday,
                Friday,
                Saturday,
                Sunday,
        }
}

Documentation

Overview

Generates get methods for private struct fields

Jump to

Keyboard shortcuts

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