Skip to content

Commit

Permalink
Merge pull request #346 from nitrictech/fix/user-preference-error
Browse files Browse the repository at this point in the history
Fix/improve initial user experience
  • Loading branch information
tjholm authored Sep 16, 2022
2 parents f5ceb60 + 0a435be commit 07469b6
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
3 changes: 1 addition & 2 deletions pkg/cmd/feedback.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ var feedbackCmd = &cobra.Command{
Body string
}{}

d, err := ghissue.Gather()
cobra.CheckErr(err)
d := ghissue.Gather()

diag, err := yaml.Marshal(d)
cobra.CheckErr(err)
Expand Down
14 changes: 11 additions & 3 deletions pkg/cmd/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package cmd

import (
"encoding/json"
"fmt"

"github.com/spf13/cobra"

"github.com/nitrictech/cli/pkg/ghissue"
Expand All @@ -28,8 +31,13 @@ var infoCmd = &cobra.Command{
Short: "Gather information about Nitric and the environment",
Long: `Gather information about Nitric and the environment.`,
Run: func(cmd *cobra.Command, args []string) {
d, err := ghissue.Gather()
cobra.CheckErr(err)
output.Print(d)
d := ghissue.Gather()

s, err := json.MarshalIndent(d, "", " ")
if err != nil {
output.Print(d)
} else {
fmt.Println(string(s))
}
},
}
11 changes: 7 additions & 4 deletions pkg/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
cmdstack "github.com/nitrictech/cli/pkg/cmd/stack"
"github.com/nitrictech/cli/pkg/ghissue"
"github.com/nitrictech/cli/pkg/output"
"github.com/nitrictech/cli/pkg/preferences"
"github.com/nitrictech/cli/pkg/utils"
)

const usageTemplate = `Nitric - The fastest way to build serverless apps
Expand Down Expand Up @@ -62,9 +62,12 @@ var rootCmd = &cobra.Command{
pterm.DisableStyling()
}

err := preferences.PromptFeedback()
if err != nil {
fmt.Println(err.Error())
// Ensure the Nitric Home Directory Exists
if _, err := os.Stat(utils.NitricHomeDir()); os.IsNotExist(err) {
err := os.MkdirAll(utils.NitricHomeDir(), 0o700) // Create the Nitric Home Directory if it's missing
if err != nil {
cobra.CheckErr(fmt.Errorf("Failed to create nitric home directory. %w", err))
}
}
},
}
Expand Down
35 changes: 19 additions & 16 deletions pkg/ghissue/buglink.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ import (
)

type Diagnostics struct {
OS string `json:"os"`
Arch string `json:"arch"`
GoVersion string `json:"goVersion"`
CliVersion string `json:"cliVersion"`
FabricVersion string `json:"fabricVersion"`
ContainerRuntime string `json:"containerRuntime"`
ContainerRuntimeVersion string `json:"containerRuntimeVersion"`
OS string `json:"os"`
Arch string `json:"arch"`
GoVersion string `json:"goVersion"`
CliVersion string `json:"cliVersion"`
FabricVersion string `json:"fabricVersion"`
ContainerRuntime string `json:"containerRuntime"`
ContainerRuntimeVersion string `json:"containerRuntimeVersion"`
DetectedErrors []string `json:"detectedErrors"`
}

type GHIssue struct {
Expand All @@ -49,27 +50,29 @@ type GHIssue struct {
}

var diag = Diagnostics{
OS: runtime.GOOS,
Arch: runtime.GOARCH,
GoVersion: runtime.Version(),
CliVersion: utils.Version,
FabricVersion: project.DefaultMembraneVersion,
OS: runtime.GOOS,
Arch: runtime.GOARCH,
GoVersion: runtime.Version(),
CliVersion: utils.Version,
FabricVersion: project.DefaultMembraneVersion,
DetectedErrors: make([]string, 0),
}

func Gather() (*Diagnostics, error) {
func Gather() *Diagnostics {
ce, err := containerengine.Discover()
if err != nil {
return &diag, err
diag.DetectedErrors = append(diag.DetectedErrors, err.Error())
return &diag
}

diag.ContainerRuntime = ce.Type()
diag.ContainerRuntimeVersion = ce.Version()

return &diag, nil
return &diag
}

func BugLink(err interface{}) string {
d, _ := Gather()
d := Gather()
issue := GHIssue{
Diagnostics: *d,
Error: fmt.Sprint(err),
Expand Down
2 changes: 1 addition & 1 deletion pkg/preferences/userpreferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func ReadUserPreferences() (*UserPreferences, error) {
func (up *UserPreferences) WriteToFile() error {
file, err := os.Create(utils.NitricPreferencesPath())
if err != nil {
return err
return fmt.Errorf("failed to update user preferences.\n\tUnable to access file: %s", utils.NitricPreferencesPath())
}
defer file.Close()

Expand Down

0 comments on commit 07469b6

Please sign in to comment.