cmd

package
v1.13.1 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var FILE2DVCmd = &cobra.Command{
	Use:          "file2dv",
	Short:        "Extract and Transform from multiple files to CSV, for Geneos Toolkit input",
	Long:         ``,
	SilenceUsage: true,
	CompletionOptions: cobra.CompletionOptions{
		DisableDefaultCmd: true,
	},
	Version:               cordial.VERSION,
	DisableAutoGenTag:     true,
	DisableSuggestions:    true,
	DisableFlagsInUseLine: true,
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		d := config.Join("dataviews", strconv.Itoa(d))
		if !cf.IsSet(d) {
			return errors.New("no dataviews found in configuration")
		}

		dv := cf.Sub(d)

		dataview, err := processFiles(dv)

		if err != nil {
			return
		}
		for _, r := range dataview.Table {
			var row []string
			for _, c := range r {
				row = append(row, strings.ReplaceAll(c, ",", "\\,"))
			}
			fmt.Println(strings.Join(row, ","))
		}
		if dataview.Name != "" {
			fmt.Printf("<!>dataview,%s\n", dataview.Name)
		}
		for _, h := range dataview.Headlines {
			fmt.Printf("<!>%s,%s\n", h.Name, strings.ReplaceAll(h.Value, ",", "\\,"))
		}
		return
	},
}

FILE2DVCmd represents the base command when called without any subcommands

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.

Types

type Column

type Column struct {
	Name  string         `mapstructure:"name"`
	Value string         `mapstructure:"value"`
	Match *regexp.Regexp `mapstructure:"match,omitempty"`
	Fail  string         `mapstructure:"fail,omitempty"`
}

Column holds the options for each column in the output

type Dataview

type Dataview struct {
	Name      string
	Headlines []Headline
	Table     [][]string
}

type Headline

type Headline struct {
	Name  string
	Value string
}

Jump to

Keyboard shortcuts

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