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

CoreUtil* structs to facilitate common behavior #127

Merged
merged 3 commits into from
Jan 28, 2024
Merged

Conversation

syrmel
Copy link
Member

@syrmel syrmel commented Jan 28, 2024

I'd like to propose adding CoreUtil* structs to common to make it easier to provide consistent behavior across utils.

For example, this would enable:

const app = common.CoreutilInfo{
	name: 'tac'
	description: 'concatenate and print files in reverse'
}
...
mut fp := app.make_flag_parser(os.args)
...
file = os.open(fname) or {
    app.quit(message: "${fname}: read error")
}
app.quit(message: "Success!", return_code: 0)
app.quit(message: "Not sure how we can be here.", return_code: 127, show_help_advice: true)

If accepted, I am happy to do some refactoring to use it in the existing utilities.

@JalonSolov
Copy link
Contributor

That's exactly what common is meant to do... collect common code, so it doesn't have to be duplicated across the other routines.

@JalonSolov JalonSolov merged commit a3b0c14 into vlang:main Jan 28, 2024
4 checks passed
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.

2 participants