Skip to content
This repository was archived by the owner on Jul 16, 2020. It is now read-only.

ciao-cli: Add support for generic string matching in templates#1004

Merged
rbradford merged 1 commit into
ciao-project:masterfrom
mcastelino:template-subset
Jan 12, 2017
Merged

ciao-cli: Add support for generic string matching in templates#1004
rbradford merged 1 commit into
ciao-project:masterfrom
mcastelino:template-subset

Conversation

@mcastelino

@mcastelino mcastelino commented Jan 10, 2017

Copy link
Copy Markdown
Contributor

ciao-cli: Add support for substring matching

Add support for new filter capabilities. This allows the selection
of list elements based on substring, prefix, suffix matching etc
which will be useful for test automation.

@coveralls

coveralls commented Jan 10, 2017

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.02%) to 66.921% when pulling 5e5c6b9 on mcastelino:template-subset into 608387c on 01org:master.

@coveralls

coveralls commented Jan 10, 2017

Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.01%) to 66.917% when pulling 8f2d4e3 on mcastelino:template-subset into 608387c on 01org:master.

Comment thread ciao-cli/template.go Outdated
return f
}

func filterBySubstr(obj interface{}, field, val string) (retval interface{}) {

@markdryan markdryan Jan 11, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This function is almost identical to filterByField. Perhaps we need to make a new function, fieldField that takes a function as a parameter, e.g.,

func filterField(obj interface{}, field, val string, cmp func(string,string) bool)(retval interface{}) {

filterBySubstr then becomes

func filterBySubstr(obj interface{}, field, val string) (retval interface{}) {
     return filterField(obj, field, val, strings.Contains)
}

filterByField

func filterByField(obj interface{}, field, val string) (retval interface{}) {
     return filterField(obj, field, val, func(a, b string) bool {
         return a == b
    })
}

You could then have a whole pile of filter functions, with no extra effort, e.g,

filter
filterSubstr (might be better to call is filterContains to match the std lib function called)
filterHasPrefix
filterHasSuffix
filterRegexp
filterFolded

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@markdryan makes perfect sense. I will also add a few more generic filters based on what the strings suport today and with the same nomenclature. That may help in other areas also, specially event processing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@markdryan updated as per review comments. Please re-review

Add support for new filter capabilities. This allows the selection
of list elements based on substring, prefix, suffix matching etc
which will be useful for test automation.

Signed-off-by: Manohar Castelino <manohar.r.castelino@intel.com>
@mcastelino mcastelino changed the title ciao-cli: Add support for substring matching ciao-cli: Add support for generic string matching in templates Jan 12, 2017
@coveralls

coveralls commented Jan 12, 2017

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.009%) to 66.885% when pulling 604e734 on mcastelino:template-subset into e57e064 on 01org:master.

@markdryan markdryan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me.

@rbradford rbradford merged commit 5635be8 into ciao-project:master Jan 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants