-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: main
Are you sure you want to change the base?
Changes from all commits
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'") | ||
| } | ||
| 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) | ||
|
Comment on lines
+81
to
+82
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. |
||
|
|
||
| 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.