-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support score-compose init subcommand #57
Conversation
Signed-off-by: Ben Meier <[email protected]>
9cc6205
to
39cb8af
Compare
Signed-off-by: Ben Meier <[email protected]>
f160804
to
1da5f3a
Compare
internal/project/project.go
Outdated
// LoadStateDirectory loads the state directory for the given directory (usually PWD). | ||
func LoadStateDirectory(directory string) (*StateDirectory, bool, error) { | ||
d := filepath.Join(directory, DefaultRelativeStateDirectory) | ||
if st, err := os.Stat(d); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, it is not considered good practice to check for a file before opening - rather favour attempting to open the file and then check the failure there. This is to avoid race conditions for file opening i.e. https://groups.google.com/g/golang-nuts/c/Ayx-BMNdMFo/m/4rL8FFHr8v4J
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed up :) now just doing a direct read with error handling.
internal/command/init.go
Outdated
} | ||
} | ||
|
||
if st, err := os.Stat(initCmdScoreFile); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, it is not considered good practice to check for a file before opening - rather favour attempting to open the file and then check the failure there. This is to avoid race conditions for file opening i.e. https://groups.google.com/g/golang-nuts/c/Ayx-BMNdMFo/m/4rL8FFHr8v4J
In this case, using os.O_CREATE
with os.O_EXCL
will be an error if the file already exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed up :) now just doing a direct read with error handling and then a write if it doesn't exist.
Signed-off-by: Ben Meier <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…iption Signed-off-by: Ben Meier <[email protected]>
The init subcommand makes it easier to get started with Score compose!
And when run:
This dumps out a score file that looks like:
Types of changes
Checklist: