-
Notifications
You must be signed in to change notification settings - Fork 11
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
Pretty print fact values #176
Conversation
9d62a86
to
3141a65
Compare
❤️ Hey awesome, I really like this idea. Makes it so much easier to take the results from the gatherers to the playground to try out some 'wild' ideas 😃 |
@angelabriel original idea is by @fabriziosestito, I'm just an executor :D All the love goes to him 😄 |
@@ -98,6 +102,10 @@ func (v *FactValueString) AsInterface() interface{} { | |||
return v.Value | |||
} | |||
|
|||
func (v *FactValueString) PrettyPrint() (string, error) { |
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.
leftover?
@@ -36,6 +40,16 @@ func (e *FactGatheringError) Wrap(msg string) *FactGatheringError { | |||
} | |||
} | |||
|
|||
func (e *Fact) PrettyPrint() (string, error) { |
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.
maybe we should cal this Prettify as well since it does not print
suite.Run(t, new(FactsGatheredTestSuite)) | ||
} | ||
|
||
func (suite *FactsGatheredTestSuite) TestFactValuePrettify() { |
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.
this is testing FactsPrettyPrint not FactValuePrettify
14cdd84
to
feb8a54
Compare
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.
It looks great man!
Nice work
func (e *Fact) Prettify() (string, error) { | ||
prettifiedValue, err := Prettify(e.Value) | ||
if err != nil { | ||
return "", errors.Wrap(err, "Error pretty-printing fact value data") |
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.
Maybe better the error being Error prettifying fact value data
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.
Done 👍
@@ -192,3 +196,28 @@ func getValue(fact FactValue, values []string) (FactValue, error) { | |||
return value, nil | |||
} | |||
} | |||
|
|||
func Prettify(fact FactValue) (string, error) { |
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.
Should this maybe be a private function?
And it could've been perfectly a struct function as well:
func (f *FactValue) Prettify() (string, error)
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.
This was the same way I tried to pursue at the beginning, but it requires a method to be implemented for each implementation of FactValue
. Instead, this way the function just works ™️ with every concrete type
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.
@arbulu89 you cannot add methods to an interface
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.
The function is better, you could achieve a semi functional result with a dedicated struct with the method implemented and then embedding with some hassle in every struct you want to prettify
But honestly I don't think it's very ideomatic, seems like some sort of oop abstract superclass with some default methods
Co-authored-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
feb8a54
to
6a89331
Compare
This PR introduces pretty printing for fact values into the CLI, formatting maps and lists as Rhai object maps and arrays.