Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

feat: set version flag #632

Merged
merged 1 commit into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion backend/app/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ var (
buildTime = "now"
)

func build() string {
short := commit
if len(short) > 7 {
short = short[:7]
}

return fmt.Sprintf("%s, commit %s, built at %s", version, short, buildTime)
}

// @title Homebox API
// @version 1.0
// @description Track, Manage, and Organize your Things.
Expand All @@ -47,7 +56,7 @@ var (
func main() {
zerolog.ErrorStackMarshaler = pkgerrors.MarshalStack

cfg, err := config.New()
cfg, err := config.New(build(), "Homebox inventory management system")
if err != nil {
panic(err)
}
Expand Down
8 changes: 7 additions & 1 deletion backend/internal/sys/config/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const (
)

type Config struct {
conf.Version
Mode string `yaml:"mode" conf:"default:development"` // development or production
Web WebConfig `yaml:"web"`
Storage Storage `yaml:"storage"`
Expand Down Expand Up @@ -46,10 +47,15 @@ type WebConfig struct {

// New parses the CLI/Config file and returns a Config struct. If the file argument is an empty string, the
// file is not read. If the file is not empty, the file is read and the Config struct is returned.
func New() (*Config, error) {
func New(buildstr string, description string) (*Config, error) {
var cfg Config
const prefix = "HBOX"

cfg.Version = conf.Version{
Build: buildstr,
Desc: description,
}

help, err := conf.Parse(prefix, &cfg)
if err != nil {
if errors.Is(err, conf.ErrHelpWanted) {
Expand Down
Loading