cmd

package
v1.0.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const Version string = "v1.0.3"

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "kayveedb-cli",
	Short: "CLI to interact with KayveeDB server",
	PersistentPreRun: func(cmd *cobra.Command, args []string) {

		dsn := os.Getenv("DB_DSN")
		if dsn != "" {
			parseDSN(dsn)
		} else {

			username = getEnvOrDefault("USERNAME", username)
			password = getEnvOrDefault("PASSWORD", password)
			database = getEnvOrDefault("DB_NAME", database)
			hostname = getEnvOrDefault("DB_HOST", hostname)
			port = getEnvOrDefault("DB_PORT", port)

			if username == "" {
				fmt.Print("username: ")
				fmt.Scanln(&username)
			}
			if database == "" {
				fmt.Print("database: ")
				fmt.Scanln(&database)
			}
			if password == "" {
				fmt.Printf("%s's password: ", username)
				bytePassword, err := term.ReadPassword(0)
				if err != nil {
					log.Fatal("Failed to read password")
				}
				password = string(bytePassword)
				fmt.Println()
			}
		}

		realClient := client.NewClient()

		err := realClient.Authenticate(username, password, database, hostname, port)
		if err != nil {
			log.Fatalf("Failed to login: %v", err)
		}
	},
}

RootCmd is the base command for the CLI.

View Source
var VersionCmd = &cobra.Command{
	Use:   "version",
	Short: "Display the version of kvdbcli",
	Run: func(cmd *cobra.Command, args []string) {
		fmt.Printf("kvdbcli version: %s\n", Version)
	},
}

Functions

func DeleteCmd

func DeleteCmd(c client.ClientInterface) *cobra.Command

func Execute

func Execute()

Execute runs the root command and its subcommands.

func InsertCmd

func InsertCmd(c client.ClientInterface) *cobra.Command

func LoginCmd

func LoginCmd(c client.ClientInterface) *cobra.Command

func ReadCmd

func ReadCmd(c client.ClientInterface) *cobra.Command

func UpdateCmd

func UpdateCmd(c client.ClientInterface) *cobra.Command

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 🇻🇳