-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
395 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"gopkg.in/yaml.v2" | ||
analyzer "github.com/replicatedhq/troubleshoot/pkg/analyze" | ||
"github.com/replicatedhq/troubleshoot/pkg/convert" | ||
"github.com/replicatedhq/troubleshoot/pkg/logger" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func Analyze() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "analyze", | ||
Short: "analyze a support bundle", | ||
Long: `...`, | ||
PreRun: func(cmd *cobra.Command, args []string) { | ||
viper.BindPFlag("url", cmd.Flags().Lookup("url")) | ||
viper.BindPFlag("output", cmd.Flags().Lookup("output")) | ||
viper.BindPFlag("quiet", cmd.Flags().Lookup("quiet")) | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
v := viper.GetViper() | ||
|
||
logger.SetQuiet(v.GetBool("quiet")) | ||
|
||
result, err := analyzer.DownloadAndAnalyze(context.TODO(), v.GetString("url")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var data interface{} | ||
switch v.GetString("compatibility") { | ||
case "support-bundle": | ||
data = convert.FromAnalyzerResult(result) | ||
default: | ||
data = result | ||
} | ||
|
||
var formatted []byte | ||
switch v.GetString("output") { | ||
case "json": | ||
formatted, err = json.MarshalIndent(data, "", " ") | ||
case "", "yaml": | ||
formatted, err = yaml.Marshal(data) | ||
default: | ||
return fmt.Errorf("unsupported output format: %q", v.GetString("output")) | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Printf("%s", formatted) | ||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().String("url", "", "URL of the support bundle to analyze") | ||
cmd.Flags().String("output", "", "output format: json, yaml") | ||
cmd.Flags().String("compatibility", "", "output compatibility mode: support-bundle") | ||
cmd.Flags().Bool("quiet", false, "enable/disable error messaging and only show parseable output") | ||
cmd.MarkFlagRequired("url") | ||
|
||
viper.BindPFlags(cmd.Flags()) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.