go-enum icon indicating copy to clipboard operation
go-enum copied to clipboard

Custom prefix with `--prefix` is appending not replacing

Open dmipeck opened this issue 2 years ago • 3 comments

I'm using go-enum v0.5.0 Linux x86_64 I've created an enum as such:

//go:generate go-enum -f=$GOFILE --marshal --names --nocamel --prefix TokenTypeEnum_
package tokens
/*
ENUM(
	AD_HOC_USER = 1
	APP_USER
	OTHER
	RFID
)
*/
type TokenTypeEnum uint8

By default, the --nocamel flag gives me TokenTypeEnum<name> but I want the constants to be named TokenTypeEnum_<name> for readability but instead I'm getting TokenTypeEnum_TokenTypeEnum<name>

The README suggests the --prefix flag should be replacing the existing prefix but it's not. --noprefix removes both prefixes

dmipeck avatar Sep 17 '22 05:09 dmipeck

Dang, you are absolutely correct. And now since it's out there, I can't just fix that as some people might be using it as shown in the example file. So I can either make the two options work together in tandem to do what you want, or introduce yet another flag. I'm going to work on the dual option first and see where that gets me. If that does work, then I'll update the readme/docs to show the way to get what you're looking for.

Sorry about that!

abice avatar Sep 24 '22 15:09 abice

Actually, I just ran it locally and was able to get what you wanted without code changes. Is this not what you expected when combining the two options?

Perhaps send the version of go-enum that you're using?

//go:generate ../bin/go-enum -f=$GOFILE --marshal --prefix=AcmeInc_ --noprefix --nocamel --names

package example

// Products of AcmeInc ENUM(
// SOME_PLACE_AWESOME,
// SomewhereElse,
// LocationUnknown
// )
type Shop string

// Code generated by go-enum DO NOT EDIT.
// Version: example
// Revision: example
// Build Date: example
// Built By: example

package example

import (
	"fmt"
	"strings"
)

const (
	// AcmeInc_SOME_PLACE_AWESOME is a Shop of type SOME_PLACE_AWESOME.
	AcmeInc_SOME_PLACE_AWESOME Shop = "SOME_PLACE_AWESOME"
	// AcmeInc_SomewhereElse is a Shop of type SomewhereElse.
	AcmeInc_SomewhereElse Shop = "SomewhereElse"
	// AcmeInc_LocationUnknown is a Shop of type LocationUnknown.
	AcmeInc_LocationUnknown Shop = "LocationUnknown"
)

abice avatar Sep 24 '22 15:09 abice

@dmipeck I'm going to merge in a fix for this, but won't mark this as closed until you say that it works for you. Please check the PR #134 to ensure that my example files don't work the same for you. If you are at version 0.5.0 (the current one before my next release) then you should see the correct behavior when using both flags.

abice avatar Sep 24 '22 16:09 abice

@abice It's working for me now thanks!

dmipeck avatar Sep 27 '22 23:09 dmipeck

@abice It's working for me now thanks!

Well, I didn't actually change anything, but glad it's working! I'll go ahead and close this ticket.

abice avatar Sep 27 '22 23:09 abice

Yeah, I must have done something strange while testing it the first time, but the doc changes and clarity are appreciated

dmipeck avatar Sep 27 '22 23:09 dmipeck