Skip to content

Commit

Permalink
coverage command support JSON output
Browse files Browse the repository at this point in the history
  • Loading branch information
k1LoW committed Oct 8, 2023
1 parent 1aa646b commit 7336844
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions cmd/coverage.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package cmd

import (
"context"
"encoding/json"
"fmt"
"net/http"
"os"
Expand Down Expand Up @@ -83,6 +84,16 @@ var coverageCmd = &cobra.Command{
if err != nil {
return err
}

if flgs.Format == "json" {
b, err := json.MarshalIndent(cov, "", " ")
if err != nil {
return err
}
_, _ = fmt.Println(string(b))
return nil
}

table := tablewriter.NewWriter(os.Stdout)
ct := "Coverage"
if flgs.Long {
Expand Down Expand Up @@ -159,5 +170,6 @@ func init() {
coverageCmd.Flags().StringSliceVarP(&flgs.GRPCProtos, "grpc-proto", "", []string{}, flgs.Usage("GRPCProtos"))
coverageCmd.Flags().StringSliceVarP(&flgs.GRPCImportPaths, "grpc-import-path", "", []string{}, flgs.Usage("GRPCImportPaths"))
coverageCmd.Flags().StringVarP(&flgs.CacheDir, "cache-dir", "", "", flgs.Usage("CacheDir"))
coverageCmd.Flags().StringVarP(&flgs.Format, "format", "", "", flgs.Usage("Format"))
coverageCmd.Flags().BoolVarP(&flgs.RetainCacheDir, "retain-cache-dir", "", false, flgs.Usage("RetainCacheDir"))
}

0 comments on commit 7336844

Please sign in to comment.