addrs: remove Plugin.ForDisplay func, the String one does the job
to make things less confusing
This commit is contained in:
parent
516e919c5e
commit
8208f425c8
|
@ -109,7 +109,7 @@ func (c *InitCommand) RunContext(buildCtx context.Context, cla *InitArgs) int {
|
|||
return 1
|
||||
}
|
||||
|
||||
log.Printf("[TRACE] for plugin %s found %d matching installation(s)", pluginRequirement.Identifier.ForDisplay(), len(installs))
|
||||
log.Printf("[TRACE] for plugin %s found %d matching installation(s)", pluginRequirement.Identifier, len(installs))
|
||||
|
||||
if len(installs) > 0 && cla.Upgrade == false {
|
||||
continue
|
||||
|
@ -125,7 +125,7 @@ func (c *InitCommand) RunContext(buildCtx context.Context, cla *InitArgs) int {
|
|||
ret = 1
|
||||
}
|
||||
if newInstall != nil {
|
||||
msg := fmt.Sprintf("Installed plugin %s %s in %q", pluginRequirement.Identifier.ForDisplay(), newInstall.Version, newInstall.BinaryPath)
|
||||
msg := fmt.Sprintf("Installed plugin %s %s in %q", pluginRequirement.Identifier, newInstall.Version, newInstall.BinaryPath)
|
||||
ui.Say(msg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,26 +27,6 @@ func (p Plugin) String() string {
|
|||
return strings.Join(p.Parts(), "/")
|
||||
}
|
||||
|
||||
// ForDisplay returns a user-friendly FQN string, simplified for readability. If
|
||||
// the plugin is using the default hostname, the hostname is omitted.
|
||||
func (p *Plugin) ForDisplay() string {
|
||||
const (
|
||||
// These will be hidden if they are a prefix
|
||||
DefaultHashicorpPluginHost = "github.com"
|
||||
DefaultHashicorpPluginNamespace = "hashicorp"
|
||||
)
|
||||
|
||||
parts := []string{}
|
||||
if p.Hostname != DefaultHashicorpPluginHost {
|
||||
parts = append(parts, p.Hostname)
|
||||
}
|
||||
if p.Namespace != DefaultHashicorpPluginNamespace && len(parts) == 0 {
|
||||
parts = append(parts, p.Namespace)
|
||||
}
|
||||
parts = append(parts, p.Type)
|
||||
return strings.Join(parts, "/")
|
||||
}
|
||||
|
||||
// ParsePluginPart processes an addrs.Plugin namespace or type string
|
||||
// provided by an end-user, producing a normalized version if possible or
|
||||
// an error if the string contains invalid characters.
|
||||
|
@ -204,7 +184,10 @@ func ParsePluginSourceString(str string) (*Plugin, hcl.Diagnostics) {
|
|||
diags = diags.Append(&hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: "Invalid plugin type",
|
||||
Detail: fmt.Sprintf("Plugin source %q has a type with the prefix %q, which isn't valid. Although that prefix is often used in the names of version control repositories for Packer plugins, plugin source strings should not include it.\n\nDid you mean %q?", ret.ForDisplay(), userErrorPrefix, suggestedAddr.ForDisplay()),
|
||||
Detail: fmt.Sprintf("Plugin source %q has a type with the prefix %q, which isn't valid. "+
|
||||
"Although that prefix is often used in the names of version control repositories for Packer plugins, "+
|
||||
"plugin source strings should not include it.\n"+
|
||||
"\nDid you mean %q?", ret, userErrorPrefix, suggestedAddr),
|
||||
})
|
||||
return nil, diags
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ func (cfg *PackerConfig) detectPluginBinaries() hcl.Diagnostics {
|
|||
if err != nil {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: fmt.Sprintf("Failed to list installation for %s", pluginRequirement.Identifier.ForDisplay()),
|
||||
Summary: fmt.Sprintf("Failed to list installation for %s", pluginRequirement.Identifier),
|
||||
Detail: err.Error(),
|
||||
})
|
||||
continue
|
||||
|
@ -86,18 +86,18 @@ func (cfg *PackerConfig) detectPluginBinaries() hcl.Diagnostics {
|
|||
if len(sortedInstalls) == 0 {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: fmt.Sprintf("no plugin installed for %s %v", pluginRequirement.Identifier.ForDisplay(), pluginRequirement.VersionConstraints.String()),
|
||||
Summary: fmt.Sprintf("no plugin installed for %s %v", pluginRequirement.Identifier, pluginRequirement.VersionConstraints.String()),
|
||||
Detail: "Did you run packer init for this project ?",
|
||||
})
|
||||
continue
|
||||
}
|
||||
log.Printf("[TRACE] Found the following %q installations: %v", pluginRequirement.Identifier.ForDisplay(), sortedInstalls)
|
||||
log.Printf("[TRACE] Found the following %q installations: %v", pluginRequirement.Identifier, sortedInstalls)
|
||||
install := sortedInstalls[len(sortedInstalls)-1]
|
||||
err = cfg.parser.PluginConfig.DiscoverMultiPlugin(pluginRequirement.Accessor, install.BinaryPath)
|
||||
if err != nil {
|
||||
diags = append(diags, &hcl.Diagnostic{
|
||||
Severity: hcl.DiagError,
|
||||
Summary: fmt.Sprintf("Error discovering plugin %s", pluginRequirement.Identifier.ForDisplay()),
|
||||
Summary: fmt.Sprintf("Error discovering plugin %s", pluginRequirement.Identifier),
|
||||
Detail: err.Error(),
|
||||
})
|
||||
continue
|
||||
|
|
|
@ -81,7 +81,7 @@ func (pr Requirement) ListInstallations(opts ListInstallationsOptions) (InstallL
|
|||
res := InstallList{}
|
||||
FilenamePrefix := pr.FilenamePrefix()
|
||||
filenameSuffix := opts.filenameSuffix()
|
||||
log.Printf("[TRACE] listing potential installations for %q that match %q. %#v", pr.Identifier.ForDisplay(), pr.VersionConstraints, opts)
|
||||
log.Printf("[TRACE] listing potential installations for %q that match %q. %#v", pr.Identifier, pr.VersionConstraints, opts)
|
||||
for _, knownFolder := range opts.FromFolders {
|
||||
glob := filepath.Join(knownFolder, pr.Identifier.Hostname, pr.Identifier.Namespace, pr.Identifier.Type, FilenamePrefix+"*"+filenameSuffix)
|
||||
|
||||
|
@ -345,7 +345,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
|
|||
getters := opts.Getters
|
||||
fail := fmt.Errorf("could not find a local nor a remote checksum for plugin %q %q", pr.Identifier, pr.VersionConstraints)
|
||||
|
||||
log.Printf("[TRACE] getting available versions for the the %s plugin", pr.Identifier.ForDisplay())
|
||||
log.Printf("[TRACE] getting available versions for the the %s plugin", pr.Identifier)
|
||||
versions := version.Collection{}
|
||||
for _, getter := range getters {
|
||||
|
||||
|
@ -397,7 +397,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
|
|||
log.Printf("[DEBUG] will try to install: %s", versions)
|
||||
|
||||
if len(versions) == 0 {
|
||||
err := fmt.Errorf("no release version found for the %s plugin matching the constraint(s): %q", pr.Identifier.ForDisplay(), pr.VersionConstraints.String())
|
||||
err := fmt.Errorf("no release version found for the %s plugin matching the constraint(s): %q", pr.Identifier, pr.VersionConstraints.String())
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -411,7 +411,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
|
|||
filepath.Join(pr.Identifier.Parts()...),
|
||||
)
|
||||
|
||||
log.Printf("[TRACE] fetching checksums file for the %q version of the %s plugin in %q...", version, pr.Identifier.ForDisplay(), outputFolder)
|
||||
log.Printf("[TRACE] fetching checksums file for the %q version of the %s plugin in %q...", version, pr.Identifier, outputFolder)
|
||||
|
||||
var checksum *FileChecksum
|
||||
for _, getter := range getters {
|
||||
|
@ -428,7 +428,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
|
|||
version: version,
|
||||
})
|
||||
if err != nil {
|
||||
err := fmt.Errorf("could not get %s checksum file for %s version %s. Is the file present on the release and correctly named ? %s", checksummer.Type, pr.Identifier.ForDisplay(), version, err)
|
||||
err := fmt.Errorf("could not get %s checksum file for %s version %s. Is the file present on the release and correctly named ? %s", checksummer.Type, pr.Identifier, version, err)
|
||||
log.Printf("[TRACE] %s", err.Error())
|
||||
return nil, err
|
||||
}
|
||||
|
@ -486,7 +486,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
|
|||
log.Printf("[TRACE] found a pre-exising %q checksum file", potentialChecksumer.Type)
|
||||
// if outputFile is there and matches the checksum: do nothing more.
|
||||
if err := localChecksum.ChecksumFile(localChecksum.Expected, potentialOutputFilename); err == nil {
|
||||
log.Printf("[INFO] %s v%s plugin is already correctly installed in %q", pr.Identifier.ForDisplay(), version, potentialOutputFilename)
|
||||
log.Printf("[INFO] %s v%s plugin is already correctly installed in %q", pr.Identifier, version, potentialOutputFilename)
|
||||
return nil, nil
|
||||
}
|
||||
}
|
||||
|
@ -519,7 +519,7 @@ func (pr *Requirement) InstallLatest(opts InstallOptions) (*Installation, error)
|
|||
expectedZipFilename: expectedZipFilename,
|
||||
})
|
||||
if err != nil {
|
||||
err := fmt.Errorf("could not get binary for %s version %s. Is the file present on the release and correctly named ? %s", pr.Identifier.ForDisplay(), version, err)
|
||||
err := fmt.Errorf("could not get binary for %s version %s. Is the file present on the release and correctly named ? %s", pr.Identifier, version, err)
|
||||
log.Printf("[TRACE] %v", err)
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -173,10 +173,7 @@ for brevity.
|
|||
|
||||
The source address with all three components given explicitly is called the
|
||||
plugin's _fully-qualified address_. You will see fully-qualified address in
|
||||
various outputs, like error messages, but in most cases a simplified display
|
||||
version is used. Therefore you may see the shortened version `"myawesomecloud"`
|
||||
instead of `"github.com/hashicorp/myawesomecloud"`. This will happen only when
|
||||
the prefix is `github.com/hashicorp`.
|
||||
various outputs, like error messages.
|
||||
|
||||
## Plugin location
|
||||
|
||||
|
|
Loading…
Reference in New Issue