create

package
v0.12.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 7 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),
	Run: func(cmd *cobra.Command, args []string) {
		orgId, err := flags.GetOrganizationID()
		if err != nil {
			cprint.Error(cmd, fmt.Errorf("failed to get organization ID: %w", err))
			return
		}

		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 := projects.Project{
			Name:        name,
			AlternateID: alternateId,
		}

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

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

		cprint.PrintDetail("Name", newProject.Name)
		cprint.PrintDetail("ID", *newProject.ID)
		cprint.PrintDetail("AlternateID", newProject.AlternateID)
	},
}

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