func NewConfig() (*Config, error) {
	cfg := Config{}
	cfg.handleFlagsConfig()
	if cfg.ShowVersion {
		return &cfg, ErrVersionRequested
	}
	if err := cfg.Validate(); err != nil {
		flag.Usage()
		return nil, err
	}
	return &cfg, nil
}
NewConfig is a factory function that produces a new Config object based
on user provided flag values.
package config
import (
	"errors"
	"flag"
	"fmt"
	"net/url"
	"os"
	"path/filepath"
	"strconv"
	"strings"
	"time"
	goteamsnotify "github.com/atc0005/go-teams-notify/v2"
)
const (
	versionFlagHelp       = "Whether to display application version and then immediately exit application."
	verboseOutputFlagHelp = "Whether detailed output should be shown after message submission success or failure."
	silentOutputFlagHelp  = "Whether ANY output should be shown after message submission success or failure."
	convertEOLFlagHelp    = "Whether messages with Windows, Mac and Linux newlines are updated to use break statements before message submission."
	teamNameFlagHelp      = "The name of the Team containing our target channel. Used in log messages. If not specified, defaults to \"unspecified\"."
	channelNameFlagHelp   = "The target channel where we will send a message. Used in log messages. If not specified, defaults to \"unspecified\"."
	webhookURLFlagHelp    = "The Webhook URL provided by a preconfigured Connector."
	targetURLFlagHelp     = "The target URL and label (specified as comma separated pair) usually visible as a button towards the bottom of the Microsoft Teams message."
	themeColorFlagHelp    = "The hex color code used to set the desired trim color on submitted messages."
	titleFlagHelp         = "The title for the message to submit."
	messageFlagHelp       = "The message to submit. This message may be provided in Markdown format."
	senderFlagHelp        = "The (optional) sending application name or generator of the message this app will attempt to deliver."
	retriesFlagHelp       = "The number of attempts that this application will make to deliver messages before giving up."
	retriesDelayFlagHelp  = "The number of seconds that this application will wait before making another delivery attempt."
)
const (
	defaultMessageThemeColor     string = "#832561"
	defaultSilentOutput          bool   = false
	defaultVerboseOutput         bool   = false
	defaultConvertEOL            bool   = false
	defaultTeamName              string = "unspecified"
	defaultChannelName           string = "unspecified"
	defaultWebhookURL            string = ""
	defaultMessageTitle          string = ""
	defaultMessageText           string = ""
	defaultSender                string = ""
	defaultDisplayVersionAndExit bool   = false
	defaultRetries               int    = 2
	defaultRetriesDelay          int    = 2
)
var version string = "dev build"
var ErrVersionRequested = errors.New("version information requested")
const myAppName string = "send2teams"
const myAppURL string = "https://github.com/atc0005/" + myAppName
const teamsSubmissionTimeoutMultiplier time.Duration = 2 * time.Second
const DefaultNagiosNotificationTimeout time.Duration = 30 * time.Second
const brandingTextPrefix string = "Message delivered by"
const brandingTextSuffix string = "on behalf of"
type TargetURL struct {
	URL url.URL
	Description string
}
type Config struct {
	Team string
	Channel string
	WebhookURL string
	ThemeColor string
	MessageTitle string
	MessageText string
	Sender string
	TargetURLs targetURLsStringFlag
	Retries int
	RetriesDelay int
	VerboseOutput bool
	SilentOutput bool
	ConvertEOL bool
	ShowVersion bool
}
type targetURLsStringFlag []TargetURL
func (tus *targetURLsStringFlag) String() string {
	if tus == nil {
		return ""
	}
	var output strings.Builder
	for i := range *tus {
		fmt.Fprintf(
			&output,
			"[URL: %s, Desc: %s]",
			(*tus)[i].URL.String(),
			(*tus)[i].Description,
		)
		if i+1 != len(*tus) {
			fmt.Fprintf(&output, ", ")
		}
	}
	return output.String()
}
func (tus *targetURLsStringFlag) Set(value string) error {
	items := strings.Split(value, ",")
	if len(items) != 2 {
		return fmt.Errorf(
			"received %d arguments for target URL flag, expected 2",
			len(items),
		)
	}
	for index, item := range items {
		items[index] = strings.TrimSpace(item)
		items[index] = strings.ReplaceAll(items[index], "'", "")
		items[index] = strings.ReplaceAll(items[index], "\"", "")
	}
	u, err := url.Parse(items[0])
	if err != nil {
		return fmt.Errorf(
			"provided URL %s failed to parse: %v",
			items[0],
			err,
		)
	}
	desc := items[1]
	*tus = append(*tus, TargetURL{
		URL:         *u,
		Description: desc,
	})
	return nil
}
func Branding() {
	fmt.Fprintf(flag.CommandLine.Output(), "\n%s %s\n%s\n\n", myAppName, version, myAppURL)
}
func MessageTrailer(sender string) string {
	var onBehalfOf string
	if strings.TrimSpace(sender) != "" {
		onBehalfOf = fmt.Sprintf(" %s %s ", brandingTextSuffix, sender)
	}
	return fmt.Sprintf(
		"%s [%s](%s) (%s) at %s%s",
		brandingTextPrefix,
		myAppName,
		myAppURL,
		version,
		time.Now().Format(time.RFC3339),
		onBehalfOf,
	)
}
func flagsUsage() func() {
	return func() {
		myBinaryName := filepath.Base(os.Args[0])
		Branding()
		fmt.Fprintf(flag.CommandLine.Output(), "Usage of \"%s\":\n",
			myBinaryName,
		)
		flag.PrintDefaults()
	}
}
func (c Config) String() string {
	return fmt.Sprintf(
		"Team=%q, "+
			"Channel=%q, "+
			"WebhookURL=%q, "+
			"ThemeColor=%q, "+
			"MessageTitle=%q, "+
			"MessageText=%q, "+
			"Sender=%q, "+
			"TargetURLs=%q, "+
			"Retries=%q, "+
			"RetriesDelay=%q, "+
			"AppTimeout=%q",
		c.Team,
		c.Channel,
		c.WebhookURL,
		c.ThemeColor,
		c.MessageTitle,
		c.MessageText,
		c.Sender,
		c.TargetURLs.String(),
		strconv.Itoa(c.Retries),
		strconv.Itoa(c.RetriesDelay),
		c.TeamsSubmissionTimeout(),
	)
}