create

package
v0.22.3 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ProjectCreateCmd = &cobra.Command{
	Use:   "create [name]",
	Short: "Create a new project in your organization",
	Long: `
The project create command sets up a new project within your Hyphen organization.

Usage:
  hyphen project create [name]

This command allows you to:
- Create a new project with a specified name
- Automatically generate an alternate ID based on the project name

The project name:
- Can include spaces and special characters
- Will be trimmed of leading/trailing spaces and quotes

The alternate ID:
- Is automatically generated from the project name
- Contains only alphanumeric characters and hyphens
- Replaces spaces with hyphens and removes other special characters

After creation, you'll receive a summary of the new project, including its:
- Name
- ID (assigned by Hyphen)
- Alternate ID (generated from the name)

Example:
  hyphen project create "My New Project"

This will create a project named "My New Project" with an alternate ID like "my-new-project".
`,
	Args: cobra.ExactArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		printer = cprint.NewCPrinter(flags.VerboseFlag)

		orgId, err := flags.GetOrganizationID()
		if err != nil {
			return fmt.Errorf("failed to get organization ID: %w", err)
		}

		rawName := args[0]
		name := strings.TrimSpace(rawName)
		name = strings.Trim(name, "\"")
		name = strings.Trim(name, "'")

		alternateId := strings.Map(func(r rune) rune {
			if unicode.IsLetter(r) || unicode.IsDigit(r) {
				return r
			} else if r == ' ' {
				return '-'
			}
			return -1
		}, name)

		service := projects.NewService(orgId)
		project := models.Project{
			Name:        name,
			AlternateID: alternateId,
		}

		newProject, err := service.CreateProject(project)
		if err != nil {
			return fmt.Errorf("failed to create project: %w", err)
		}

		printer.GreenPrint(fmt.Sprintf("Project '%s' created successfully!", name))

		printer.PrintDetail("Name", newProject.Name)
		printer.PrintDetail("ID", *newProject.ID)
		printer.PrintDetail("AlternateID", newProject.AlternateID)
		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