Skip to content

Conversation

fanminshi
Copy link
Contributor

@fanminshi fanminshi commented Mar 9, 2018

fixes #82

@fanminshi
Copy link
Contributor Author

Manual test:

$ operator-sdk new memcached-operator --api-version=cache.example.com/v1alpha1 --kind=Memcached
Create memcached-operator/cmd/memcached-operator/main.go
Create memcached-operator/config/config.yaml
Create memcached-operator/deploy/rbac.yaml
Create memcached-operator/pkg/apis/cache/v1alpha1/doc.go
Create memcached-operator/pkg/apis/cache/v1alpha1/register.go
Create memcached-operator/pkg/apis/cache/v1alpha1/types.go
Create memcached-operator/pkg/stub/handler.go
Create memcached-operator/tmp/build/build.sh
Create memcached-operator/tmp/build/docker_build.sh
Create memcached-operator/tmp/build/Dockerfile
Create memcached-operator/tmp/codegen/boilerplate.go.txt
Create memcached-operator/tmp/codegen/update-generated.sh
Create memcached-operator/Gopkg.toml
Create memcached-operator/Gopkg.lock
Run dep ensure ...
Run dep ensure done

@fanminshi
Copy link
Contributor Author

cc/ @hasbro17

if err := ioutil.WriteFile(tp, buf.Bytes(), defaultFileMode); err != nil {
return err
}
fmt.Printf("Create %v \n", tp)
Copy link
Contributor

@hasbro17 hasbro17 Mar 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding a fmt.Printf() after every write could be hard to maintain if we add new files to generate. Or want to change the print message. How about making it a helper function in generator.go:

func writeFileAndPrint(filePath string, data []byte, fileMode os.FileMode) error {
	if err := ioutil.WriteFile(filePath, data, fileMode); err != nil {
		return err
	}
	fmt.Printf("Create %v \n", hp)
        return nil
}

And then just call it

if err := writeFileAndPrint(filepath.Join(g.projectName, gopkgtoml), buf.Bytes(), defaultFileMode) err != nil {
        return err
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, that's better.

@fanminshi
Copy link
Contributor Author

Latest test:

$ operator-sdk new memcached-operator --api-version=cache.example.com/v1alpha1 --kind=Memcached
Create memcached-operator/cmd/memcached-operator/main.go
Create memcached-operator/config/config.yaml
Create memcached-operator/deploy/rbac.yaml
Create memcached-operator/pkg/apis/cache/v1alpha1/doc.go
Create memcached-operator/pkg/apis/cache/v1alpha1/register.go
Create memcached-operator/pkg/apis/cache/v1alpha1/types.go
Create memcached-operator/pkg/stub/handler.go
Create memcached-operator/tmp/build/build.sh
Create memcached-operator/tmp/build/docker_build.sh
Create memcached-operator/tmp/build/Dockerfile
Create memcached-operator/tmp/codegen/boilerplate.go.txt
Create memcached-operator/tmp/codegen/update-generated.sh
Create memcached-operator/Gopkg.toml
Create memcached-operator/Gopkg.lock
Run dep ensure ...
Run dep ensure done

@fanminshi
Copy link
Contributor Author

all fixed. PTAL cc/ @hasbro17

@hasbro17
Copy link
Contributor

LGTM

@fanminshi fanminshi merged commit 09d7ff9 into operator-framework:master Mar 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Print the progress of operator-sdk new command

2 participants