mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Be more rigid specifying format in config file.
This commit is contained in:
parent
1bdaf5854a
commit
655b8f4db1
2 changed files with 25 additions and 10 deletions
|
|
@ -11,6 +11,7 @@ package main
|
|||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/csaf-poc/csaf_distribution/v2/internal/options"
|
||||
|
|
@ -18,10 +19,12 @@ import (
|
|||
|
||||
const defaultPreset = "mandatory"
|
||||
|
||||
type outputFormat string
|
||||
|
||||
type config struct {
|
||||
Output string `short:"o" long:"output" description:"File name of the generated report" value-name:"REPORT-FILE" toml:"output"`
|
||||
//lint:ignore SA5008 We are using choice twice: json, html.
|
||||
Format string `short:"f" long:"format" choice:"json" choice:"html" description:"Format of report" default:"json" toml:"format"`
|
||||
Format outputFormat `short:"f" long:"format" choice:"json" choice:"html" description:"Format of report" default:"json" toml:"format"`
|
||||
Insecure bool `long:"insecure" description:"Do not check TLS certificates from provider" toml:"insecure"`
|
||||
ClientCert *string `long:"client-cert" description:"TLS client certificate file (PEM encoded data)" value-name:"CERT-FILE" toml:"client_cert"`
|
||||
ClientKey *string `long:"client-key" description:"TLS client private key file (PEM encoded data)" value-name:"KEY-FILE" toml:"client_key"`
|
||||
|
|
@ -47,6 +50,18 @@ var configPaths = []string{
|
|||
"csaf_checker.toml",
|
||||
}
|
||||
|
||||
// UnmarshalText implements [encoding/text.TextUnmarshaler].
|
||||
func (of *outputFormat) UnmarshalText(text []byte) error {
|
||||
s := string(text)
|
||||
switch s {
|
||||
case "html", "json":
|
||||
*of = outputFormat(s)
|
||||
default:
|
||||
return fmt.Errorf(`%q is neither "html" nor "json"`, s)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// parseArgsConfig parse the command arguments and loads configuration
|
||||
// from a configuration file.
|
||||
func parseArgsConfig() ([]string, *config, error) {
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ func (nc *nopCloser) Close() error { return nil }
|
|||
|
||||
// write defines where to write the report according to the "output" flag option.
|
||||
// It calls also the "writeJSON" or "writeHTML" function according to the "format" flag option.
|
||||
func (r *Report) write(format, output string) error {
|
||||
func (r *Report) write(format outputFormat, output string) error {
|
||||
|
||||
var w io.WriteCloser
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue