setorg

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SetOrgCmd = &cobra.Command{
	Use:   "set-org <id>",
	Short: "Set the organization ID",
	Long:  `Set the organization ID for the Hyphen CLI to use.`,
	Args:  cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		printer = cprint.NewCPrinter(flags.VerboseFlag)
		orgID := args[0]
		var err error

		projectService := projects.NewService(orgID)
		projectList, err := projectService.ListProjects()
		if err != nil {
			return err
		}
		if len(projectList) == 0 {
			return fmt.Errorf("no projects found")
		}
		defaultProject := projectList[0]

		if globalFlag {
			err = config.UpsertGlobalOrganizationID(orgID)
		} else {
			err = config.UpsertOrganizationID(orgID)
		}
		if err != nil {
			return fmt.Errorf("failed to update organization ID: %w", err)
		}

		if globalFlag {
			err = config.UpsertGlobalProjectID(*defaultProject.ID)
		} else {
			err = config.UpsertProjectID(*defaultProject.ID)
		}
		if err != nil {
			return fmt.Errorf("failed to update project ID: %w", err)
		}

		printOrgUpdateSuccess(orgID, globalFlag)
		return nil
	},
}

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