Skip to content

Rewrite Command-Line Parser for Smart Parsing with Built-In Options and Enhanced FlexibilityΒ #41

@dreamer-coding

Description

@dreamer-coding

Category: Fossil IO
Component: Command-Line Parsing
Proposed Enhancement: Rewrite the command-line parser to support an easy-to-use command-line pallet with intelligent parsing capabilities, built-in options like --help, --version, --color, --verbose, and a variety of data types (bool, int, strings, arrays, etc.) while integrating subcommands and flags based on option types.


πŸ“ Summary

This rewrite will enhance the current command-line parser to streamline parsing for smart, flexible command-line interfaces. The new system will have an intuitive approach to handling commands, subcommands, flags, subflags, and values. Additionally, it will automatically include common CLI options like --help, --version, --color, and --verbose. Options will support different types such as bool, int, strings, array, and even feature toggles, akin to Meson build system CLI parsing.

We’ll leverage string flags to simplify command and flag definitions, improving readability and user-friendliness. The default color scheme will make it easier for users to understand the output, with blue for text and light blue for values in color mode.


πŸ’‘ Motivation

  • Current CLI parsing may be cumbersome, especially when adding new options and handling multiple types.
  • Common CLI options like --help, --version, and --verbose need to be natively supported.
  • Parsing different option types, such as boolean flags, integers, and arrays, can be cumbersome and error-prone in the existing implementation.
  • Enabling users to have more flexibility and clarity when dealing with complex command-line configurations is key.

πŸ”§ Proposed Features

  1. Built-in CLI Options

    • --help – Displays usage information and options.
    • --version – Outputs version information.
    • --color – Toggles colorized output (defaults to blue for text, light blue for values).
    • --verbose – Enables verbose output.
  2. Support for Multiple Option Types

    • Boolean – Simple flags like --verbose (true/false).
    • Integers – Use --threads <number> to specify values (e.g., --threads 4).
    • Strings – Basic text input, such as --file <filename>.
    • Arrays – Use --include <file1> <file2> to specify multiple values.
    • Feature Toggles (Enable/Disable/Auto) – Support flags like --debug=<enable/disable/auto> where default could be auto.
  3. Subcommands and Flags

    • Support for commands and subcommands with their own flags and values. E.g.:
      • command [subcommand] [flags]
      • build --config debug --threads 4
  4. Color Mode and Text Customization

    • Default color scheme: text will be blue, and light blue will be used for values in colorized output mode.
    • The user can override the color scheme via --color option.
  5. Option Aliases and Simplicity

    • Aliases for flags: Short flags like -v for --verbose, and -h for --help.
    • Simplified, readable syntax for adding commands and subcommands, including array-based options or toggles.
    • Ability to parse complex options efficiently (e.g., --config {enable,bold,underline}).

πŸ“‚ Location

  • Core File: Update the src/io/parser.c for command parsing logic.
  • Helper File: Create or update src/io/cli_options.c to define built-in options and how to handle their parsing.
  • Unit Tests: Create tests/io/test_parser.c to validate the behavior of all new and existing CLI options, subcommands, and flags.

βœ… Dependencies

  • Minimal additional dependencies: Utilize basic string and argument manipulation methods from cstring.h.
  • No external libraries required for core functionality (relying on custom parsing).

πŸ› οΈ Next Steps

  1. Define core CLI options (e.g., --help, --version, --color, --verbose) and set default behavior.
  2. Implement flexible parsing that supports option types: boolean, integer, string, array, and feature toggles.
  3. Add subcommand support for easier, more modular CLI structures.
  4. Design the color mode logic to change default text formatting based on the --color flag.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions