log.go

34 lines
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
//go:build cgo

package commands

import (
	"flag"
	"fmt"
	"os"
	"strings"

	"congo.gg/dev/models"
)

func Log() {
	f := flag.NewFlagSet("log", flag.ExitOnError)
	logType := f.String("type", "work", "Log type (work, system, alert, heartbeat)")
	author := f.String("author", "twin", "Author")
	detail := f.String("detail", "", "Detailed text")
	f.Parse(os.Args[2:])

	summary := strings.Join(f.Args(), " ")
	if summary == "" {
		fmt.Fprintln(os.Stderr, "usage: congo log <summary> [--type work] [--author twin]")
		os.Exit(1)
	}

	models.LogEntries.Insert(&models.LogEntry{
		Type:    *logType,
		Summary: summary,
		Detail:  *detail,
		Author:  *author,
	})
	fmt.Println("logged")
}