Class CommandParser

Class Documentation

class CommandParser

Static class for parsing command-line arguments and creating command contexts.

The CommandParser class provides a complete command-line argument parsing system for the ComChemKit application. It handles:

  • Command identification and validation

  • Option parsing with type conversion and validation

  • Configuration file integration

  • Help system and documentation generation

  • Error handling and user feedback

Pattern

This class follows the static utility class pattern - all methods are static and no instances are created. This simplifies usage and ensures consistent parsing behavior throughout the application.

Flow

  1. Command identification (extract, check-done, etc.)

  2. Common option parsing (threads, quiet, etc.)

  3. Dispatch to specific ICommand implementations for their arguments

  4. Configuration integration and validation

  5. Context finalization and return

Public Static Functions

static CommandContext parse(int argc, char *argv[])

Parse command-line arguments and create execution context.

This is the main entry point for command-line parsing. It processes all arguments, applies configuration defaults, validates parameters, and returns a complete CommandContext ready for command execution.

Note

Warnings are collected in the context rather than thrown as exceptions

Parameters:
  • argc – Number of command-line arguments

  • argv – Array of command-line argument strings

Returns:

Fully populated CommandContext ready for execution

Throws:
  • std::invalid_argument – for invalid command syntax

  • std::out_of_range – for parameter values outside valid ranges

static void print_help(const std::string &program_name = "cck")

Print general help information.

Displays comprehensive help including:

  • Application overview and description

  • Available commands and brief descriptions

  • Common options and their usage

  • Configuration file information

  • Usage examples

Parameters:

program_name – Name of the program executable (for display)

static void print_command_help(CommandType command, const std::string &program_name = "cck")

Print help for a specific command.

Displays detailed help for a specific command including:

  • Command description and purpose

  • Command-specific options and parameters

  • Usage examples and common scenarios

  • Related commands and workflows

Parameters:
  • command – The command type to show help for

  • program_name – Name of the program executable (for display)

static void print_config_help()

Print configuration system help.

Displays information about:

  • Configuration file locations

  • Available configuration options

  • Configuration file format

  • How to create default configuration

static void create_default_config()

Create a default configuration file.

Generates a default configuration file with all available options and their descriptions for user customization.

static std::string get_command_name(CommandType command)

Convert CommandType enum to string representation.

Parameters:

command – CommandType to convert

Returns:

String name of the command