profile

package
v0.11.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProfileCmd = &cobra.Command{
	Use:   "profile",
	Short: "Manage profiles",
	Args:  cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {
		c, err := config.GetConfig()
		if err != nil {
			log.Fatal(err)
		}

		profilesList := c.Profiles

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

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

		chosenProfileId := profile.GetProfileIdFromPrompt(profilesList, c.ActiveProfileId, "Choose a profile to use or add a new one", true)

		if chosenProfileId == profile.NewProfileId {
			_, err = CreateProfile(c, nil, true)
			if err != nil {
				log.Fatal(err)
			}
			return
		}

		if chosenProfileId == "" {
			return
		}

		chosenProfile, err := c.GetProfile(chosenProfileId)
		if err != nil {
			log.Fatal(err)
		}

		c.ActiveProfileId = chosenProfile.Id

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

		util.RenderInfoMessage(fmt.Sprintf("Active profile set to: %s", chosenProfile.Name))
	},
}
View Source
var ProfileUseCmd = &cobra.Command{
	Use:   "use",
	Short: "Set the active profile",
	Args:  cobra.ExactArgs(1),
	Run: func(cmd *cobra.Command, args []string) {
		c, err := config.GetConfig()
		if err != nil {
			log.Fatal(err)
		}

		if len(args) == 0 {
			log.Fatal("Please provide the profile name")
		}

		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{}) {
			log.Fatal("Profile does not exist: ", profileArg)
		}

		c.ActiveProfileId = chosenProfile.Id

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

		if output.FormatFlag != "" {
			output.Output = chosenProfile.Id
			return
		}

		view_util.RenderInfoMessage(fmt.Sprintf("Active profile set to %s", chosenProfile.Name))
	},
}

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