knative/func

Allow Initializing in Nonempty Directories

lkingland opened this issue · 1 comments

Currently func [init|create] will error if there are any files in the target directory.

This was a stop-gap measure, since a common pattern would be to first create a git repository, a README, perhaps add some other files, and then run func init [language].

In order to support this very likely workflow, it would be very nice if we could do a pre-apply of the template chosen, tallying up a list of all the files that would be overwritten to give the user a clear error message.

When in Noninteractive Mode (no --confirm):
If there already exists a func.yaml file, the error message would state as such before listing the files and directories
that should be moved or be overwritten with --force:

$ func init go
Target location contains an initialized function.  Use --force to continue, which will overwrite the following files:
func.yaml
handle.go
handle_test.go

If the directory does not contain an initialized function (no func.yaml), the output would be almost identical, just with a slightly differently worded warning:

$ func init go
The target location has files which will be overwritten. Use --force to overwrite the following files:
handle.go
handle_test.go
README.md

When in interactive mode (--confirm), it would use a two-step prompt. Something akin to:

$ func init go --confirm
Target location contains an initialized function.  Continue? (y/N):  y
Choose which files to overwrite? (Choosing 'no' will overwrite all) (Y/n):
Overwrite 'handle.go'? (Y/n)
Overwrite 'handle_test.go'? (Y/n)
Overwrite 'README.md'? (Y/n)

Nuances:

The output enumerating the files to be overwritten need not recursively list everything in .func.
For simplicity's sake, we may want to start by being nonrecursive in general
The --force flag is not something that should be either persisted between runs or be globally configurable
Note how the --confirm mode defaults are to not overwrite an existing function, but if the user does chose to do so, the rest of the defaults are to overwrite.

This issue is stale because it has been open for 90 days with no
activity. It will automatically close after 30 more days of
inactivity. Reopen the issue with /reopen. Mark the issue as
fresh by adding the comment /remove-lifecycle stale.