Skip to content
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

GetStdinFile functionality moved from score compose #85

Merged
merged 3 commits into from
Feb 17, 2025

Conversation

rabelmervin
Copy link
Contributor

@rabelmervin rabelmervin commented Jan 27, 2025

Description

This pull request moves the GetStdinFile function from the score-compose repository to the score-go repository under the uriget package.

Changes Made

Moved GetStdinFile to score-go:

  • The GetStdinFile function is now located in score-go/uriget/uriget.go.

  • The GetStdinFile is now integrated as a part of GetFile

  • This function reads from stdin and returns the content.

@rabelmervin rabelmervin changed the title GetStdinFile functionality moved GetStdinFile functionality moved from score compose Jan 27, 2025
@rabelmervin
Copy link
Contributor Author

Hi @astromechza @mathieu-benoit Can you please review it....

uriget/uriget.go Outdated
Comment on lines 97 to 99
if rawUri == "-" {
return getStdinFile(ctx)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of handling "-" separately in the command, consider adding support for it directly in GetFile, using a case "-" inside uriget.go
This would keep the logic consistent with other URI options and improve maintainability

Copy link
Member

Choose a reason for hiding this comment

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

@rabelmervin please move the rawUri == "-" check down into o.getFile as it's a variant of the file reading code - I don't want to have extra branches not related to the scheme checking here in the top-level GetFile function.

uriget/uriget.go Outdated
Comment on lines 128 to 146
func getStdinFile(ctx context.Context) ([]byte, error) {
// Check if stdin is being piped
stat, err := os.Stdin.Stat()
if err != nil {
return nil, err
}

// Check if stdin is a pipe
if (stat.Mode() & os.ModeCharDevice) == 0 {
return io.ReadAll(os.Stdin)
}

return nil, fmt.Errorf("no stdin data provided")
}

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a good practice to document the codebase but instead of these line comments you can add a small description here
Also, add a small test at https://github.com/score-spec/score-go/blob/main/uriget/example_test.go

Copy link
Member

Choose a reason for hiding this comment

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

@rabelmervin please add a unit test that temporarily assigns a file to os.Stdin and checks that we can read from it.

A manual test of this function may be useful too if you can.

@7h3-3mp7y-m4n
Copy link
Contributor

Thanks, @rabelmervin
You need to sign your commits to have the DCO pass successfully on this PR

Copy link
Member

@astromechza astromechza left a comment

Choose a reason for hiding this comment

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

Almost there! thanks for working on this. Additions to score-go benefit all the score implementations so far.

uriget/uriget.go Outdated
Comment on lines 97 to 99
if rawUri == "-" {
return getStdinFile(ctx)
}
Copy link
Member

Choose a reason for hiding this comment

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

@rabelmervin please move the rawUri == "-" check down into o.getFile as it's a variant of the file reading code - I don't want to have extra branches not related to the scheme checking here in the top-level GetFile function.

uriget/uriget.go Outdated
Comment on lines 128 to 146
func getStdinFile(ctx context.Context) ([]byte, error) {
// Check if stdin is being piped
stat, err := os.Stdin.Stat()
if err != nil {
return nil, err
}

// Check if stdin is a pipe
if (stat.Mode() & os.ModeCharDevice) == 0 {
return io.ReadAll(os.Stdin)
}

return nil, fmt.Errorf("no stdin data provided")
}

Copy link
Member

Choose a reason for hiding this comment

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

@rabelmervin please add a unit test that temporarily assigns a file to os.Stdin and checks that we can read from it.

A manual test of this function may be useful too if you can.

Copy link
Member

@astromechza astromechza left a comment

Choose a reason for hiding this comment

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

Thanks, @rabelmervin, for your contribution!

@astromechza astromechza merged commit 21887c9 into score-spec:main Feb 17, 2025
4 checks passed
@rabelmervin
Copy link
Contributor Author

Thanks @astromechza @mathieu-benoit for the opportunity. Why can't I make it double.
I would love to contribute to another issue :)

@rabelmervin
Copy link
Contributor Author

@astromechza I would like to connect with you on socials.

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.

3 participants