Skip to content
Open
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
13 changes: 9 additions & 4 deletions cmd/crossplane/project/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ const projectFileName = "crossplane-project.yaml"

// initCmd initializes a new project.
type initCmd struct {
Name string `arg:"" help:"The name of the new project."`
Directory string `help:"Directory to initialize. Defaults to project name." short:"d" type:"path"`
Name string `arg:"" help:"The name of the new project."`
Directory string `help:"Directory to initialize. Defaults to project name." short:"d" type:"path"`
Repository string `default:"example.com/my-org" help:"Override the repository in the project file." optional:"" short:"r"`
}

func (c *initCmd) Help() string {
Expand All @@ -61,6 +62,10 @@ func (c *initCmd) Run(sp terminal.SpinnerPrinter) error {
return err
}

repo := strings.TrimRight(strings.TrimSpace(c.Repository), "/")
if repo == "" {
return errors.New("repository cannot be empty; set --repository to an OCI repository prefix like 'xpkg.crossplane.io/my-org'")
}
return sp.WrapWithSuccessSpinner("Initializing project", func() error {
if err := os.MkdirAll(c.Directory, 0o750); err != nil {
return errors.Wrapf(err, "failed to create directory %s", c.Directory)
Expand All @@ -73,8 +78,8 @@ kind: Project
metadata:
name: %s
spec:
repository: example.com/my-org/%s
`, c.Name, c.Name)
repository: %s/%s
`, c.Name, repo, c.Name)

if err := os.WriteFile(projFile, []byte(content), 0o600); err != nil {
return errors.Wrapf(err, "failed to write %s", projectFileName)
Expand Down
Loading