diff --git a/pkg/cmd/feedback.go b/pkg/cmd/feedback.go index 8c7e0aab9..546818b6e 100644 --- a/pkg/cmd/feedback.go +++ b/pkg/cmd/feedback.go @@ -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) diff --git a/pkg/cmd/info.go b/pkg/cmd/info.go index 09949364f..539f7051e 100644 --- a/pkg/cmd/info.go +++ b/pkg/cmd/info.go @@ -17,6 +17,9 @@ package cmd import ( + "encoding/json" + "fmt" + "github.com/spf13/cobra" "github.com/nitrictech/cli/pkg/ghissue" @@ -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)) + } }, } diff --git a/pkg/cmd/root.go b/pkg/cmd/root.go index 13b3e2564..2b7b503d5 100644 --- a/pkg/cmd/root.go +++ b/pkg/cmd/root.go @@ -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 @@ -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)) + } } }, } diff --git a/pkg/ghissue/buglink.go b/pkg/ghissue/buglink.go index 4fc1689de..67c6fa68b 100644 --- a/pkg/ghissue/buglink.go +++ b/pkg/ghissue/buglink.go @@ -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 { @@ -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), diff --git a/pkg/preferences/userpreferences.go b/pkg/preferences/userpreferences.go index 15093b115..767697dab 100644 --- a/pkg/preferences/userpreferences.go +++ b/pkg/preferences/userpreferences.go @@ -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()