From 67c4161d0194aca379751c9b61261d1fa2ac2e1b Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Tue, 31 May 2022 11:46:34 -0400 Subject: [PATCH 1/2] build: Imply current import path --- pkg/commands/build.go | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/pkg/commands/build.go b/pkg/commands/build.go index dd6b0b33f7..5284761364 100644 --- a/pkg/commands/build.go +++ b/pkg/commands/build.go @@ -32,36 +32,39 @@ func addBuild(topLevel *cobra.Command) { Long: `This sub-command builds the provided import paths into Go binaries, containerizes them, and publishes them.`, Aliases: []string{"publish"}, Example: ` - # Build and publish import path references to a Docker - # Registry as: + # Build and publish import path references to a Docker Registry as: # ${KO_DOCKER_REPO}/- - # When KO_DOCKER_REPO is ko.local, it is the same as if - # --local and --preserve-import-paths were passed. + # When KO_DOCKER_REPO is ko.local, it is the same as if --local and + # --preserve-import-paths were passed. + # If the import path is not provided, the current working directory is the + # default. ko build github.com/foo/bar/cmd/baz github.com/foo/bar/cmd/blah # Build and publish a relative import path as: # ${KO_DOCKER_REPO}/- - # When KO_DOCKER_REPO is ko.local, it is the same as if - # --local and --preserve-import-paths were passed. + # When KO_DOCKER_REPO is ko.local, it is the same as if --local and + # --preserve-import-paths were passed. ko build ./cmd/blah # Build and publish a relative import path as: # ${KO_DOCKER_REPO}/ - # When KO_DOCKER_REPO is ko.local, it is the same as if - # --local was passed. + # When KO_DOCKER_REPO is ko.local, it is the same as if --local was passed. ko build --preserve-import-paths ./cmd/blah - # Build and publish import path references to a Docker - # daemon as: + # Build and publish import path references to a Docker daemon as: # ko.local/ # This always preserves import paths. ko build --local github.com/foo/bar/cmd/baz github.com/foo/bar/cmd/blah`, - Args: cobra.MinimumNArgs(1), RunE: func(cmd *cobra.Command, args []string) error { if err := options.Validate(po, bo); err != nil { return fmt.Errorf("validating options: %w", err) } + if len(args) == 0 { + // Build the current directory by default. + args = []string{"."} + } + ctx := cmd.Context() bo.InsecureRegistry = po.InsecureRegistry From 1be83e035492c8432969d7bc180862c5a7b908a0 Mon Sep 17 00:00:00 2001 From: Jason Hall Date: Tue, 31 May 2022 12:01:12 -0400 Subject: [PATCH 2/2] update generated docs --- doc/ko_build.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/doc/ko_build.md b/doc/ko_build.md index a31ed2a2c2..d9bd788fe7 100644 --- a/doc/ko_build.md +++ b/doc/ko_build.md @@ -14,27 +14,26 @@ ko build IMPORTPATH... [flags] ``` - # Build and publish import path references to a Docker - # Registry as: + # Build and publish import path references to a Docker Registry as: # ${KO_DOCKER_REPO}/- - # When KO_DOCKER_REPO is ko.local, it is the same as if - # --local and --preserve-import-paths were passed. + # When KO_DOCKER_REPO is ko.local, it is the same as if --local and + # --preserve-import-paths were passed. + # If the import path is not provided, the current working directory is the + # default. ko build github.com/foo/bar/cmd/baz github.com/foo/bar/cmd/blah # Build and publish a relative import path as: # ${KO_DOCKER_REPO}/- - # When KO_DOCKER_REPO is ko.local, it is the same as if - # --local and --preserve-import-paths were passed. + # When KO_DOCKER_REPO is ko.local, it is the same as if --local and + # --preserve-import-paths were passed. ko build ./cmd/blah # Build and publish a relative import path as: # ${KO_DOCKER_REPO}/ - # When KO_DOCKER_REPO is ko.local, it is the same as if - # --local was passed. + # When KO_DOCKER_REPO is ko.local, it is the same as if --local was passed. ko build --preserve-import-paths ./cmd/blah - # Build and publish import path references to a Docker - # daemon as: + # Build and publish import path references to a Docker daemon as: # ko.local/ # This always preserves import paths. ko build --local github.com/foo/bar/cmd/baz github.com/foo/bar/cmd/blah