func newContributorsCommand()

in internal/cmd/contributors.go [35:89]


func newContributorsCommand() *cobra.Command {
	options := &contributorsOptions{}
	cmd := &cobra.Command{
		Use:   "contributors",
		Short: "Calculate active project contributors",
		Long: fmt.Sprintf(
			`
A command-line helper for Qodana pricing[1] to calculate active contributor(s)[2] in the given local repositories.

[1] More information about available Qodana plans can be found at %s
`, core.PricingUrl,
		),
		Run: func(cmd *cobra.Command, args []string) {
			if len(options.ProjectDirs) == 0 {
				options.ProjectDirs = append(options.ProjectDirs, ".")
			}
			contributors := core.GetContributors(options.ProjectDirs, options.Days, false)
			switch options.Output {
			case "tabular":
				core.PrintContributorsTable(contributors, options.Days, len(options.ProjectDirs))
				return
			case "json":
				out, err := core.ToJSON(contributors)
				if err != nil {
					log.Fatalf("Failed to convert to JSON: %s", err)
				}
				_, err = fmt.Fprintln(cmd.OutOrStdout(), out)
				if err != nil {
					log.Fatalf("Failed to write to stdout: %s", err)
				}
				return
			default:
				log.Fatalf("Unknown output format: %s", options.Output)
			}
		},
	}
	flags := cmd.Flags()
	flags.StringArrayVarP(
		&options.ProjectDirs,
		"project-dir",
		"i",
		[]string{},
		"Project directory, can be specified multiple times to check multiple projects, if not specified, current directory will be used",
	)
	flags.IntVarP(
		&options.Days,
		"days",
		"d",
		90,
		"Number of days since when to calculate the number of active contributors",
	)
	flags.StringVarP(&options.Output, "output", "o", "tabular", "Output format, can be tabular or json")

	return cmd
}