From 0c78e6c23d37eb6732fe3593cd97d944d1e8af52 Mon Sep 17 00:00:00 2001 From: Blake Mizerany Date: Fri, 5 Apr 2024 22:14:09 -0700 Subject: [PATCH] x/mode: add Name.DisplayFullest and update docs --- x/model/name.go | 49 +++++++++++++++++++++++++++++--------------- x/model/name_test.go | 6 +++--- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/x/model/name.go b/x/model/name.go index 4d4e1cb3..cc9857ef 100644 --- a/x/model/name.go +++ b/x/model/name.go @@ -104,11 +104,11 @@ type Name struct { // // Examples of valid paths: // -// "example.com/mistral:7b+x" -// "example.com/mistral:7b+Q4_0" +// "example.com/library/mistral:7b+x" +// "example.com/eva/mistral:7b+Q4_0" // "mistral:7b+x" -// "example.com/x/mistral:latest+Q4_0" -// "example.com/x/mistral:latest" +// "example.com/mike/mistral:latest+Q4_0" +// "example.com/bruce/mistral:latest" // // Examples of invalid paths: // @@ -191,23 +191,18 @@ func (r Name) DisplayModel() string { return r.model } -// DisplayComplete returns a complete display string of the Name. For any -// part that is missing, a ("?") is used. If a complete name is not required -// and only the longest possible name is needed, use [Name.String] or -// String or check if [Name.Complete] is true before calling. -// -// It does not include the build. func (r Name) DisplayComplete() string { return (Name{ - host: cmp.Or(r.host, "?"), - namespace: cmp.Or(r.namespace, "?"), - model: cmp.Or(r.model, "?"), - tag: cmp.Or(r.tag, "?"), + host: r.host, + namespace: r.namespace, + model: r.model, + tag: r.tag, }).String() } -// GoString implements fmt.GoStringer. It is like DisplayComplete but -// includes the build or a "?" if the build is missing. +// GoString implements fmt.GoStringer. It returns a string representation that +// includes all parts of the Name. For any part that is missing, it is +// replaced with a ("?"). func (r Name) GoString() string { return (Name{ host: cmp.Or(r.host, "?"), @@ -225,6 +220,8 @@ func (r Name) LogValue() slog.Value { // DisplayShort returns a short display string of the Name with only the // model, tag, and build parts. +// +// It does not include the build. func (r Name) DisplayShort() string { return (Name{ model: r.model, @@ -234,6 +231,8 @@ func (r Name) DisplayShort() string { // DisplayLong returns a long display string of the Name including namespace, // model, tag, and build parts. +// +// It does not include the build. func (r Name) DisplayLong() string { return (Name{ namespace: r.namespace, @@ -242,7 +241,23 @@ func (r Name) DisplayLong() string { }).String() } -// String returns the fully qualified Name string. +// DisplayFullest returns the fullest display string of the Name including +// host, namespace, model, tag. +// +// It does not include the build. +func (r Name) DisplayFullest() string { + return (Name{ + host: r.host, + namespace: r.namespace, + model: r.model, + tag: r.tag, + }).String() +} + +// String returns the fullest string respresentation of the Name. +// +// It includes the build, if any. For a string representation without the +// build, use [Name.DisplayFullest]. func (r Name) String() string { var b strings.Builder if r.host != "" { diff --git a/x/model/name_test.go b/x/model/name_test.go index a1c8d2bc..b44be44b 100644 --- a/x/model/name_test.go +++ b/x/model/name_test.go @@ -218,7 +218,7 @@ func TestNameDisplay(t *testing.T) { in: "mistral:latest", wantShort: "mistral:latest", wantLong: "mistral:latest", - wantComplete: "?/?/mistral:latest", + wantComplete: "mistral:latest", wantModel: "mistral", wantGoString: "?/?/mistral:latest+?", }, @@ -227,7 +227,7 @@ func TestNameDisplay(t *testing.T) { in: "library/mistral:latest", wantShort: "mistral:latest", wantLong: "library/mistral:latest", - wantComplete: "?/library/mistral:latest", + wantComplete: "library/mistral:latest", wantModel: "mistral", wantGoString: "?/library/mistral:latest+?", }, @@ -236,7 +236,7 @@ func TestNameDisplay(t *testing.T) { in: "Library/Mistral:Latest", wantShort: "Mistral:Latest", wantLong: "Library/Mistral:Latest", - wantComplete: "?/Library/Mistral:Latest", + wantComplete: "Library/Mistral:Latest", wantModel: "Mistral", wantGoString: "?/Library/Mistral:Latest+?", },