init

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var InitCmd = &cobra.Command{
	Use:   "init",
	Short: "init setups package management for the project",
	Long: `init setups package management for the project. It setups Nix files based on the language detected.
	`,

	PreRun: func(cmd *cobra.Command, args []string) {
		precheck.AllPrechecks()
	},

	Run: func(cmd *cobra.Command, args []string) {
		conf, err := configure.PreCheckConf()
		if err != nil {
			fmt.Println(styles.ErrorStyle.Render("error:", err.Error()))
			os.Exit(1)
		}

		isBaseImage, err := YesNoPrompt("Do you want to build a base image?")
		if err != nil {
			fmt.Println(styles.ErrorStyle.Render("error:", err.Error()))
			os.Exit(1)
		}

		var imageName string
		var pt langdetect.ProjectType
		var includeCommonDeps bool
		var commonDeps string

		if isBaseImage {
			imageName, err = IoPrompt("What should the image name be?")
			if err != nil {
				fmt.Println(styles.ErrorStyle.Render("error:", err.Error()))
				os.Exit(1)
			}

			includeCommonDeps, err = YesNoPrompt("Would you like to add common dependencies (compiler, linter, debugger, etc.)?")
			if err != nil {
				fmt.Println(styles.ErrorStyle.Render("error:", err.Error()))
				os.Exit(1)
			}

			if includeCommonDeps {
				commonDeps, err = IoPrompt("Which common deps would you like to add? (Go/Python/Rust/JsNpm)")
				if err != nil {
					fmt.Println(styles.ErrorStyle.Render("error:", err.Error()))
					os.Exit(1)
				}
			}
		}

		sc, err := search.NewClientWithAddr(conf.BuildSafeAPI, conf.BuildSafeAPITLS)
		if err != nil {
			fmt.Println(styles.ErrorStyle.Render("error:", err.Error()))
			os.Exit(1)
		}

		m := model{sc: sc, pt: pt, baseImgName: imageName, addCommonDeps: includeCommonDeps, commonDepsType: commonDeps}
		m.resetSpinner()
		if _, err := tea.NewProgram(m).Run(); err != nil {
			os.Exit(1)
		}
	},
}

InitCmd represents the init command

Functions

func GetBSFInitializers

func GetBSFInitializers() (bsfv1.SearchServiceClient, *hcl2nix.FileHandlers, error)

GetBSFInitializers generates the nix files

func IoPrompt added in v0.2.2

func IoPrompt(label string) (string, error)

IoPrompt is used to promt a user for a string based answer

func YesNoPrompt added in v0.2.2

func YesNoPrompt(label string) (bool, error)

YesNoPrompt is used to promt a user for a bool based answer

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL