func newShowCommand()

in internal/cmd/show.go [28:96]


func newShowCommand() *cobra.Command {
	cliOptions := &showOptions{}
	cmd := &cobra.Command{
		Use:   "show",
		Short: "Show a Qodana report",
		Long: `Show (serve) the latest Qodana report. Or open the results directory if the flag is set.

Due to JavaScript security restrictions, the generated report cannot
be viewed via the file:// protocol (by double-clicking the index.html file).
https://www.jetbrains.com/help/qodana/html-report.html
This command serves the Qodana report locally and opens a browser to it.`,
		Run: func(cmd *cobra.Command, args []string) {
			qdenv.InitializeQodanaGlobalEnv(qdenv.EmptyEnvProvider())

			commonCtx := commoncontext.Compute(
				cliOptions.Linter,
				"",
				"",
				"",
				"",
				cliOptions.ResultsDir,
				cliOptions.ReportDir,
				qdenv.GetQodanaGlobalEnv(qdenv.QodanaToken),
				false,
				cliOptions.ProjectDir,
				"",
				cliOptions.ConfigName,
			)
			if cliOptions.OpenDir {
				err := core.OpenDir(commonCtx.ResultsDir)
				if err != nil {
					log.Fatal(err)
				}
			} else {
				commoncontext.ShowReport(
					commonCtx.ResultsDir,
					commonCtx.ReportDir,
					cliOptions.Port,
				)
			}
		},
	}
	flags := cmd.Flags()
	flags.StringVarP(&cliOptions.Linter, "linter", "l", "", "Override linter to use")
	flags.StringVarP(&cliOptions.ProjectDir, "project-dir", "i", ".", "Root directory of the inspected project")
	flags.StringVarP(
		&cliOptions.ResultsDir,
		"results-dir",
		"o",
		"",
		"Override directory to save Qodana inspection results to (default <userCacheDir>/JetBrains/<linter>/results)",
	)
	flags.StringVarP(
		&cliOptions.ReportDir,
		"report-dir",
		"r",
		"",
		"Override directory to save Qodana HTML report to (default <userCacheDir>/JetBrains/<linter>/results/report)",
	)
	flags.IntVarP(&cliOptions.Port, "port", "p", 8080, "Specify port to serve report at")
	flags.BoolVarP(&cliOptions.OpenDir, "dir-only", "d", false, "Open report directory only, don't serve it")
	flags.StringVar(
		&cliOptions.ConfigName,
		"config",
		"",
		"Set a custom configuration file instead of 'qodana.yaml'. Relative paths in the configuration will be based on the project directory.",
	)
	return cmd
}