-
Notifications
You must be signed in to change notification settings - Fork 18
Add repository option to crossplane project init
#105
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
Changes from 3 commits
18ca466
92b63fa
4675ae8
81a8e27
d853516
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 { | ||
|
|
@@ -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'") | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| 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) | ||
|
|
@@ -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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer to just use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The first component of the repository being an organization name is just a convention, not specified by OCI. That said, it is a very common convention - every public registry I can think of follows it (GHCR, Docker Hub, Upbound marketplace, etc.). Agreed it's a nice UX to not require repeating the project name. I think making the argument |
||
|
|
||
| if err := os.WriteFile(projFile, []byte(content), 0o600); err != nil { | ||
| return errors.Wrapf(err, "failed to write %s", projectFileName) | ||
|
|
||
There was a problem hiding this comment.
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
repois a valid, fully-qualified repository by callingname.NewRepository.