Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: typos command examples initapp use id flag #174

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ jobs:

- name: Upload binaries for Unix-like systems
if: runner.os != 'Windows'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: hyphen-${{ env.VERSION }}-${{ matrix.arch }}
path: hyphen-${{ env.VERSION }}-${{ matrix.arch }}

- name: Upload binaries for Windows
if: runner.os == 'Windows'
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: hyphen-${{ env.VERSION }}-${{ matrix.arch }}
path: artifacts/hyphen-${{ env.VERSION }}-${{ matrix.arch }}.exe
30 changes: 19 additions & 11 deletions cmd/initapp/initapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/Hyphen/cli/internal/database"
"github.com/Hyphen/cli/internal/env"
"github.com/Hyphen/cli/internal/manifest"
"github.com/Hyphen/cli/internal/projects"
"github.com/Hyphen/cli/pkg/cprint"
"github.com/Hyphen/cli/pkg/errors"
"github.com/Hyphen/cli/pkg/flags"
Expand Down Expand Up @@ -69,10 +70,22 @@ func RunInitApp(cmd *cobra.Command, args []string) {
return
}

orgID, err := flags.GetOrganizationID()
if err != nil {
printer.Error(cmd, err)
return
}
appService := app.NewService()
envService := env.NewService()
projectService := projects.NewService(orgID)

orgID, err := flags.GetOrganizationID()
projectID, err := flags.GetProjectID()
if err != nil {
printer.Error(cmd, err)
return
}

