<commit_before>package governor

import (
	"fmt"
	"github.com/spf13/cobra"
	"os"
)

type (
	govflags struct {
		configFile string
	}
)

func (s *Server) initCommand(conf ConfigOpts) {
	rootCmd := &cobra.Command{
		Use:   conf.Appname,
		Short: conf.Description,
		Long: conf.Description + `

It is built on the governor microservice framework which handles config
management, logging, health checks, setup procedures, jobs, authentication, db,
caching, object storage, emailing, message queues and more.`,
		Version: conf.Version + " " + conf.VersionHash,
	}

	serveCmd := &cobra.Command{
		Use:   "serve",
		Short: "starts the http server and runs all services",
		Long: `Starts the http server and runs all services

The server first runs all init procedures for all services before starting.`,
		Run: func(cmd *cobra.Command, args []string) {
			s.Start()
		},
	}

	setupCmd := &cobra.Command{
		Use:   "setup",
		Short: "runs the setup procedures for all services",
		Long: `Runs the setup procedures for all services

The server first runs all init procedures for all services before running
setup.`,
		Run: func(cmd *cobra.Command, args []string) {
			if err := s.Setup(ReqSetup{
				Username:  "",
				Password:  "",
				Email:     "",
				Firstname: "",
				Lastname:  "",
				Orgname:   "",
			}); err != nil {
				os.Exit(1)
			}
		},
	}

	rootCmd.AddCommand(serveCmd, setupCmd)

	rootCmd.PersistentFlags().StringVar(&s.flags.configFile, "config", "", fmt.Sprintf("config file (default is $XDG_CONFIG_HOME/%s/%s.yaml)", conf.Appname, conf.DefaultFile))

	s.rootCmd = rootCmd
}

// Execute runs the governor cmd
func (s *Server) Execute() {
	if err := s.rootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}<commit_msg>Add cli prompt setup<commit_after>package governor

import (
	"bufio"
	"fmt"
	"github.com/spf13/cobra"
	"os"
	"strings"
)

type (
	govflags struct {
		configFile string
	}
)

func (s *Server) initCommand(conf ConfigOpts) {
	rootCmd := &cobra.Command{
		Use:   conf.Appname,
		Short: conf.Description,
		Long: conf.Description + `

It is built on the governor microservice framework which handles config
management, logging, health checks, setup procedures, jobs, authentication, db,
caching, object storage, emailing, message queues and more.`,
		Version: conf.Version + " " + conf.VersionHash,
	}

	serveCmd := &cobra.Command{
		Use:   "serve",
		Short: "starts the http server and runs all services",
		Long: `Starts the http server and runs all services

The server first runs all init procedures for all services before starting.`,
		Run: func(cmd *cobra.Command, args []string) {
			s.Start()
		},
	}

	setupCmd := &cobra.Command{
		Use:   "setup",
		Short: "runs the setup procedures for all services",
		Long: `Runs the setup procedures for all services

The server first runs all init procedures for all services before running
setup.`,
		Run: func(cmd *cobra.Command, args []string) {
			req, err := getPromptReq()
			if err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
			if err := req.valid(); err != nil {
				fmt.Println(err)
				os.Exit(1)
			}
			if err := s.Setup(*req); err != nil {
				os.Exit(1)
			}
		},
	}

	rootCmd.AddCommand(serveCmd, setupCmd)

	rootCmd.PersistentFlags().StringVar(&s.flags.configFile, "config", "", fmt.Sprintf("config file (default is $XDG_CONFIG_HOME/%s/%s.yaml)", conf.Appname, conf.DefaultFile))

	s.rootCmd = rootCmd
}

// Execute runs the governor cmd
func (s *Server) Execute() {
	if err := s.rootCmd.Execute(); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func getPromptReq() (*ReqSetup, error) {
	reader := bufio.NewReader(os.Stdin)
	fmt.Print("Username: ")
	username, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}

	fmt.Print("Password: ")
	password, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}

	fmt.Print("Email: ")
	email, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}

	fmt.Print("First name: ")
	firstname, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}

	fmt.Print("Last name: ")
	lastname, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}

	fmt.Print("Orgname: ")
	orgname, err := reader.ReadString('\n')
	if err != nil {
		return nil, err
	}

	return &ReqSetup{
		Username:  strings.TrimSpace(username),
		Password:  strings.TrimSpace(password),
		Email:     strings.TrimSpace(email),
		Firstname: strings.TrimSpace(firstname),
		Lastname:  strings.TrimSpace(lastname),
		Orgname:   strings.TrimSpace(orgname),
	}, nil
}
{'fraction_non_alphanumeric': 0.13984168865435356, 'fraction_numerical': 0.0021987686895338612, 'mean_word_length': 3.6896907216494848, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '24943', 'n_tokens_mistral': 1686, 'n_tokens_neox': 1562, 'n_words': 445}