cmd

package
v0.0.0-...-8cf2643 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AddCmd = &cobra.Command{
	Use:   "add",
	Short: "Add new component",
	Args:  cobra.MaximumNArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		root, err := cmd.Flags().GetString("root")
		if err != nil {
			color.Red("%s", err)
			return
		}

		var (
			categoryId  string
			componentId string
		)

		if len(args) > 0 {
			id := args[0]
			idSplit := strings.SplitN(id, ".", 2)
			categoryId = strings.SplitN(id, ".", 2)[0]

			if len(idSplit) > 1 {
				componentId = lo.Must(lo.Last(strings.SplitN(id, ".", 2)))
			}
		}

		if categoryId == "" {
			err := survey.AskOne(&survey.Select{
				Message: "Component Category",
				Options: components.ComponentCategoryOptions,
			}, &categoryId)
			if err != nil {
				color.Red("%s", err)
				return
			}
		}

		if componentId == "" {
			err := survey.AskOne(&survey.Select{
				Message: "Select Components",
				Options: components.ComponentMapping[categoryId],
			}, &componentId)
			if err != nil {
				color.Red("%s", err)
				return
			}
		}

		categoryId = lo.Capitalize(categoryId)
		componentId = lo.Capitalize(componentId)

		err = components.NewConfigService().Add(
			components.AddArgs{
				Component: fmt.Sprintf("%s.%s", categoryId, componentId),
				Root:      root,
			},
		)
		if err != nil {
			color.Red("%s", err)
			return
		}
	},
}
View Source
var InitCmd = &cobra.Command{
	Use:   "init",
	Short: "Initialize a new alchemy project",
	Run: func(cmd *cobra.Command, args []string) {
		var root string
		var orm string
		var databaseProvider string
		var databaseUrl string
		var provisionDatabase string

		err := survey.AskOne(&survey.Input{Message: "Provide alchemy component root: ", Default: "."}, &root)
		if err != nil {
			color.Red("%s", err)
			return
		}

		err = survey.AskOne(&survey.Select{Message: "Choose ORM: ", Options: orms.OrmOptions}, &orm)
		if err != nil {
			color.Red("%s", err)
			return
		}

		err = survey.AskOne(
			&survey.Select{
				Message: "Choose Database Provider: ",
				Options: orms.OrmMappings[orm],
			}, &databaseProvider,
		)
		if err != nil {
			color.Red("%s", err)
			return
		}

		err = survey.AskOne(
			&survey.Select{
				Message: "Provision Database with Docker Compose: ",
				Options: []string{"Yes", "No"},
				Default: "Yes",
			},
			&provisionDatabase,
		)
		if err != nil {
			color.Red("%s", err)
			return
		}

		if strings.ToLower(provisionDatabase) == "no" {
			err = survey.AskOne(&survey.Input{Message: "Provide database url: "}, &databaseUrl)
			if err != nil {
				color.Red("%s", err)
				return
			}
		}

		err = components.NewConfigService().Init(components.InitArgs{
			Root:                  root,
			Orm:                   orm,
			ShouldProvideDatabase: strings.ToLower(provisionDatabase) == "yes",
			DatabaseUrl:           databaseUrl,
			DatabaseProvider:      databaseProvider,
		})
		if err != nil {
			color.Red("%s", err)
			return
		}
	},
}
View Source
var RemoveCmd = &cobra.Command{
	Use:   "remove",
	Short: "Add new component",
	Args:  cobra.ExactArgs(1),
	Run:   func(cmd *cobra.Command, args []string) {},
}
View Source
var RootCmd = &cobra.Command{
	Use:   "go-alchemy",
	Short: "Golang Alchemy CLI",
}
View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Print the version info",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Printf("Version: %s\nCommit: %s\nBuild Date: %s\n", version, commit, buildDate)
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