Skip to content

Commit

Permalink
Output license details with 'view' command
Browse files Browse the repository at this point in the history
  • Loading branch information
cheshire137 committed Oct 8, 2024
1 parent 0a56b20 commit bb9e140
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
28 changes: 17 additions & 11 deletions cmd/view/model_printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ func newModelPrinter(summary *azure_models.ModelSummary, details *azure_models.M
func (p *modelPrinter) render() error {
modelSummary := p.modelSummary
if modelSummary != nil {
p.addLabeledValue("Display name:", modelSummary.FriendlyName)
p.addLabeledValue("Summary name:", modelSummary.Name)
p.addLabeledValue("Publisher:", modelSummary.Publisher)
p.addLabeledValue("Summary:", modelSummary.Summary)
p.printLabelledLine("Display name:", modelSummary.FriendlyName)
p.printLabelledLine("Summary name:", modelSummary.Name)
p.printLabelledLine("Publisher:", modelSummary.Publisher)
p.printLabelledLine("Summary:", modelSummary.Summary)
}

modelDetails := p.modelDetails
if modelDetails != nil {
p.addLabel("Description:")
p.printer.AddField(modelDetails.Description, tableprinter.WithTruncate(nil))
p.printer.EndRow()
p.printLabelledLine("License:", modelDetails.License)
p.printMultipleLinesWithLabel("License description:", modelDetails.LicenseDescription)
p.printMultipleLinesWithLabel("Description:", modelDetails.Description)
}

err := p.printer.Render()
Expand All @@ -43,12 +43,18 @@ func (p *modelPrinter) render() error {
return nil
}

func (p *modelPrinter) addLabel(label string) {
p.printer.AddField(label, tableprinter.WithTruncate(nil), tableprinter.WithColor(util.LightGrayUnderline))
func (p *modelPrinter) printLabelledLine(label string, value string) {
p.addLabel(label)
p.printer.AddField(value)
p.printer.EndRow()
}

func (p *modelPrinter) addLabeledValue(label string, value string) {
func (p *modelPrinter) printMultipleLinesWithLabel(label string, value string) {
p.addLabel(label)
p.printer.AddField(value)
p.printer.AddField(value, tableprinter.WithTruncate(nil))
p.printer.EndRow()
}

func (p *modelPrinter) addLabel(label string) {
p.printer.AddField(label, tableprinter.WithTruncate(nil), tableprinter.WithColor(util.LightGrayUnderline))
}
4 changes: 3 additions & 1 deletion internal/azure_models/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ func (c *Client) GetModelDetails(registry string, modelName string, version stri
}

return &ModelDetails{
Description: detailsResponse.Description,
Description: detailsResponse.Description,
License: detailsResponse.License,
LicenseDescription: detailsResponse.LicenseDescription,
}, nil
}

Expand Down
4 changes: 3 additions & 1 deletion internal/azure_models/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ type modelCatalogDetailsResponse struct {
}

type ModelDetails struct {
Description string `json:"description"`
Description string `json:"description"`
License string `json:"license"`
LicenseDescription string `json:"license_description"`
}

func Ptr[T any](value T) *T {
Expand Down

0 comments on commit bb9e140

Please sign in to comment.