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

Commit

Permalink
set version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
hay-kot committed Nov 17, 2023
1 parent 8cc0f30 commit 0ddf359
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
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

0 comments on commit 0ddf359

Please sign in to comment.