diff --git a/README.md b/README.md index 890ff6ce3c..1587e35e52 100644 --- a/README.md +++ b/README.md @@ -31,11 +31,36 @@ K8sGPT uses analyzers to triage and diagnose issues in your cluster. It has a se ## Usage ``` -# Ensure KUBECONFIG env is set to an active Kubernetes cluster +Kubernetes debugging powered by AI + +Usage: + k8sgpt [command] + +Available Commands: + analyze This command will find problems within your Kubernetes cluster + auth Authenticate with your chosen backend + completion Generate the autocompletion script for the specified shell + help Help about any command + +``` + +_Run a scan with the default analyzers_ + +``` k8sgpt auth -k8sgpt find problems -# for more detail -k8s find problems --explain +k8sgpt analyze --explain +``` + +_Filter on resource_ + +``` +k8sgpt analyze --explain --resource=Service +``` + +_Output to JSON_ + +``` +k8sgpt analyze --explain --resource=Service --output=json ``` ## Upcoming major milestones diff --git a/cmd/analyze/analyze.go b/cmd/analyze/analyze.go index 22c48bff54..4d2785f6c6 100644 --- a/cmd/analyze/analyze.go +++ b/cmd/analyze/analyze.go @@ -89,6 +89,11 @@ var AnalyzeCmd = &cobra.Command{ if len(*analysisResults) > 0 { bar = progressbar.Default(int64(len(*analysisResults))) } + + // This variable is used to store the results that will be printed + // It's necessary because the heap memory is lost when the function returns + var printOutput []analyzer.Analysis + for _, analysis := range *analysisResults { if explain { @@ -100,10 +105,11 @@ var AnalyzeCmd = &cobra.Command{ analysis.Details = parsedText bar.Add(1) } + printOutput = append(printOutput, analysis) } // print results - for n, analysis := range *analysisResults { + for n, analysis := range printOutput { switch output { case "json":