github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/utils/docgen/main.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"log"
     7  	"os"
     8  
     9  	docgen "github.com/lmorg/murex/utils/docgen/api"
    10  )
    11  
    12  const (
    13  	// Version is the release ID of docgen
    14  	Version = "3.1.0"
    15  
    16  	// Copyright is the copyright owner string
    17  	Copyright = "(c) 2018-2024 Laurence Morgan"
    18  
    19  	// License is the projects software license
    20  	License = "Licence GPL v2"
    21  )
    22  
    23  // flags
    24  var (
    25  	fConfigFile string
    26  )
    27  
    28  func main() {
    29  	readFlags()
    30  
    31  	err := docgen.ReadConfig(fConfigFile)
    32  	if err != nil {
    33  		log.Fatalln("[ERROR]", err)
    34  	}
    35  
    36  	err = docgen.Render()
    37  	if err != nil {
    38  		log.Fatalln("[ERROR]", err)
    39  	}
    40  
    41  	os.Exit(docgen.ExitStatus)
    42  }
    43  
    44  func readFlags() error {
    45  	flag.BoolVar(&docgen.Panic, "panic", false, "Write a stack trace on error")
    46  	flag.BoolVar(&docgen.Verbose, "verbose", false, "Verbose output (all log messages inc warnings)")
    47  	flag.BoolVar(&docgen.Warning, "warning", false, "Display warning messages (recommended)")
    48  	flag.BoolVar(&docgen.ReadOnly, "readonly", false, "Don't write output to disk. Use this to test the config")
    49  
    50  	flag.StringVar(&fConfigFile, "config", "", "Location of the base docgen config file")
    51  	version := flag.Bool("version", false, "Output docgen version number and exit")
    52  
    53  	flag.Parse()
    54  
    55  	if *version {
    56  		fmt.Printf("docgen version %s\n%s, %s", Version, License, Copyright)
    57  		os.Exit(0)
    58  	}
    59  
    60  	if fConfigFile == "" {
    61  		log.Fatalln("missing required flag: -config")
    62  	}
    63  
    64  	return nil
    65  }