This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
80 lines (69 loc) · 1.6 KB
/
main.go
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/test-network-function/gradetool/tool"
)
var (
results string
policy string
OutputPath string
grade = &cobra.Command{
Use: "gradetool",
Short: "gradetool",
RunE: runGradetool,
}
)
func main() {
// Build command
NewCommand()
if err := grade.Execute(); err != nil {
log.Fatal(err)
}
}
func runGradetool(_ *cobra.Command, _ []string) error {
resultsPath := results
policyPath := policy
outputPath := OutputPath
// Trim the spaces out of these paths
resultsPath = strings.TrimSpace(resultsPath)
policyPath = strings.TrimSpace(policyPath)
outputPath = strings.TrimSpace(outputPath)
// Generate the grade
err := tool.GenerateGrade(resultsPath, policyPath, outputPath)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// read the output file and display to user
outFile, err := os.ReadFile(outputPath)
if err != nil {
fmt.Println(err)
return err
}
outFileString := string(outFile)
fmt.Println(outFileString)
return nil
}
func NewCommand() *cobra.Command {
grade.Flags().StringVarP(&results, "results", "r", "", "Path to the input test results file")
grade.Flags().StringVarP(&policy, "policy", "p", "", "Path to the input policy file")
grade.Flags().StringVarP(&OutputPath, "OutputPath", "o", "", "Path to the output file")
// Mark required flags
err := grade.MarkFlagRequired("results")
if err != nil {
return nil
}
err = grade.MarkFlagRequired("policy")
if err != nil {
return nil
}
err = grade.MarkFlagRequired("OutputPath")
if err != nil {
return nil
}
return grade
}