Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Build help text based on terminal width, adjust column widths dynamically #761

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

effigies
Copy link
Contributor

This PR adds maxTableWidth and colRigidity options to TableSettings, allowing the table renderer to target a particular maximum width. colRigidity is a parameter where 1 indicates that the column width should not be reduced, and 0 that it can be adjusted arbitrarily. I made it a number instead of a bool, since it seems plausible to allow for a 0.5 to be reduced by half the amount of a 0, but I only implemented 0 and 1.

I then use this to update the help text generation, which is constrained to use the terminal width as the maximum width. I make the first columns rigid, as the descriptions and types are more likely to take up space and more tolerant to line breaks.

I hope this is reasonable. It dramatically improves the help text for my tool.

Before (regardless of terminal width):
❯ deno run -A jsr:@bids/validator --help

Usage:   bids-validator <dataset_directory>
Version: 1.14.13

Description:

  This tool checks if a dataset in a given directory is compatible with the Brain Imaging Data Structure specification. To learn more about
  Brain Imaging Data Structure visit http://bids.neuroimaging.io

Options:

  -h, --help                              - Show this help.
  -V, --version                           - Show the version number for this program.
  --json                                  - Output machine readable JSON
  -s, --schema           <URL-or-tag>     - Specify a schema version to use for validation
  -c, --config           <file>           - Path to a JSON configuration file
  -v, --verbose                           - Log more extensive information about issues
  --ignoreWarnings                        - Disregard non-critical issues
  --ignoreNiftiHeaders                    - Disregard NIfTI header content during validation
  --debug                <level>          - Enable debug output                                                             (Default: "ERROR", Values: "NOTSET", "DEBUG", "INFO",
                                                                                                                            "WARN", "ERROR", "CRITICAL")
  --filenameMode                          - Enable filename checks for newline separated filenames read from stdin
  --blacklistModalities  <modalities...>  - Array of modalities to error on if detected.                                    (Default: [], Values: "MRI", "PET", "MEG", "EEG", "iEEG",
                                                                                                                            "Microscopy", "NIRS", "MRS")
  -r, --recursive                         - Validate datasets found in derivatives directories in addition to root dataset
  -o, --outfile          <file>           - File to write validation results to.
  --color, --no-color    [color]          - Enable/disable color output (defaults to detected support)                      (Default: true)
After (88 columns)
❯ deno run -A ~/Projects/bids/bids-validator/bids-validator/src/bids-validator.ts --help

Usage:   bids-validator <dataset_directory>
Version: v1.14.15-dev.0-11-g8f3519b3

Description:

  This tool checks if a dataset in a given directory is compatible with the Brain
  Imaging Data Structure specification. To learn more about Brain Imaging Data
  Structure visit http://bids.neuroimaging.io

Options:

  -h, --help                              - Show this help.
  -V, --version                           - Show the version number
                                            for this program.
  --json                                  - Output machine readable
                                            JSON
  -s, --schema           <URL-or-tag>     - Specify a schema version
                                            to use for validation
  -c, --config           <file>           - Path to a JSON
                                            configuration file
  -v, --verbose                           - Log more extensive
                                            information about issues
  --ignoreWarnings                        - Disregard non-critical
                                            issues
  --ignoreNiftiHeaders                    - Disregard NIfTI header
                                            content during
                                            validation
  --debug                <level>          - Enable debug output       (Default:
                                                                      "ERROR", Values:
                                                                      "NOTSET",
                                                                      "DEBUG", "INFO",
                                                                      "WARN", "ERROR",
                                                                      "CRITICAL")
  --filenameMode                          - Enable filename checks
                                            for newline separated
                                            filenames read from
                                            stdin
  --blacklistModalities  <modalities...>  - Array of modalities to    (Default: [],
                                            error on if detected.     Values: "MRI",
                                                                      "PET", "MEG",
                                                                      "EEG", "iEEG",
                                                                      "Microscopy",
                                                                      "NIRS", "MRS")
  -r, --recursive                         - Validate datasets found
                                            in derivatives
                                            directories in addition
                                            to root dataset
  -o, --outfile          <file>           - File to write validation
                                            results to.
  --color, --no-color    [color]          - Enable/disable color      (Default: true)
                                            output (defaults to
                                            detected support)
142 columns
❯ deno run -A ~/Projects/bids/bids-validator/bids-validator/src/bids-validator.ts --help

Usage:   bids-validator <dataset_directory>
Version: v1.14.15-dev.0-11-g8f3519b3

Description:

  This tool checks if a dataset in a given directory is compatible with the Brain Imaging Data Structure specification. To learn more about
  Brain Imaging Data Structure visit http://bids.neuroimaging.io

Options:

  -h, --help                              - Show this help.
  -V, --version                           - Show the version number for this program.
  --json                                  - Output machine readable JSON
  -s, --schema           <URL-or-tag>     - Specify a schema version to use for validation
  -c, --config           <file>           - Path to a JSON configuration file
  -v, --verbose                           - Log more extensive information about issues
  --ignoreWarnings                        - Disregard non-critical issues
  --ignoreNiftiHeaders                    - Disregard NIfTI header content during validation
  --debug                <level>          - Enable debug output                                      (Default: "ERROR", Values: "NOTSET",
                                                                                                     "DEBUG", "INFO", "WARN", "ERROR",
                                                                                                     "CRITICAL")
  --filenameMode                          - Enable filename checks for newline separated filenames
                                            read from stdin
  --blacklistModalities  <modalities...>  - Array of modalities to error on if detected.             (Default: [], Values: "MRI", "PET",
                                                                                                     "MEG", "EEG", "iEEG", "Microscopy",
                                                                                                     "NIRS", "MRS")
  -r, --recursive                         - Validate datasets found in derivatives directories in
                                            addition to root dataset
  -o, --outfile          <file>           - File to write validation results to.
  --color, --no-color    [color]          - Enable/disable color output (defaults to detected        (Default: true)
                                            support)

@effigies
Copy link
Contributor Author

I think this closes #723. It doesn't enable configuration, but it does do what I think they want. It's certainly what I want.

If someone wants to try this out, you can replace @cliffy/command with @effigies/[email protected] and @cliffy/table with @effigies/[email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant