Skip to content
11 changes: 6 additions & 5 deletions cmd/crossplane/project/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ import (
//go:embed help/build.md
var buildHelp string

// buildCmd builds a project into Crossplane packages.
type buildCmd struct {
// BuildCmd builds a project into Crossplane packages.
type BuildCmd struct {
ProjectFile string `default:"${project_file}" help:"Path to project definition." short:"f"`
Repository string `help:"Override the repository in the project file." optional:""`
OutputDir string `default:"_output" help:"Output directory for packages." short:"o"`
Expand All @@ -64,12 +64,13 @@ type buildCmd struct {
projFS afero.Fs
}

func (c *buildCmd) Help() string {
// Help returns help for the build command.
func (c *BuildCmd) Help() string {
return buildHelp
}

// AfterApply parses flags and reads the project file.
func (c *buildCmd) AfterApply() error {
func (c *BuildCmd) AfterApply() error {
projFilePath, err := filepath.Abs(c.ProjectFile)
if err != nil {
return err
Expand All @@ -88,7 +89,7 @@ func (c *buildCmd) AfterApply() error {
}

// Run executes the build command.
func (c *buildCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter, cfg *config.Config) error {
func (c *BuildCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter, cfg *config.Config) error {
ctx := context.Background()

if c.Repository != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/crossplane/project/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ spec:
sp := terminal.NewSpinnerPrinter(io.Discard, false)
cfg := &config.Config{}

c := &buildCmd{ProjectFile: projectFile, CacheDir: filepath.Join(dir, "cache"), GitToken: token, GitUsername: "test-user", MaxConcurrency: 1}
c := &BuildCmd{ProjectFile: projectFile, CacheDir: filepath.Join(dir, "cache"), GitToken: token, GitUsername: "test-user", MaxConcurrency: 1}
if err := c.AfterApply(); err != nil {
t.Fatal(err)
}
Expand Down
12 changes: 7 additions & 5 deletions cmd/crossplane/project/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ import (
//go:embed help/init.md
var initHelp string

// initCmd initializes a new project.
type initCmd struct {
// 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"`
Registry string `default:"example.com/my-org" help:"Override the registry in the project file." optional:"" short:"r"`
Repository string `help:"Override the repository name in the project file. Defaults to the project name." optional:""`
}

func (c *initCmd) Help() string {
// Help returns help for the init command.
func (c *InitCmd) Help() string {
return initHelp
}

func (c *initCmd) Run(sp terminal.SpinnerPrinter) error {
// Run executes the init command.
func (c *InitCmd) Run(sp terminal.SpinnerPrinter) error {
// Validate the project name is a valid DNS-1035 label.
if errs := validation.IsDNS1035Label(c.Name); len(errs) > 0 {
return errors.Errorf("'%s' is not a valid project name. DNS-1035 constraints: %s", c.Name, strings.Join(errs, "; "))
Expand Down Expand Up @@ -112,7 +114,7 @@ spec:
})
}

func (c *initCmd) checkTargetDirectory() error {
func (c *InitCmd) checkTargetDirectory() error {
f, err := os.Stat(c.Directory)
switch {
case os.IsNotExist(err):
Expand Down
12 changes: 6 additions & 6 deletions cmd/crossplane/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ package project

// Cmd contains project subcommands.
type Cmd struct {
Init initCmd `cmd:"" help:"Initialize a new project."`
Build buildCmd `cmd:"" help:"Build a project into Crossplane packages."`
Push pushCmd `cmd:"" help:"Push a built project to an OCI registry."`
Run runCmd `cmd:"" help:"Build and run a project in a local dev control plane." novale:"Google.WordList[\"admin\"]"`
Simulate simulateCmd `cmd:"" help:"Preview how a project's Compositions would change a cluster's composite resources." maturity:"alpha"`
Stop stopCmd `cmd:"" help:"Tear down a local dev control plane."`
Init InitCmd `cmd:"" help:"Initialize a new project."`
Build BuildCmd `cmd:"" help:"Build a project into Crossplane packages."`
Push PushCmd `cmd:"" help:"Push a built project to an OCI registry."`
Run RunCmd `cmd:"" help:"Build and run a project in a local dev control plane." novale:"Google.WordList[\"admin\"]"`
Simulate SimulateCmd `cmd:"" help:"Preview how a project's Compositions would change a cluster's composite resources." maturity:"alpha"`
Stop StopCmd `cmd:"" help:"Tear down a local dev control plane."`
}
13 changes: 7 additions & 6 deletions cmd/crossplane/project/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import (
//go:embed help/push.md
var pushHelp string

// pushCmd pushes a built project to an OCI registry.
type pushCmd struct {
// PushCmd pushes a built project to an OCI registry.
type PushCmd struct {
ProjectFile string `default:"${project_file}" help:"Path to project definition." short:"f"`
Repository string `help:"Override the repository in the project file." optional:""`
Tag string `default:"" help:"Tag for the pushed package. Defaults to a time-based semver-like tag." short:"t"`
Expand All @@ -60,13 +60,14 @@ type pushCmd struct {
transport http.RoundTripper
}

func (c *pushCmd) Help() string {
// Help returns help for the push command.
func (c *PushCmd) Help() string {
return pushHelp
}

// AfterApply parses flags, reads the project file, and prepares the push
// runtime (filesystem views and HTTP transport).
func (c *pushCmd) AfterApply() error {
func (c *PushCmd) AfterApply() error {
projFilePath, err := filepath.Abs(c.ProjectFile)
if err != nil {
return err
Expand Down Expand Up @@ -102,7 +103,7 @@ func (c *pushCmd) AfterApply() error {
}

// Run executes the push command.
func (c *pushCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter) error {
func (c *PushCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter) error {
ctx := context.Background()

if c.Repository != "" {
Expand Down Expand Up @@ -154,7 +155,7 @@ func (c *pushCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter) error {
return nil
}

func (c *pushCmd) loadPackages() (project.ImageTagMap, error) {
func (c *PushCmd) loadPackages() (project.ImageTagMap, error) {
opener := func() (io.ReadCloser, error) {
return c.packageFS.Open(c.PackageFile)
}
Expand Down
11 changes: 6 additions & 5 deletions cmd/crossplane/project/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ import (
//go:embed help/run.md
var runHelp string

// runCmd builds a project and runs it in a local dev control plane.
type runCmd struct {
// RunCmd builds a project and runs it in a local dev control plane.
type RunCmd struct {
ProjectFile string `default:"${project_file}" help:"Path to project definition." short:"f"`
Repository string `help:"Override the repository." optional:""`
MaxConcurrency uint `default:"8" help:"Max concurrent builds."`
Expand All @@ -83,12 +83,13 @@ type runCmd struct {
extraResources []runtime.RawExtension
}

func (c *runCmd) Help() string {
// Help returns help for the run command.
func (c *RunCmd) Help() string {
return runHelp
}

// AfterApply parses flags and reads the project file.
func (c *runCmd) AfterApply() error {
func (c *RunCmd) AfterApply() error {
projFilePath, err := filepath.Abs(c.ProjectFile)
if err != nil {
return err
Expand Down Expand Up @@ -134,7 +135,7 @@ func (c *runCmd) AfterApply() error {
}

// Run executes the run command.
func (c *runCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter, cfg *config.Config) error { //nolint:gocyclo // Main command orchestration.
func (c *RunCmd) Run(logger logging.Logger, sp terminal.SpinnerPrinter, cfg *config.Config) error { //nolint:gocyclo // Main command orchestration.
ctx := context.Background()

if c.Repository != "" {
Expand Down
11 changes: 6 additions & 5 deletions cmd/crossplane/project/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,24 @@ var (
simulateExamples string
)

// simulateCmd previews how a project's compositions would change the
// SimulateCmd previews how a project's compositions would change the
// composite resources in a cluster.
type simulateCmd struct {
type SimulateCmd struct {
simulate.Flags `embed:""`
simulate.CompositionFlags `embed:""`

MaxConcurrency uint `default:"8" help:"Max concurrent function builds."`
ProjectFile string `default:"${project_file}" help:"Path to project definition." short:"f"`
}

func (c *simulateCmd) Help() string {
// Help returns help for the simulate command.
func (c *SimulateCmd) Help() string {
return simulateHelp + simulate.Help(true) + simulateExamples
}

// Run previews the project's compositions against the cluster, with its
// functions built locally.
func (c *simulateCmd) Run(sigCtx context.Context, k *kong.Context, logger logging.Logger, sp terminal.SpinnerPrinter, cliCfg *config.Config) error {
func (c *SimulateCmd) Run(sigCtx context.Context, k *kong.Context, logger logging.Logger, sp terminal.SpinnerPrinter, cliCfg *config.Config) error {
return simulate.NewRunner(&c.Flags).Run(sigCtx, k, logger, sp, &simulate.Inputs{Build: func(ctx context.Context) (*simulate.Built, error) {
return c.buildProject(ctx, logger, sp, cliCfg)
}, Selection: &c.CompositionFlags})
Expand All @@ -71,7 +72,7 @@ func (c *simulateCmd) Run(sigCtx context.Context, k *kong.Context, logger loggin
// buildProject returns the project's compositions, its locally built
// functions, and the packages its provider dependencies resolve through.
// --image-configs, when set, replaces the project's ImageConfigs for both.
func (c *simulateCmd) buildProject(ctx context.Context, logger logging.Logger, sp terminal.SpinnerPrinter, cliCfg *config.Config) (*simulate.Built, error) {
func (c *SimulateCmd) buildProject(ctx context.Context, logger logging.Logger, sp terminal.SpinnerPrinter, cliCfg *config.Config) (*simulate.Built, error) {
projFilePath, err := filepath.Abs(c.ProjectFile)
if err != nil {
return nil, errors.Wrap(err, "cannot get absolute path of project file")
Expand Down
Loading