-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BUILD-206: added BuildRun, resource accepts context
New Subcommands for working with BuildRun Created via 'build run' Can be deleted, listed and view logs Resource objects now support context passed from cobra commands SubCommand Run method now accepts IoStreams for information output Other minor changes, including README
- Loading branch information
Alice Rum
committed
Apr 7, 2021
1 parent
47e2250
commit 863e038
Showing
29 changed files
with
607 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// build contains types and functions for build cobra sub-command | ||
package build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package build | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
buildv1alpha1 "github.com/shipwright-io/build/pkg/apis/build/v1alpha1" | ||
"github.com/spf13/cobra" | ||
|
||
"k8s.io/cli-runtime/pkg/genericclioptions" | ||
|
||
"github.com/shipwright-io/cli/pkg/shp/cmd/buildrun" | ||
"github.com/shipwright-io/cli/pkg/shp/cmd/runner" | ||
"github.com/shipwright-io/cli/pkg/shp/params" | ||
"github.com/shipwright-io/cli/pkg/shp/resource" | ||
) | ||
|
||
// RunCommand contains data input from user for run sub-command | ||
type RunCommand struct { | ||
cmd *cobra.Command | ||
|
||
buildName string | ||
} | ||
|
||
// Cmd returns cobra command object | ||
func (c *RunCommand) Cmd() *cobra.Command { | ||
return c.cmd | ||
} | ||
|
||
func runCmd() runner.SubCommand { | ||
runCommand := &RunCommand{ | ||
cmd: &cobra.Command{ | ||
Use: "run <name>", | ||
Short: "Start a build specified by 'name'", | ||
Args: cobra.ExactArgs(1), | ||
}, | ||
} | ||
|
||
return runCommand | ||
} | ||
|
||
// Complete fills in data provided by user | ||
func (c *RunCommand) Complete(params *params.Params, args []string) error { | ||
if len(args) < 1 { | ||
return errors.New("'name' argument is empty") | ||
} | ||
|
||
c.buildName = args[0] | ||
|
||
return nil | ||
} | ||
|
||
// Validate validates data input by user | ||
func (c *RunCommand) Validate() error { | ||
return nil | ||
} | ||
|
||
// Run executes run sub-command logic | ||
func (c *RunCommand) Run(params *params.Params, ioStreams *genericclioptions.IOStreams) error { | ||
br := resource.GetBuildResource(params) | ||
brr := resource.GetBuildRunResource(params) | ||
|
||
var build buildv1alpha1.Build | ||
if err := br.Get(c.cmd.Context(), c.buildName, &build); err != nil { | ||
return err | ||
} | ||
|
||
buildRun := buildrun.NewBuildRun(&build, build.Name) | ||
|
||
if err := brr.Create(c.cmd.Context(), "", buildRun); err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(ioStreams.Out, "BuildRun created %q\n", buildRun.Name) | ||
return nil | ||
} |
Oops, something went wrong.