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

Feature request: Advanced exporting with tags #167

Closed
dmi3j opened this issue May 24, 2016 · 15 comments
Closed

Feature request: Advanced exporting with tags #167

dmi3j opened this issue May 24, 2016 · 15 comments

Comments

@dmi3j
Copy link

dmi3j commented May 24, 2016

Would be nice to specify tags are in "OR" or "AND" mode. Currently when exporting with multiple tags all the translations with "any" of tags are exported. I would like to export translation where "all" mentioned tags present.

@sebastianludwig
Copy link
Collaborator

sebastianludwig commented May 24, 2016

How about +/- prefixes to specify how a tag condition should be used?

--tags tag1,tag2,tag3 -> (tag1 OR tag2 OR tag3)    # current behavior 
--tags +tag1,+tag2,+tag3 -> (tag1 AND tag2 AND tag3)
--tags -tag1,-tag2,-tag3 -> !(tag1 OR tag2 OR tag3)
--tags tag1,tag2,+tag3 -> (tag1 OR tag2) AND (tag3)
--tags tag1,tag2,+tag3,+tag4 -> (tag1 OR tag2) AND (tag3 AND tag4)
--tags tag1,tag2,-tag3 -> (tag1 OR tag2) AND !(tag3)
--tags tag1,tag2,-tag3,-tag4 -> (tag1 OR tag2) AND !(tag3 OR tag4)
--tags tag1,tag2,+tag3,+tag4,-tag5,-tag6 -> (tag1 OR tag2) AND (tag3 AND tag4) AND !(tag5 OR tag6)

This would also solve #98.

@scelis, opinions?

@scelis
Copy link
Owner

scelis commented May 24, 2016

Are there other tools that do similar ORing and ANDing (and maybe NOTing)? I find the order of operations above (without explicit parentheses) quite hard to follow.

@sebastianludwig
Copy link
Collaborator

My command-line-foo is pretty weak and I actually don't know very many CLIs, so not that I'm aware of :-) Maybe the rules seem more complicated than what I had in mind.

  1. Group all tags without prefix and OR them
  2. Group all tags with + and AND them
  3. Group all tags with - and OR them - invert this group (!)
  4. Join all Groups with AND

So the last example could be reordered and still yield the same result:

--tags -tag6,tag2,+tag3,tag1,+tag4,-tag5 -> (tag1 OR tag2) AND (tag3 AND tag4) AND !(tag5 OR tag6)

And maybe the rules become even simpler if the third one is rephrased: Invert all tags with - and AND them. The result would be

--tags tag1,tag2,+tag3,+tag4,-tag5,-tag6 -> (tag1 OR tag2) AND (tag3 AND tag4) AND (!tag5 AND !tag6)

@dmi3j, @rk13: you requested this feature, what's your opinion?

@dmi3j
Copy link
Author

dmi3j commented May 25, 2016

My initial idea was instead of currently available:
--tags tag1,tag2,tag3
which basically means OR to have
--anytags tags1,tags2,tag3 = OR
and
--alltags tag1,tag2,tag3 = AND

It's hard to image who would needs comprehensive combinations of OR and AND

@sebastianludwig
Copy link
Collaborator

For #98 we'd also need --notags tag1,tag2,tag3 or something like that. Would those command line arguments be combinable then, too?

@sebastianludwig
Copy link
Collaborator

@scelis, what do you like better? A little more complex syntax or more command line options?

I personally prefer the syntax, because

  1. we wouldn't get rid of the "how do all these combine" complexity by separating the options
  2. it's even harder to understand if the tags aren't listed together
  3. twine already has a ton of command line options ;-)
  4. if this is an advanced feature, it's okay if it's not 100% obvious and needs a quick readme lookup

@scelis
Copy link
Owner

scelis commented May 30, 2016

Honestly, both of these options seem overly complicated to me. What about a separator other than comma for ANDing?

--tags a+b+c+d

Comma for OR, plus for AND. If there are both, ORs have a higher order of precedence. ! Could be added for NOT if necessary or that could be done in a later PR.

It's similar to what you have above, but I think a tad simpler.

@sebastianludwig
Copy link
Collaborator

So --tags a+b,c+d would be a AND (b or c) AND d?

Since filtering for missing tags is already on the list, I'd like to at least come up with a plan on how it would work to be sure it will work.

--tags a,b+c+d!e!f -> (a OR b) AND c AND d AND !e AND !f?

I'm cool with that :-)

@scelis
Copy link
Owner

scelis commented May 30, 2016

The not still requires an OR or AND separator.

--tags a,b+c,!d+!f

@rk13
Copy link

rk13 commented May 30, 2016

Cucumber project has quite simple logical ANDing and ORing for tags
https://github.com/cucumber/cucumber/wiki/Tags

Scenarios which match @Important OR @billing
cucumber --tags @billing,@important

Running scenarios which match @Important AND @billing
cucumber --tags @billing --tags @important

Applying similar approach for Twine might result
OR (currently available)
--tags tag1,tag2

AND
--tags tags1 --tags tags2

NOT
--tags ~tags3

@sebastianludwig
Copy link
Collaborator

I need to check how the OptionParser handles arguments that are specified multiple times.

@sebastianludwig
Copy link
Collaborator

It's supported, so we could also do that. --tags a,b+c,!d+!f would then be --tags a,b --tags c,~d --tags ~f. @scelis, which one shall it be? ;-)

@scelis
Copy link
Owner

scelis commented Jun 2, 2016

Hmm, I'd like to see if we can find 1 or 2 more tools that do something similar before deciding.

@sebastianludwig
Copy link
Collaborator

All right, here we go:

Cucumber

AND := --tags @billing --tags @important
OR := --tags @billing,@important
NOT := n/a
Source

Rspec

AND := --tag billing --tag important
OR := n/a
NOT := --tag ~billing
Source
Explanation

behat

AND := --tags billing&&important
OR := --tags billing,important
NOT := --tags ~billing
Source

AWS EC2

AND := --filters "Name=tag:Name,Values=xxx" "Name=tag:env,Values=dev"
OR := --filter tag:Purpose=X --filter tag:Purpose=Y
NOT := n/a
Source
Explanation

I also looked at Android's logcat, but that doesn't really apply.

Results

  1. We should keep the rule that --tags billing,important means OR to not break the existing interface.
  2. It's common to supply the same argument multiple times, for us that concatenation would be AND (because , is OR)
  3. It's common to use ~ as negation

@scelis
Copy link
Owner

scelis commented Jun 17, 2016

Awesome! Thanks so much for looking into this. I agree totally with your assessments.

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

No branches or pull requests

4 participants