Giter VIP home page Giter VIP logo

Comments (4)

macintacos avatar macintacos commented on June 20, 2024

To clarify, currently in order for a nested label + its parents to be filed, I would have to do something like this:

    {
      filter: {
        from: "[email protected]"
      },
      actions: {
        labels: [
          "Foo/Bar/Baz/Bax",
          "Foo/Bar/Baz",
          "Foo/Bar",
          "Foo",
        ]
      }
    },

When It feels like I should be able to do something like this (making up a new option):

    {
      filter: {
        from: "[email protected]"
      },
      actions: {
        labels: [
          "Foo/Bar/Baz/Bax",
        ],
        expandLabels: true // this would imply that the `labels` array should be split on the "/" so that all labels are applied as needed
      }
    },

from gmailctl.

mbrt avatar mbrt commented on June 20, 2024

This can be achieved by using Jsonnet directly. I'm always reluctant to add features in gmailctl itself, especially user-specific workflows. This will make it bloated and difficult to understand over time.

With that said, what you want could be achieved by using Jsonnet functions directly. I can see how a addParents function could take a label and produce an array with the same + all the parents.

actions: { labels: addParents('Foo/Bar') },

https://github.com/mbrt/gmailctl/blob/master/internal/data/gmailctl.libsonnet#L45 should serve as an inspiration for the implementation.

from gmailctl.

macintacos avatar macintacos commented on June 20, 2024

Ah okay, fair enough! I should dig more into what is possible with jsonnet anyway, as you said. If I come up with something, I'll be sure to share it here.

from gmailctl.

macintacos avatar macintacos commented on June 20, 2024

Forgot to comment - this is the solution I went with, and it's been working well:

{
  # This will take an array and transform strings like ["some/label"] to ["some", "some/label"]
  expandLabels(labels)::
    local splitLabel(label) = std.split(label, '/');
    local genSubLabels(label) =
      [
        std.join(
          '/',
          splitLabel(label)[:i + 1]
        )
        for i in std.range(0, std.length(splitLabel(label)) - 1)
      ];
    std.flattenArrays([genSubLabels(i) for i in labels]),
}

from gmailctl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.