Command-Line Flags Handling
Relevant source files
The following files were used as context for generating this wiki page:
Introduction
Command-line flags in ollacc are designed to manage application state and configuration before the main execution logic begins. The system distinguishes between internal management flags—which reset or clear configuration values—and passthrough flags intended for the underlying claude executable. By processing management flags early in the execution flow, the system ensures that users can recover from invalid states (such as expired API keys or stale model defaults) without manually editing configuration files.
Sources: lib/flags.sh:1-6, README.md:92-101
Flag Processing Architecture
The flag handling logic is encapsulated primarily within lib/flags.sh. It utilizes a centralized function, flags_handle, which is called by the main orchestrator early in the execution lifecycle. This prevents the application from prompting for authentication or loading complex catalogs if the user's intent is simply to clear existing settings.
Management Flags
The system provides specific flags to manipulate the ~/.ollacc/config file. These flags utilize the config_unset function from lib/config.sh to remove specific key-value pairs while preserving other configuration data and comments.
| Flag | Description | Target Configuration Key |
|---|---|---|
--model-clear | Clears the saved default model, forcing the model selection menu on the next run. | OLLAMA_CLAUDE_DEFAULT_MODEL |
--key-clear | Removes the saved Anthropic/Ollama Cloud API key, triggering a re-prompt. | ANTHROPIC_AUTH_TOKEN |
Sources: lib/flags.sh:11-31, lib/config.sh:76-88, README.md:94-95
Passthrough Logic
Flags that do not match the internal management patterns are generally forwarded to the claude command. The system supports a -- separator to explicitly distinguish between flags meant for ollacc and those meant for the underlying Anthropic SDK/Claude Code CLI.
The diagram shows the decision path for flags where management flags terminate execution after modifying the configuration, while others proceed to normal operation.
Sources: lib/flags.sh:1-10, README.md:97-105
Implementation Details
Configuration Unsetting Logic
The config_unset function in lib/config.sh is the underlying mechanism for management flags. It uses awk to filter out lines matching the specified key while maintaining the integrity of the configuration file and its permissions (chmod 600).
config_unset() {
local key="$1"
[ -f "$OLLACC_CONFIG" ] || return 0
local tmp
tmp=$(mktemp)
awk -v k="$key" '
/^[[:space:]]*#/ { print; next }
$0 ~ "^[[:space:]]*" k "=" { next }
{ print }
' "$OLLACC_CONFIG" > "$tmp" && mv "$tmp" "$OLLACC_CONFIG"
chmod 600 "$OLLACC_CONFIG"
}
Sources: lib/config.sh:76-88
Integration with Main Flow
The flag handler returns 0 if a flag was successfully processed (leading to an immediate exit) and 1 if the flow should fall through to the rest of the application. This ensures that the configuration state is modified before any attempts to source the config or validate the ANTHROPIC_AUTH_TOKEN.
Sources: lib/flags.sh:8-10, lib/auth.sh:7-13
Summary
The command-line flag handling in ollacc provides a robust mechanism for state management. By prioritizing the detection of --model-clear and --key-clear, the system allows users to interactively reset their environment. All other flags are preserved and passed to the final execution of the claude model, ensuring that the wrapper does not interfere with the native capabilities of the underlying tool.