p, err := projectService.GetProject(projectID)
if err != nil {
printer.Error(cmd, err)
return
Expand Down Expand Up @@ -111,12 +124,7 @@ func RunInitApp(cmd *cobra.Command, args []string) {
return
}

if mc.ProjectId == nil {
printer.Error(cmd, fmt.Errorf("No project found in .hx file"))
return
}

newApp, err := appService.CreateApp(orgID, *mc.ProjectId, appAlternateId, appName)
newApp, err := appService.CreateApp(orgID, *p.ID, appAlternateId, appName)
if err != nil {
if !errors.Is(err, errors.ErrConflict) {
printer.Error(cmd, err)
Expand All @@ -137,9 +145,9 @@ func RunInitApp(cmd *cobra.Command, args []string) {
}

mcl := manifest.Config{
ProjectId: mc.ProjectId,
ProjectAlternateId: mc.ProjectAlternateId,
ProjectName: mc.ProjectName,
ProjectId: p.ID,
ProjectAlternateId: &p.AlternateID,
ProjectName: &p.Name,
OrganizationId: mc.OrganizationId,
AppName: &newApp.Name,
AppAlternateId: &newApp.AlternateId,
Expand Down Expand Up @@ -307,7 +315,7 @@ func CreateGitignoredFile(cmd *cobra.Command, fileName string) error {

func GetAppID(cmd *cobra.Command, appName string) string {
defaultAppAlternateId := GenerateDefaultAppId(appName)
appAlternateId := appIDFlag
appAlternateId, _ := cmd.Flags().GetString("id")
if appAlternateId == "" {
appAlternateId = defaultAppAlternateId
}
Expand Down
27 changes: 18 additions & 9 deletions cmd/initialize/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,47 @@ var printer *cprint.CPrinter

var InitCmd = &cobra.Command{
Use: "init <app name>",
Short: "Initialize a new Hyphen application in the current directory",
Short: "Initialize a new Hyphen application or monorepo project in the current directory",
Long: `
The init command sets up a new Hyphen application in your current directory.
The init command sets up a new Hyphen application or monorepo project in your current directory.

This command will:
- Create a new application in Hyphen
- Create a new application or project in Hyphen
- Generate a local configuration file
- Set up environment files for each project environment
- Update .gitignore to exclude sensitive files

If no app name is provided, it will prompt to use the current directory name.

For single applications:
The command will guide you through:
- Confirming or entering an application name
- Generating or providing an app ID
- Creating necessary local files

After initialization, you'll receive a summary of the new application, including its name,
ID, and associated organization.
For monorepos (using --monorepo flag):
The command will guide you through:
- Setting up a project structure
- Adding multiple applications within the project
- Configuring each application with its own settings
- Creating environment files for each application

After initialization, you'll receive a summary of the new application(s), including name(s),
ID(s), and associated organization.

Examples:
hyphen init
hyphen init "My New App"
hyphen init "My New App" --id my-custom-app-id
hyphen init # Initialize single app
hyphen init "My New App" # Initialize single app with name
hyphen init "My New App" --id my-custom-app-id # Initialize single app with custom ID
hyphen init --monorepo # Initialize monorepo project
hyphen init "My Project" --monorepo # Initialize monorepo with project name
`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if isMonorepo {
runInitMonorepo(cmd, args)
} else {
initapp.RunInitApp(cmd, args)

}
},
}
Expand Down
9 changes: 5 additions & 4 deletions cmd/initproject/initproject.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,16 @@ func RunInitProject(cmd *cobra.Command, args []string) {

func GetProjectID(cmd *cobra.Command, projectName string) string {
defaultProjectAlternateId := GenerateDefaultProjectId(projectName)
projectAlternateId := projectIDFlag
projectAlternateId, _ := cmd.Flags().GetString("id")

if projectAlternateId == "" {
projectAlternateId = defaultProjectAlternateId
}

err := projects.CheckProjectId(projectAlternateId)
if err != nil {
suggestedID := strings.TrimSpace(strings.Split(err.Error(), ":")[1])
response := prompt.PromptYesNo(cmd, fmt.Sprintf("Invalid app ID. Do you want to use the suggested ID [%s]?", suggestedID), true)
response := prompt.PromptYesNo(cmd, fmt.Sprintf("Invalid project ID. Do you want to use the suggested ID [%s]?", suggestedID), true)

if !response.Confirmed {
if response.IsFlag {
Expand All @@ -166,7 +167,7 @@ func GetProjectID(cmd *cobra.Command, projectName string) string {
// Prompt for a custom project ID
for {
var err error
projectAlternateId, err = prompt.PromptString(cmd, "Enter a custom app ID:")
projectAlternateId, err = prompt.PromptString(cmd, "Enter a custom project ID:")
if err != nil {
printer.Error(cmd, err)
return ""
Expand All @@ -176,7 +177,7 @@ func GetProjectID(cmd *cobra.Command, projectName string) string {
if err == nil {
return projectAlternateId
}
printer.Warning("Invalid app ID. Please try again.")
printer.Warning("Invalid project ID. Please try again.")
}
}
} else {
Expand Down
61 changes: 30 additions & 31 deletions cmd/project/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ package create
import (
"fmt"
"strings"
"unicode"

"github.com/Hyphen/cli/cmd/initproject"
"github.com/Hyphen/cli/internal/projects"
"github.com/Hyphen/cli/pkg/cprint"
"github.com/Hyphen/cli/pkg/flags"
"github.com/spf13/cobra"
)

var printer *cprint.CPrinter
var (
printer *cprint.CPrinter
isMonorepo bool
projectIDFlag string
)

var ProjectCreateCmd = &cobra.Command{
Use: "create [name]",
Expand All @@ -20,30 +24,17 @@ var ProjectCreateCmd = &cobra.Command{
The project create command sets up a new project within your Hyphen organization.

Usage:
hyphen project create [name]
hyphen project create [name] [--monorepo] [--id project-id]

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)
- Create a monorepo project using the --monorepo flag
- Specify a custom project ID using the --id flag

Example:
hyphen project create "My New Project"

This will create a project named "My New Project" with an alternate ID like "my-new-project".
hyphen project create "My Monorepo Project" --monorepo
hyphen project create "Custom ID Project" --id my-custom-id
`,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -60,33 +51,41 @@ This will create a project named "My New Project" with an alternate ID like "my-
name = strings.Trim(name, "\"")
name = strings.Trim(name, "'")

// Ensure the alternate ID is alphanumeric and replaces spaces with hyphens
alternateId := strings.Map(func(r rune) rune {
if unicode.IsLetter(r) || unicode.IsDigit(r) {
return r
} else if r == ' ' {
return '-'
}
return -1 // Strip out any other non-alphanumeric characters
}, name)
alternateId := initproject.GetProjectID(cmd, name)
if alternateId == "" {
return
}

service := projects.NewService(orgId)

// Check if project exists first
_, err = service.GetProject(alternateId)
if err == nil {
printer.Error(cmd, fmt.Errorf("project with ID '%s' already exists", alternateId))
return
}

project := projects.Project{
Name: name,
AlternateID: alternateId,
IsMonorepo: isMonorepo,
}

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

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

printer.PrintDetail("Name", newProject.Name)
printer.PrintDetail("ID", *newProject.ID)
printer.PrintDetail("AlternateID", newProject.AlternateID)
printer.PrintDetail("Monorepo", fmt.Sprintf("%t", newProject.IsMonorepo))
},
}

func init() {
ProjectCreateCmd.Flags().BoolVarP(&isMonorepo, "monorepo", "m", false, "Create the project as a monorepo")
ProjectCreateCmd.Flags().StringVarP(&projectIDFlag, "id", "i", "", "Specify a custom project ID")
}
Loading