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'")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth validating that repo is a valid, fully-qualified repository by calling name.NewRepository.

}
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)
Comment on lines +81 to +82

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to just use repo when it's specified, rather than appending the project name. OCI defines two things: registries and repositories; the in-between of a partially-specified repository isn't really a concept.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we really have three parts - the registry, the org and the repository? Maybe the option should be registryPath or similar to include both the registry and the org? I'd like to be able to default the repository name to the project name rather than have to specify it again in the registry path.


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