Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unused imports in generated code with -only #11

Open
mdegat01 opened this issue Feb 18, 2022 · 0 comments
Open

Unused imports in generated code with -only #11

mdegat01 opened this issue Feb 18, 2022 · 0 comments

Comments

@mdegat01
Copy link

mdegat01 commented Feb 18, 2022

When using the -only option to limit the generated file to just the needed interface the generator still adds imports of "fmt" and "errors" at the top. Those imports are only used in the Signal section of the generated code shown below and that section isn't included in the generated file when -only is used. These imports have to be manually removed after generation right now in order for the file to compile.

Signal section

// Signal is a common interface for all signals.
type Signal interface {
	Name() string
	Interface() string
	Sender() string

	path() dbus.ObjectPath
	values() []interface{}
}

// ErrUnknownSignal is returned by LookupSignal when a signal cannot be resolved.
var ErrUnknownSignal = errors.New("unknown signal")

// LookupSignal converts the given raw D-Bus signal with variable body
// into one with typed structured body or returns ErrUnknownSignal error.
func LookupSignal(signal *dbus.Signal) (Signal, error) {
	switch signal.Name {
	case InterfaceOrgFreedesktopDBusProperties + "." + "PropertiesChanged":
		v0, ok := signal.Body[0].(string)
		if !ok {
			return nil, fmt.Errorf("prop .Interface is %T, not string", signal.Body[0])
		}
		v1, ok := signal.Body[1].(map[string]dbus.Variant)
		if !ok {
			return nil, fmt.Errorf("prop .ChangedProperties is %T, not map[string]dbus.Variant", signal.Body[1])
		}
		v2, ok := signal.Body[2].([]string)
		if !ok {
			return nil, fmt.Errorf("prop .InvalidatedProperties is %T, not []string", signal.Body[2])
		}
		return &OrgFreedesktopDBusPropertiesPropertiesChangedSignal{
			sender: signal.Sender,
			Path:   signal.Path,
			Body: &OrgFreedesktopDBusPropertiesPropertiesChangedSignalBody{
				Interface:             v0,
				ChangedProperties:     v1,
				InvalidatedProperties: v2,
			},
		}, nil
	default:
		return nil, ErrUnknownSignal
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant