mason icon indicating copy to clipboard operation
mason copied to clipboard

feat: enum conditionals

Open lishaduck opened this issue 1 year ago • 2 comments

Description

I'm trying to create an app template that can be optionally compatible with Serverpod & Dart Frog. I'd originally created with without server support, then added Serverpod support via a boolean. Now, I'd like to additionaly add optional support for Dart Frog, but it shouldn't be possible to create an app supporting both Serverpod and Dart Frog. Therefore, I'd like to convert it my boolean to an enum. However, there does not appear to be (at least documented) support for switch-cases in mason.

Requirements

  • [ ] Allow switch-casing (or equivalent) over enums in mason

Additional Context

n/a?

lishaduck avatar Aug 03 '24 21:08 lishaduck

Mason's brick.yaml supports enum types Here is an example from the favorite color example:

name: favorite_color
description: A new brick created with the Mason CLI.

version: 0.1.0+1

environment:
  mason: ">=0.1.0-dev <0.1.0"

vars:
  color:
    type: enum
    description: Your favorite color
    default: green
    prompt: What is your favorite color?
    values:
      - red
      - green
      - blue

Luckey-Elijah avatar Aug 05 '24 21:08 Luckey-Elijah

Mason's brick.yaml supports enum types.

Yes, the issue is that you can't case over them. I'd like to define

server:
  type: enum
  values:
    - none
    - serverpod
    - dart_frog

and then do the following in my templates:

{{server.none}}
{{/server.none}}

// or

{{server}}
  {{.none}}{{/.none}}
  {{.dart_frog}}{{/.dart_frog}}
{{/server}}

lishaduck avatar Aug 06 '24 20:08 lishaduck