(flags *flags, cmd *cobra.Command, args []string)
| 51 | } |
| 52 | |
| 53 | func run(flags *flags, cmd *cobra.Command, args []string) { |
| 54 | if len(args) != 2 { |
| 55 | fmt.Fprintln(os.Stderr, "Expected exactly two arguments: base-profile & new-profile") |
| 56 | cmd.Usage() |
| 57 | os.Exit(2) |
| 58 | } |
| 59 | |
| 60 | if flags.threshold < 0 || flags.threshold > 1 { |
| 61 | fmt.Fprintln(os.Stderr, "coverage threshold must be a float number between 0 to 1, inclusive") |
| 62 | os.Exit(1) |
| 63 | } |
| 64 | |
| 65 | baseProfilePath := args[0] |
| 66 | newProfilePath := args[1] |
| 67 | |
| 68 | baseProfiles, err := util.LoadProfile(baseProfilePath) |
| 69 | if err != nil { |
| 70 | fmt.Fprintf(os.Stderr, "Failed to parse base profile file: %v.\n", err) |
| 71 | os.Exit(1) |
| 72 | } |
| 73 | |
| 74 | newProfiles, err := util.LoadProfile(newProfilePath) |
| 75 | if err != nil { |
| 76 | fmt.Fprintf(os.Stderr, "Failed to parse new profile file: %v.\n", err) |
| 77 | os.Exit(1) |
| 78 | } |
| 79 | |
| 80 | postContent, isCoverageLow := diff.ContentForGitHubPost(baseProfiles, newProfiles, flags.jobName, flags.threshold) |
| 81 | |
| 82 | var file io.WriteCloser |
| 83 | if flags.outputFile == "-" { |
| 84 | file = os.Stdout |
| 85 | } else { |
| 86 | file, err = os.Create(flags.outputFile) |
| 87 | if err != nil { |
| 88 | fmt.Fprintf(os.Stderr, "Failed to create output file: %v.", err) |
| 89 | os.Exit(1) |
| 90 | } |
| 91 | defer file.Close() |
| 92 | } |
| 93 | |
| 94 | _, err = io.WriteString(file, fmt.Sprintf("isCoverageLow = %v\n", isCoverageLow)) |
| 95 | |
| 96 | if err != nil { |
| 97 | fmt.Fprintf(os.Stderr, "Failed to write low coverage check: %v.\n", err) |
| 98 | os.Exit(1) |
| 99 | } |
| 100 | |
| 101 | _, err = io.WriteString(file, fmt.Sprintf("Post content:\n%v", postContent)) |
| 102 | if err != nil { |
| 103 | fmt.Fprintf(os.Stderr, "Failed to write post content: %v.\n", err) |
| 104 | os.Exit(1) |
| 105 | } |
| 106 | } |
no test coverage detected