Skip to content

Commit

Permalink
Improve toolchain installation help messaging (#3)
Browse files Browse the repository at this point in the history
* Don't print RemediationError's via text.Output to ensure whitespace is kept intact.

* Make rust toolchain installation remediation errors more user friendly and the command to run more explicit.
  • Loading branch information
phamann authored Feb 24, 2020
1 parent 7263c52 commit bdec6ab
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions pkg/compute/rust.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/BurntSushi/toml"
"github.com/fastly/cli/pkg/common"
"github.com/fastly/cli/pkg/errors"
"github.com/fastly/cli/pkg/text"
)

const (
Expand Down Expand Up @@ -62,7 +63,7 @@ func (r Rust) Verify(out io.Writer) error {
if err != nil {
return errors.RemediationError{
Inner: fmt.Errorf("`rustup` not found in $PATH"),
Remediation: "Please install rustup via e.g.\n\n\tcurl https://sh.rustup.rs -sSf | sh\n\tbrew install rustup-init ; rustup-init\n",
Remediation: fmt.Sprintf("To fix this error, run the following command:\n\n\t$ %s", text.Bold("curl https://sh.rustup.rs -sSf | sh")),
}
}

Expand Down Expand Up @@ -94,7 +95,7 @@ func (r Rust) Verify(out io.Writer) error {
if !found {
return errors.RemediationError{
Inner: fmt.Errorf("rust toolchain %s not found", RustToolchainVersion),
Remediation: fmt.Sprintf("Please install via\n\n\trustup toolchain install %s\n", RustToolchainVersion),
Remediation: fmt.Sprintf("To fix this error, run the following command:\n\n\t$ %s\n", text.Bold("rustup toolchain install "+RustToolchainVersion)),
}
}

Expand Down Expand Up @@ -125,7 +126,7 @@ func (r Rust) Verify(out io.Writer) error {
if !found {
return errors.RemediationError{
Inner: fmt.Errorf("rust target %s not found", WasmWasiTarget),
Remediation: fmt.Sprintf("Please install via\n\n\trustup target add %s --toolchain %s\n", WasmWasiTarget, RustToolchainVersion),
Remediation: fmt.Sprintf("To fix this error, run the following command:\n\n\t$ %s\n", text.Bold(fmt.Sprintf("rustup target add %s --toolchain %s", WasmWasiTarget, RustToolchainVersion))),
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/errors/remediation_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (re RemediationError) Print(w io.Writer) {
fmt.Fprintln(w) // additional "\n" to allow breathing room
}
if re.Remediation != "" {
text.Output(w, "%s\n", strings.TrimRight(re.Remediation, "\r\n"))
fmt.Fprintf(w, "%s\n", strings.TrimRight(re.Remediation, "\r\n"))
}
}

Expand Down

0 comments on commit bdec6ab

Please sign in to comment.