# Command Argument Parser

### KCmdArgParser Class Overview

* Define allowed options and arguments
* Parsing of the command line arguments
* Methods to query and retrieve options and arguments

### Example

```java
import ch.k43.util.KCmdArgParser;

public class CmdParser {
	
   public static void main(String[] args) {

      // Parser syntax: -a and -l optional, one parameter required
      final String ARG_SYNTAX = "?-l:?-a:!.";			
		
      // Initialize command line parser with argument syntax
      KCmdArgParser argParser = new KCmdArgParser(ARG_SYNTAX);
		
      // Parse command line arguments
      if (!argParser.parse(args)) {
         System.out.println("Syntax error: " + argParser.getLastError());
         System.exit(1);
      }
		
      System.out.println("Option -l: " + argParser.hasOption("-l"));
      System.out.println("Option -a: " + argParser.hasOption("-a"));
      System.out.println("Parameter: " + argParser.getArgument());
   }
}
```

### Output

```
% CmdParser -l file.txt
Option -l: true
Option -a: false
Parameter: file.txt

% CmdParser -x file.txt
Syntax error: Command line option not supported: -x
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://java-util.k43.ch/examples/command-argument-parser.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
