profile

package
v0.43.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProfileAddCmd = &cobra.Command{
	Use:     "add",
	Short:   "Add profile",
	Args:    cobra.NoArgs,
	Aliases: []string{"new"},
	RunE: func(cmd *cobra.Command, args []string) error {
		c, err := config.GetConfig()
		if err != nil {
			return err
		}

		profileAddView := profile.ProfileAddView{
			ProfileName: profileNameFlag,
			ApiUrl:      apiUrlFlag,
			ApiKey:      apiKeyFlag,
		}

		if profileAddView.ProfileName != "" && profileAddView.ApiUrl != "" && profileAddView.ApiKey != "" {
			_, err = addProfile(profileAddView, c, true)
		} else {
			_, err = CreateProfile(c, &profileAddView, true)
		}

		return err
	},
}
View Source
var ProfileCmd = &cobra.Command{
	Use:     "profile",
	Short:   "Manage profiles",
	GroupID: util.PROFILE_GROUP,
}
View Source
var ProfileUseCmd = &cobra.Command{
	Use:     "use",
	Short:   "Use profile [PROFILE_NAME]",
	Args:    cobra.MaximumNArgs(1),
	GroupID: util.PROFILE_GROUP,
	RunE: func(cmd *cobra.Command, args []string) error {
		c, err := config.GetConfig()
		if err != nil {
			return err
		}

		if len(args) == 0 {
			profilesList := c.Profiles

			if len(profilesList) == 0 {
				views.RenderInfoMessage("Add a profile by running `daytona profile add`")
				return nil
			}

			if len(profilesList) == 1 {
				views.RenderInfoMessage(fmt.Sprintf("You are using profile %s. Add a new profile by running `daytona profile add`", profilesList[0].Name))
				return nil
			}

			chosenProfile, err := profile.GetProfileFromPrompt(profilesList, c.ActiveProfileId, true)
			if err != nil {
				return err
			}

			if chosenProfile == nil {
				return nil
			}

			if chosenProfile.Id == profile.NewProfileId {
				_, err = CreateProfile(c, nil, true)
				return err
			}

			if chosenProfile.Id == "" {
				return nil
			}

			profile, err := c.GetProfile(chosenProfile.Id)
			if err != nil {
				return err
			}

			c.ActiveProfileId = profile.Id

			err = c.Save()
			if err != nil {
				return err
			}

			views.RenderInfoMessage(fmt.Sprintf("Active profile set to: %s", profile.Name))
		} else {
			profileArg := args[0]

			var chosenProfile config.Profile

			for _, profile := range c.Profiles {
				if profile.Name == profileArg || profile.Id == profileArg {
					chosenProfile = profile
					break
				}
			}

			if chosenProfile == (config.Profile{}) {
				return fmt.Errorf("profile does not exist: %s", profileArg)
			}

			c.ActiveProfileId = chosenProfile.Id

			err = c.Save()
			if err != nil {
				return err
			}

			views.RenderInfoMessage(fmt.Sprintf("Active profile set to: %s", chosenProfile.Name))
		}
		return nil
	},
}

Functions

func CreateProfile

func CreateProfile(c *config.Config, profileAddView *profile.ProfileAddView, notify bool) (string, error)

func EditProfile

func EditProfile(c *config.Config, notify bool, profileToEdit *config.Profile) error

Types

This section is empty.

Jump to

Keyboard shortcuts

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