x/mode: add Name.DisplayFullest and update docs
This commit is contained in:
parent
c0d4f55f3e
commit
0c78e6c23d
@ -104,11 +104,11 @@ type Name struct {
|
|||||||
//
|
//
|
||||||
// Examples of valid paths:
|
// Examples of valid paths:
|
||||||
//
|
//
|
||||||
// "example.com/mistral:7b+x"
|
// "example.com/library/mistral:7b+x"
|
||||||
// "example.com/mistral:7b+Q4_0"
|
// "example.com/eva/mistral:7b+Q4_0"
|
||||||
// "mistral:7b+x"
|
// "mistral:7b+x"
|
||||||
// "example.com/x/mistral:latest+Q4_0"
|
// "example.com/mike/mistral:latest+Q4_0"
|
||||||
// "example.com/x/mistral:latest"
|
// "example.com/bruce/mistral:latest"
|
||||||
//
|
//
|
||||||
// Examples of invalid paths:
|
// Examples of invalid paths:
|
||||||
//
|
//
|
||||||
@ -191,23 +191,18 @@ func (r Name) DisplayModel() string {
|
|||||||
return r.model
|
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 {
|
func (r Name) DisplayComplete() string {
|
||||||
return (Name{
|
return (Name{
|
||||||
host: cmp.Or(r.host, "?"),
|
host: r.host,
|
||||||
namespace: cmp.Or(r.namespace, "?"),
|
namespace: r.namespace,
|
||||||
model: cmp.Or(r.model, "?"),
|
model: r.model,
|
||||||
tag: cmp.Or(r.tag, "?"),
|
tag: r.tag,
|
||||||
}).String()
|
}).String()
|
||||||
}
|
}
|
||||||
|
|
||||||
// GoString implements fmt.GoStringer. It is like DisplayComplete but
|
// GoString implements fmt.GoStringer. It returns a string representation that
|
||||||
// includes the build or a "?" if the build is missing.
|
// includes all parts of the Name. For any part that is missing, it is
|
||||||
|
// replaced with a ("?").
|
||||||
func (r Name) GoString() string {
|
func (r Name) GoString() string {
|
||||||
return (Name{
|
return (Name{
|
||||||
host: cmp.Or(r.host, "?"),
|
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
|
// DisplayShort returns a short display string of the Name with only the
|
||||||
// model, tag, and build parts.
|
// model, tag, and build parts.
|
||||||
|
//
|
||||||
|
// It does not include the build.
|
||||||
func (r Name) DisplayShort() string {
|
func (r Name) DisplayShort() string {
|
||||||
return (Name{
|
return (Name{
|
||||||
model: r.model,
|
model: r.model,
|
||||||
@ -234,6 +231,8 @@ func (r Name) DisplayShort() string {
|
|||||||
|
|
||||||
// DisplayLong returns a long display string of the Name including namespace,
|
// DisplayLong returns a long display string of the Name including namespace,
|
||||||
// model, tag, and build parts.
|
// model, tag, and build parts.
|
||||||
|
//
|
||||||
|
// It does not include the build.
|
||||||
func (r Name) DisplayLong() string {
|
func (r Name) DisplayLong() string {
|
||||||
return (Name{
|
return (Name{
|
||||||
namespace: r.namespace,
|
namespace: r.namespace,
|
||||||
@ -242,7 +241,23 @@ func (r Name) DisplayLong() string {
|
|||||||
}).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 {
|
func (r Name) String() string {
|
||||||
var b strings.Builder
|
var b strings.Builder
|
||||||
if r.host != "" {
|
if r.host != "" {
|
||||||
|
@ -218,7 +218,7 @@ func TestNameDisplay(t *testing.T) {
|
|||||||
in: "mistral:latest",
|
in: "mistral:latest",
|
||||||
wantShort: "mistral:latest",
|
wantShort: "mistral:latest",
|
||||||
wantLong: "mistral:latest",
|
wantLong: "mistral:latest",
|
||||||
wantComplete: "?/?/mistral:latest",
|
wantComplete: "mistral:latest",
|
||||||
wantModel: "mistral",
|
wantModel: "mistral",
|
||||||
wantGoString: "?/?/mistral:latest+?",
|
wantGoString: "?/?/mistral:latest+?",
|
||||||
},
|
},
|
||||||
@ -227,7 +227,7 @@ func TestNameDisplay(t *testing.T) {
|
|||||||
in: "library/mistral:latest",
|
in: "library/mistral:latest",
|
||||||
wantShort: "mistral:latest",
|
wantShort: "mistral:latest",
|
||||||
wantLong: "library/mistral:latest",
|
wantLong: "library/mistral:latest",
|
||||||
wantComplete: "?/library/mistral:latest",
|
wantComplete: "library/mistral:latest",
|
||||||
wantModel: "mistral",
|
wantModel: "mistral",
|
||||||
wantGoString: "?/library/mistral:latest+?",
|
wantGoString: "?/library/mistral:latest+?",
|
||||||
},
|
},
|
||||||
@ -236,7 +236,7 @@ func TestNameDisplay(t *testing.T) {
|
|||||||
in: "Library/Mistral:Latest",
|
in: "Library/Mistral:Latest",
|
||||||
wantShort: "Mistral:Latest",
|
wantShort: "Mistral:Latest",
|
||||||
wantLong: "Library/Mistral:Latest",
|
wantLong: "Library/Mistral:Latest",
|
||||||
wantComplete: "?/Library/Mistral:Latest",
|
wantComplete: "Library/Mistral:Latest",
|
||||||
wantModel: "Mistral",
|
wantModel: "Mistral",
|
||||||
wantGoString: "?/Library/Mistral:Latest+?",
|
wantGoString: "?/Library/Mistral:Latest+?",
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user