Skip to content

Nested case objects cannot use the "name" pragma field #10

@mratsim

Description

@mratsim

Test case

import
  confutils/defs

# Nimbus Bench - Scenario configuration
# --------------------------------------------------

type
  StartupCommand* = enum
    noCommand
    cmdFullStateTransition
    cmdSlotProcessing
    cmdBlockProcessing
    cmdEpochProcessing

  BlockProcessingCat* = enum
    catBlockHeader
    catRANDAO
    catEth1Data
    catProposerSlashings
    catAttesterSlashings
    catAttestations
    catDeposits
    catVoluntaryExits

  ScenarioConf* = object
    scenarioDir* {.
      desc: "The directory of your benchmark scenario"
      name: "scenario-dir"
      abbr: "d"
      required .}: InputDir
    preState* {.
      desc: "The name of your pre-state (without .ssz)"
      name: "pre"
      abbr: "p"
      defaultValue: "pre".}: string
    blocksPrefix* {.
      desc: "The prefix of your blocks file, for exemple \"blocks_\" for blocks in the form \"blocks_XX.ssz\""
      name: "blocks-prefix"
      abbr: "b"
      defaultValue: "blocks_".}: string
    blocksQty* {.
      desc: "The number of blocks to process for this transition. Blocks should start at 0."
      name: "block-quantity"
      abbr: "q"
      defaultValue: 1.}: int
    skipBLS*{.
      desc: "Skip BLS public keys and signature verification"
      name: "skip-bls"
      defaultValue: true.}: bool
    case cmd*{.
      command
      defaultValue: noCommand }: StartupCommand
    of noCommand:
      discard
    of cmdFullStateTransition:
      discard
    of cmdSlotProcessing:
      numSlots* {.
        desc: "The number of slots the pre-state will be advanced by"
        name: "num-slots"
        abbr: "s"
        defaultValue: 1.}: uint64
    of cmdBlockProcessing:
      case blockProcessingCat* {.
        desc: "block transitions"
        name: "process-blocks" # Comment this to make it work
        implicitlySelectable
        required .}: BlockProcessingCat
      of catBlockHeader:
        discard
      of catRANDAO:
        discard
      of catEth1Data:
        discard
      of catProposerSlashings:
        discard
      of catAttesterSlashings:
        discard
      of catAttestations:
        # discard
        # Or comment out the attestation below
        attestation*{.
          desc: "Attestation filename (without .ssz)"
          name: "attestation".}: string
      of catDeposits:
        discard
      of catVoluntaryExits:
        discard
    of cmdEpochProcessing:
      discard

import confutils
let scenario = ScenarioConf.load()

I can't rename cmdBlockProcessing to --process-blocks otherwise the compiler returns Error: Unable to find blockProcessingCat.

Tracing findOpt gives the following:

(name: "cmd", abbr: "", desc: "", typename: "StartupCommand", idx: 5, hasDefault: true,
 kind: Discriminator, isCommand: true, isImplicitlySelectable: false, subCmds: [
    (name: "noCommand", opts: [], shortHelpString: ""),
    (name: "cmdFullStateTransition", opts: [], shortHelpString: ""),
    (name: "cmdSlotProcessing", opts: [], shortHelpString: ""),
    (name: "cmdBlockProcessing", opts: [], shortHelpString: ""),
    (name: "cmdEpochProcessing", opts: [], shortHelpString: "")], defaultSubCmd: 0)
(name: "cmd", abbr: "", desc: "", typename: "StartupCommand", idx: 5, hasDefault: true,
 kind: Discriminator, isCommand: true, isImplicitlySelectable: false, subCmds: [
    (name: "noCommand", opts: [], shortHelpString: ""),
    (name: "cmdFullStateTransition", opts: [], shortHelpString: ""), (
    name: "cmdSlotProcessing", opts: [(name: "num-slots", abbr: "s", desc: "The number of slots the pre-state will be advanced by",
                                    typename: "uint64", idx: 6, hasDefault: true,
                                    kind: CliSwitch, isCommand: false,
                                    isImplicitlySelectable: false, subCmds: [],
                                    defaultSubCmd: 0)], shortHelpString: ""),
    (name: "cmdBlockProcessing", opts: [], shortHelpString: ""),
    (name: "cmdEpochProcessing", opts: [], shortHelpString: "")], defaultSubCmd: 0)
(name: "cmd", abbr: "", desc: "", typename: "StartupCommand", idx: 5, hasDefault: true,
 kind: Discriminator, isCommand: true, isImplicitlySelectable: false, subCmds: [
    (name: "noCommand", opts: [], shortHelpString: ""),
    (name: "cmdFullStateTransition", opts: [], shortHelpString: ""), (
    name: "cmdSlotProcessing", opts: [(name: "num-slots", abbr: "s", desc: "The number of slots the pre-state will be advanced by",
                                    typename: "uint64", idx: 6, hasDefault: true,
                                    kind: CliSwitch, isCommand: false,
                                    isImplicitlySelectable: false, subCmds: [],
                                    defaultSubCmd: 0)], shortHelpString: ""), (
    name: "cmdBlockProcessing", opts: [(name: "process-blocks", abbr: "",
                                     desc: "block transitions",
                                     typename: "BlockProcessingCat", idx: 7,
                                     hasDefault: false, kind: Discriminator,
                                     isCommand: false,
                                     isImplicitlySelectable: true, subCmds: [
    (name: "catBlockHeader", opts: [], shortHelpString: ""),
    (name: "catRANDAO", opts: [], shortHelpString: ""),
    (name: "catEth1Data", opts: [], shortHelpString: ""),
    (name: "catProposerSlashings", opts: [], shortHelpString: ""),
    (name: "catAttesterSlashings", opts: [], shortHelpString: ""),
    (name: "catAttestations", opts: [], shortHelpString: ""),
    (name: "catDeposits", opts: [], shortHelpString: ""),
    (name: "catVoluntaryExits", opts: [], shortHelpString: "")], defaultSubCmd: -1)],
    shortHelpString: ""),
    (name: "cmdEpochProcessing", opts: [], shortHelpString: "")], defaultSubCmd: 0)
(name: "process-blocks", abbr: "", desc: "block transitions",
 typename: "BlockProcessingCat", idx: 7, hasDefault: false, kind: Discriminator,
 isCommand: false, isImplicitlySelectable: true, subCmds: [
    (name: "catBlockHeader", opts: [], shortHelpString: ""),
    (name: "catRANDAO", opts: [], shortHelpString: ""),
    (name: "catEth1Data", opts: [], shortHelpString: ""),
    (name: "catProposerSlashings", opts: [], shortHelpString: ""),
    (name: "catAttesterSlashings", opts: [], shortHelpString: ""),
    (name: "catAttestations", opts: [], shortHelpString: ""),
    (name: "catDeposits", opts: [], shortHelpString: ""),
    (name: "catVoluntaryExits", opts: [], shortHelpString: "")], defaultSubCmd: -1)

So maybe a fieldName or originalName need to be kept around.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions