Skip to content

Instantly share code, notes, and snippets.

@pepicrft
Created June 4, 2024 15:04
Show Gist options
  • Save pepicrft/303a625933bd575150c1b4dc4b7d2710 to your computer and use it in GitHub Desktop.
Save pepicrft/303a625933bd575150c1b4dc4b7d2710 to your computer and use it in GitHub Desktop.

Commands like tuist build and tuist generate support passing arguments that represent the targets a developer wants to focus on. While the target level of granularity gives developers a lot of control, it puts them in a position of having to script around Tuist to be able to pass a group of tagets that have a semantic meaning. Here are some scenarios:

  • I'd like to focus on all the targets of a project
  • I'd like to focus only on the external targets
  • I'd like to focus only on the test targets
  • I'd like to focus only on the targets with a given tag

This has come up several times, so I'm taking the time to write down how I'd approach it if I was about to implement it as a first time contributor.

First of all, make sure you've read the Get started guidelines for contributors. At the end of it, you should be able to run tuist through the scheme in the Xcode project. Once you are familiar with that, I recommend loooking at the generate command. Note that the command assumes that what the user provides is a list of targets, where each target is represented by its name as a string.

We need to evolve those arguments from "a list of target names" to "a list of target filters". Here's a bit of pseudocode of how I'd model it:

enum TargetFilter {
  case target(name: String)
  case project(name: String)
  
  func parse(arguments: [String]) -> [TargetFilter] {
    // ...parsing logic
  }
}

The command would then use the parse logic to obtain a set of filters, that can then be use further down with the graph to filter the targets that should be included.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment