func NewExporterCommand()

in cmd/exporter/app/server.go [37:83]


func NewExporterCommand(stopChan <-chan struct{}) *cobra.Command {

	s, err := options.NewExporterOptions()
	if err != nil {
		klog.Fatalf("unable to initialize command options: %v", err)
	}

	cmd := &cobra.Command{
		Use:  "carbon-data-exporter",
		Long: `The carbon-data-exporter is a controller that pulls carbon intensity data from GSF API server`,
		Run: func(cmd *cobra.Command, args []string) {
			var err error
			var c *exporterconfig.Config
			verflag.PrintAndExitIfRequested()

			c, err = s.Config()
			if err != nil {
				klog.Fatalf("unable to initialize command configs: %s", err.Error())
			}
			if err := Run(c.Complete(), stopChan); err != nil {
				klog.Fatalf("unable to execute command : %s", err.Error())
			}
		},
	}

	fs := cmd.Flags()
	namedFlagSets := s.Flags()
	verflag.AddFlags(namedFlagSets.FlagSet("global"))
	globalflag.AddGlobalFlags(namedFlagSets.FlagSet("global"), cmd.Name())

	for _, f := range namedFlagSets.FlagSets {
		fs.AddFlagSet(f)
	}
	usageFmt := "Usage:\n  %s\n"
	cols, _, _ := term.TerminalSize(cmd.OutOrStdout())
	cmd.SetUsageFunc(func(cmd *cobra.Command) error {
		fmt.Fprintf(cmd.OutOrStderr(), usageFmt, cmd.UseLine())
		cliflag.PrintSections(cmd.OutOrStderr(), namedFlagSets, cols)
		return nil
	})
	cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
		fmt.Fprintf(cmd.OutOrStdout(), "%s\n\n"+usageFmt, cmd.Long, cmd.UseLine())
		cliflag.PrintSections(cmd.OutOrStdout(), namedFlagSets, cols)
	})

	return cmd
}