Skip to content

[BUG] Argparse boolean_optional action handled sub-optimally #89

Description

@michellewang

With this argdump:

  {
    "$schema": "https://niwrap.dev/argdump/schema-v1.json",
    "$env": {
      "python_version": "3.14.7",
      "python_implementation": "CPython",
      "platform_system": "Linux",
      "platform_release": "6.17.0-1022-azure",
      "platform_machine": "x86_64",
      "argdump_version": "0.1.3"
    },
    "prog": "fmriprep",
    "description": "fMRIPrep: fMRI PREProcessing workflows v26.0.0.dev1+g4092cba59",
    "formatter_class": "ArgumentDefaultsHelpFormatter",
    "actions": [
      {
        "option_strings": [
          "--submm-recon",
          "--no-submm-recon"
        ],
        "dest": "hires",
        "action_type": "boolean_optional",
        "nargs": 0,
        "default": true,
        "help": "Enable or disable sub-millimeter (hi-res) reconstruction."
      }
    ]
  }

I get this descriptor:

{
  "schema-version": "0.5+styx",
  "name": "fmriprep",
  "description": "fMRIPrep: fMRI PREProcessing workflows v26.0.0.dev1+g4092cba59",
  "command-line": "fmriprep [SUBMM_RECON]",
  "inputs": [
    {
      "id": "submm_recon",
      "type": "String",
      "value-key": "[SUBMM_RECON]",
      "description": "Enable or disable sub-millimeter (hi-res) reconstruction.",
      "optional": true,
      "value-choices": [
        "--submm-recon",
        "--no-submm-recon"
      ],
      "name": "submm_recon"
    }
  ]
}

Which is annoying because then the invocation has to be something like this:

{
  "submm_recon": "--submm-recon"
}

Better to have a descriptor like this (mistakes possible):

{
  "schema-version": "0.5+styx",
  "name": "fmriprep",
  "description": "fMRIPrep: fMRI PREProcessing workflows v26.0.0.dev1+g4092cba59",
  "command-line": "fmriprep [SUBMM_RECON_OR_NO_SUBMM_RECON]",
  "inputs": [
    {
      "id": "submm_recon_or_no_submm_recon",
      "description": "Enable or disable sub-millimeter (hi-res) reconstruction.",
      "type": [
        {
          "command-line": "[SUBMM_RECON]",
          "inputs": [
            {
              "id": "submm_recon",
              "type": "Flag",
              "value-key": "[SUBMM_RECON]",
              "command-line-flag": "--submm-recon",
              "name": "submm_recon"
            }
          ],
          "name": "submm_recon",
          "id": "submm_recon"
        },
        {
          "name": "no_submm_recon",
          "id": "no_submm_recon",
          "command-line": "[NO_SUBMM_RECON]",
          "inputs": [
            {
              "id": "no_submm_recon",
              "type": "Flag",
              "value-key": "[NO_SUBMM_RECON]",
              "command-line-flag": "--no-submm-recon",
              "name": "no_submm_recon"
            }
          ]
        }
      ],
      "value-key": "[SUBMM_RECON_OR_NO_SUBMM_RECON]",
      "optional": true,
      "name": "submm_recon_or_no_submm_recon"
    }
  ]

which would allow an invocation like this, which I feel is better:

{
  "submm_recon_or_no_submm_recon": {
    "submm-recon": true
  }
}

Though in general the <A>_OR_<B> pattern feels a bit convoluted. But that seems to be the easiest way to encode mutually exclusive groups without relying on the Boutiques-specific groups field

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions