github.com/jfrog/jfrog-cli-core/v2@v2.51.0/common/format/output.go (about)

     1  package format
     2  
     3  import (
     4  	"strings"
     5  
     6  	"github.com/jfrog/jfrog-cli-core/v2/utils/coreutils"
     7  	"github.com/jfrog/jfrog-client-go/utils/errorutils"
     8  )
     9  
    10  type OutputFormat string
    11  
    12  const (
    13  	// OutputFormat values
    14  	Table      OutputFormat = "table"
    15  	Json       OutputFormat = "json"
    16  	SimpleJson OutputFormat = "simple-json"
    17  	Sarif      OutputFormat = "sarif"
    18  )
    19  
    20  var OutputFormats = []string{string(Table), string(Json), string(SimpleJson), string(Sarif)}
    21  
    22  func GetOutputFormat(formatFlagVal string) (format OutputFormat, err error) {
    23  	// Default print format is table.
    24  	format = Table
    25  	if formatFlagVal != "" {
    26  		switch strings.ToLower(formatFlagVal) {
    27  		case string(Table):
    28  			format = Table
    29  		case string(Json):
    30  			format = Json
    31  		case string(SimpleJson):
    32  			format = SimpleJson
    33  		case string(Sarif):
    34  			format = Sarif
    35  		default:
    36  			err = errorutils.CheckErrorf("only the following output formats are supported: " + coreutils.ListToText(OutputFormats))
    37  		}
    38  	}
    39  	return
    40  }