aboutsummaryrefslogtreecommitdiff
path: root/cmd/cvss.go
blob: d704811e3af6d975bc72aa78f41592709a498767 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package cmd

import (
  "encoding/json"
  "github.com/pablotron/cvez/cvss"
  "github.com/spf13/cobra"
  "github.com/rs/zerolog"
  "github.com/rs/zerolog/log"
  "os"
  "time"
)

var cvssCmd = &cobra.Command{
  Use:   "cvss",
  Short: "CVSS vector calculator.",
  Long: `Common Vulnerability Scoring System (CVSS) vector calculator.`,

  Run: func(cmd *cobra.Command, args []string) {
    // set global logging options
    zerolog.TimeFieldFormat = time.RFC3339
    zerolog.SetGlobalLevel(zerolog.InfoLevel)

    // parse args, write result
    e := json.NewEncoder(os.Stdout)
    if err := e.Encode(cvss.Calc(args)); err != nil {
      log.Error().Err(err).Msg("Encode")
    }
  },
}

func init() {
  rootCmd.AddCommand(cvssCmd)
}