BigJk / snd

Sales & Dungeons — Thermal Printer as D&D / TTRPG Utility
https://sales-and-dungeons.app/
MIT License
474 stars 17 forks source link

Unify cmd packages? #10

Closed BigJk closed 4 years ago

BigJk commented 4 years ago

Currently there is

After adding libusb I think it's a good time to rethink this approach. Maybe you are using MacOSX and still want to have a electron window and libusb. Currently that is not covered by these 3 packages.

In Go it's possible to activate and deactivate features based on OS or tags that can be specified while building. I think this would be a better solution than separate packages and would allow users to mix and match what they need.

My Idea

Optional Tags

Example

headless without libusb or electron window

cd /somewhere/.../snd/cmd
go build

libusb

cd /somewhere/.../snd/cmd
go build -tags="LIBUSB"

libusb + electron

cd /somewhere/.../snd/cmd
go build -tags="LIBUSB ELECTRON"

This also would help to keep it more DRY because the 3 packages currently all contain the same main() function with just minor changes.

I pushed it to a seperate branch so feel free to take a look at it cmd-unify/cmd. If there are no objections I will merge it into master.


Just a little info for anybody that is not familiar with go. The init() function of a file will be executed before the main function. This can be combined with the build tags / constraints to enable or remove stuff depending on the tags or OS.

init(): https://golang.org/doc/effective_go.html#init build constraints: https://golang.org/pkg/go/build/

BigJk commented 4 years ago

Merged 91b892f45d6cf4b7420fa0b8bffc1ef843ae120a