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

flagext: Add support for using Bytes as a CLI flag #302

Merged
merged 3 commits into from
May 23, 2023
Merged

Conversation

56quarters
Copy link
Contributor

What this PR does:

Adds support for use as a CLI flag in addition to the existing YAML serialization.

Which issue(s) this PR fixes:

N/A

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Adds support for use as a CLI flag in addition to the existing
YAML serialization.

Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
@56quarters 56quarters marked this pull request as ready for review May 18, 2023 14:57
}

func Test_Bytes_Set(t *testing.T) {
for _, tcase := range []struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Given str is the input value, I'd put it first, as then the test cases read "this is the input, and this is the expected output"


func Test_Bytes_UnmarshalYAML(t *testing.T) {
for _, tcase := range []struct {
value uint64
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Same as above - given str is the input value, I'd put it first, as then the test cases read "this is the input, and this is the expected output"

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if this is really necessary given we're using a library for the conversions, but it might be good to include some test cases that aren't exactly 1 GB / MB / KB (eg. 1500 bytes or 2.3 GB)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out the library will format things like that in a very precise yet ugly way: 1536 * 1024 * 1024 becomes 1GiB512MiB

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I guess the good news is that we'll almost never go from int -> string. This would mostly be used for going the other direction, taking user input of string and turning it into an int.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah I think that's fine, as long as it can handle a user providing something like 2.3 GiB.

Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

LGTM (modulo Charles' comments). Thanks!

Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
Signed-off-by: Nick Pillitteri <nick.pillitteri@grafana.com>
@56quarters 56quarters merged commit c959df0 into main May 23, 2023
3 checks passed
@56quarters 56quarters deleted the bytes-flags branch May 23, 2023 13:36
@charleskorn charleskorn mentioned this pull request Jun 7, 2023
2 tasks
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.

None yet

3 participants