cmd

package
v1.12.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2024 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CriticalCellStyle = excelize.Style{
		Fill: excelize.Fill{
			Type:    "pattern",
			Color:   []string{"DC143C"},
			Pattern: 1,
		},
		Font: &excelize.Font{
			Color: "FFFFFF",
		},
	}
	WarningCellStyle = excelize.Style{
		Fill: excelize.Fill{
			Type:    "pattern",
			Color:   []string{"FFD700"},
			Pattern: 1,
		},
		Font: &excelize.Font{
			Color: "000000",
		},
	}
	OKCellStyle = excelize.Style{
		Fill: excelize.Fill{
			Type:    "pattern",
			Color:   []string{"32cd32"},
			Pattern: 1,
		},
		Font: &excelize.Font{
			Color: "FFFFFF",
		},
	}
	HeadingCellStyle = excelize.Style{
		Font: &excelize.Font{
			Bold: true,
		},
	}
)

Hardwired cell defaults

View Source
var DV2EMAILCmd = &cobra.Command{
	Use:          "dv2email",
	Short:        "Email a Dataview following Geneos Action/Effect conventions",
	Long:         DV2EMAILCmdDescription,
	SilenceUsage: true,
	CompletionOptions: cobra.CompletionOptions{
		DisableDefaultCmd: true,
	},
	Version:               cordial.VERSION,
	DisableAutoGenTag:     true,
	DisableSuggestions:    true,
	DisableFlagsInUseLine: true,
	RunE: func(cmd *cobra.Command, _ []string) (err error) {
		gw, err := dialGateway(cf)
		if err != nil {
			log.Fatal().Err(err).Msg("")
		}

		em := setupEmail(toArg, ccArg, bccArg)

		data, err := fetchDataviews(cmd, gw,
			em.GetString("_firstcolumn"),
			em.GetString("__headlines"),
			em.GetString("__rows"),
			em.GetString("__columns"),
			em.GetString("__roworder"),
		)

		switch cf.GetString("email.split") {
		case "entity":
			entities := map[string][]*commands.Dataview{}
			for _, d := range data.Dataviews {
				if len(entities[d.XPath.Entity.Name]) == 0 {
					entities[d.XPath.Entity.Name] = []*commands.Dataview{}
				}
				entities[d.XPath.Entity.Name] = append(entities[d.XPath.Entity.Name], d)
			}
			for _, e := range entities {
				many := DV2EMailData{
					Dataviews: e,
					Env:       data.Env,
				}
				if err = sendEmail(em, many, inlineCSS); err != nil {
					log.Fatal().Err(err).Msg("")
				}
			}
		case "dataview":
			for _, d := range data.Dataviews {
				one := DV2EMailData{
					Dataviews: []*commands.Dataview{d},
					Env:       data.Env,
				}
				if err = sendEmail(em, one, inlineCSS); err != nil {
					log.Fatal().Err(err).Msg("")
				}
			}
		default:
			if err = sendEmail(em, data, inlineCSS); err != nil {
				log.Fatal().Err(err).Msg("")
			}
		}

		return
	},
}

DV2EMAILCmd represents the base command when called without any subcommands

View Source
var DV2EMAILCmdDescription string

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the RootCmd.

func Less added in v1.11.2

func Less(a, b string) bool

Less does a 'natural' comparison on the two strings.

It treats digits as decimal numbers, so that Less("10", "2") return false.

This function does no memory allocation.

Types

type DV2EMailData added in v1.11.0

type DV2EMailData struct {
	// Dataviews is a slice of each Dataview's data, including Columns
	// and Rows which are ordered names for the columns and rows
	// respectively, suitable for range loops. See
	// https://pkg.go.dev/github.com/itrs-group/cordial/pkg/commands#Dataview
	// for details
	Dataviews []*commands.Dataview

	// Env is a map of environment variable, names to values
	Env map[string]string
}

type NatsortStringSlice added in v1.11.2

type NatsortStringSlice []string

NatsortStringSlice attaches the methods of Interface to []string, sorting in increasing order using natural order.

func (NatsortStringSlice) Len added in v1.11.2

func (p NatsortStringSlice) Len() int

func (NatsortStringSlice) Less added in v1.11.2

func (p NatsortStringSlice) Less(i, j int) bool

func (NatsortStringSlice) Swap added in v1.11.2

func (p NatsortStringSlice) Swap(i, j int)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL