Configuration Commands
Overview
Configuration commands manage cpm system settings including server connections, file paths, and operational parameters. Configuration is stored in YAML format and provides centralized control over cpm behavior.
Table of Contents
cpm config init
Description
Initialize default configuration file and directory structure. Creates ~/.cpm/config.yaml with sensible defaults and sets up required directories.
Syntax
cpm config init [flags]
Flags
| Flag | Type | Description |
|---|---|---|
--force |
boolean | Overwrite existing configuration |
Behavior
- Creates
~/.cpmdirectory if not exists - Generates default
config.yamlfile - Creates
data/subdirectory for repositories - Creates
keys/subdirectory for SSH keys - Sets appropriate permissions
- Won't overwrite existing config unless
--forcespecified
Default Configuration
main_server: ""
data_dir: ~/.cpm/data
ssh_key_path: ~/.cpm/id_rsa
database_path: ~/.cpm/cpm.db
Examples
cpm config init
# Output:
# Initializing cpm configuration...
# Created directory: /home/user/.cpm
# Created directory: /home/user/.cpm/data
# Created directory: /home/user/.cpm/keys
# Created configuration file: /home/user/.cpm/config.yaml
#
# Default configuration:
# main_server: (not set)
# data_dir: /home/user/.cpm/data
# ssh_key_path: /home/user/.cpm/id_rsa
# database_path: /home/user/.cpm/cpm.db
#
# Configuration initialized successfully
#
# Next steps:
# 1. Set main server: cpm config set main_server user@host
# 2. Generate SSH key: cpm ssh-key generate main
# 3. Register servers: cpm servers add origin hostname
# Force reinitialize
cpm config init --force
# Output:
# WARNING: This will overwrite existing configuration
# Continue? (y/N): y
# Reinitializing configuration...
# Configuration file overwritten: /home/user/.cpm/config.yaml
cpm config show
Description
Display current configuration settings in readable format.
Syntax
cpm config show [flags]
Flags
| Flag | Type | Description |
|---|---|---|
--format <type> |
string | Output format: yaml (default), json |
Examples
cpm config show
# Output:
# CONFIGURATION
#
# Config file: /home/user/.cpm/config.yaml
#
# Settings:
# main_server: git@git.example.com
# data_dir: /home/user/.cpm/data
# ssh_key_path: /home/user/.cpm/keys/main
# database_path: /home/user/.cpm/cpm.db
#
# Directory structure:
# Config directory: /home/user/.cpm
# Data directory: /home/user/.cpm/data (47 repositories)
# Keys directory: /home/user/.cpm/keys (3 keys)
# Database file: /home/user/.cpm/cpm.db (892 KB)
# JSON format
cpm config show --format json
# Output:
# {
# "config_file": "/home/user/.cpm/config.yaml",
# "main_server": "git@git.example.com",
# "data_dir": "/home/user/.cpm/data",
# "ssh_key_path": "/home/user/.cpm/keys/main",
# "database_path": "/home/user/.cpm/cpm.db"
# }
cpm config set
Description
Set a configuration value. Updates the configuration file with the new value.
Syntax
cpm config set <key> <value>
Arguments
| Argument | Required | Description |
|---|---|---|
key |
Yes | Configuration key to set |
value |
Yes | Value to set |
Valid Configuration Keys
| Key | Type | Description | Example |
|---|---|---|---|
main_server |
string | Main server address | git@git.example.com |
data_dir |
path | Directory for storing repository data | /var/lib/cpm/data |
ssh_key_path |
path | Default SSH key path | ~/.cpm/keys/main |
database_path |
path | Path to SQLite database file | ~/.cpm/cpm.db |
Examples
# Set main server
cpm config set main_server git@git.example.com
# Output:
# Configuration updated: main_server = git@git.example.com
# Config file: /home/user/.cpm/config.yaml
# Set data directory
cpm config set data_dir /var/lib/cpm/data
# Output:
# Configuration updated: data_dir = /var/lib/cpm/data
# Creating directory: /var/lib/cpm/data
# Config file: /home/user/.cpm/config.yaml
# Set SSH key path
cpm config set ssh_key_path ~/.cpm/keys/production
# Output:
# Configuration updated: ssh_key_path = /home/user/.cpm/keys/production
# Note: Ensure key exists at this path
# Set database path
cpm config set database_path ~/.cpm/production.db
# Output:
# Configuration updated: database_path = /home/user/.cpm/production.db
# Note: Database will be created at this location
Path Expansion
Configuration values support shell expansion:
~expands to user home directory$HOMEexpands to home directory$VARexpands environment variables
Validation
The set command validates configuration values:
- Checks path accessibility for directory settings
- Validates server address format for main_server
- Ensures database path is writable
cpm config get
Description
Retrieve a specific configuration value.
Syntax
cpm config get <key>
Arguments
| Argument | Required | Description |
|---|---|---|
key |
Yes | Configuration key to retrieve |
Examples
cpm config get main_server
# Output:
# git@git.example.com
cpm config get data_dir
# Output:
# /home/user/.cpm/data
cpm config get ssh_key_path
# Output:
# /home/user/.cpm/keys/main
cpm config get database_path
# Output:
# /home/user/.cpm/cpm.db
# Use in scripts
DATA_DIR=$(cpm config get data_dir)
echo "Repositories stored in: $DATA_DIR"
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success (key found and returned) |
| 1 | Key not found |
| 2 | Invalid key name |
cpm config path
Description
Display the absolute path to the configuration file.
Syntax
cpm config path
Examples
cpm config path
# Output:
# /home/user/.cpm/config.yaml
# Edit configuration manually
vim $(cpm config path)
# View configuration
cat $(cpm config path)
# Output:
# main_server: git@git.example.com
# data_dir: /home/user/.cpm/data
# ssh_key_path: /home/user/.cpm/keys/main
# database_path: /home/user/.cpm/cpm.db
Configuration Workflows
Initial Setup
# Initialize configuration
cpm config init
# Configure main server
cpm config set main_server git@git.example.com
# Set custom data directory (optional)
cpm config set data_dir /var/lib/cpm/data
# Verify configuration
cpm config show
Custom Configuration File
# Use custom config location
export GITM_CONFIG=/etc/cpm/config.yaml
# Or use --config flag
cpm --config /etc/cpm/config.yaml config show
# Initialize at custom location
cpm --config /etc/cpm/config.yaml config init
Migration to New System
# On old system: export configuration
cpm config show --format json > cpm-config.json
# Transfer file to new system
# On new system: import configuration
cpm config init
cpm config set main_server $(jq -r .main_server cpm-config.json)
cpm config set data_dir $(jq -r .data_dir cpm-config.json)
# ... etc
Environment-Specific Configuration
# Development configuration
cpm config set main_server git@dev.example.com
cpm config set data_dir ~/cpm-dev/data
# Production configuration
cpm config set main_server git@prod.example.com
cpm config set data_dir /var/lib/cpm/data
# Use separate config files
cpm --config ~/.cpm/dev-config.yaml config init
cpm --config ~/.cpm/prod-config.yaml config init
Configuration Backup
# Backup configuration
cp $(cpm config path) ~/cpm-config-backup.yaml
# Backup with timestamp
cp $(cpm config path) ~/cpm-config-$(date +%Y%m%d).yaml
# Restore configuration
cp ~/cpm-config-backup.yaml $(cpm config path)
cpm config show # Verify restoration
Configuration File Format
YAML Structure
# Main server for push/pull operations
main_server: "git@git.example.com"
# Local repository storage directory
data_dir: "/home/user/.cpm/data"
# Default SSH private key path
ssh_key_path: "/home/user/.cpm/keys/main"
# SQLite database file path
database_path: "/home/user/.cpm/cpm.db"
Comments
Add comments to document configuration:
# Production Git Server
main_server: "git@prod.example.com"
# Shared storage mount for repositories
data_dir: "/mnt/cpm-storage/data"
# Production SSH key
ssh_key_path: "/etc/cpm/keys/prod"
# Database with organization and user data
database_path: "/var/lib/cpm/cpm.db"
Multiple Environments
Use separate configuration files:
# Development
~/.cpm/dev-config.yaml
# Staging
~/.cpm/staging-config.yaml
# Production
~/.cpm/prod-config.yaml
# Use with:
cpm --config ~/.cpm/dev-config.yaml <command>
Best Practices
Configuration Management
- Initialize configuration before first use
- Document non-default settings with comments
- Backup configuration before major changes
- Use environment-specific config files for different deployments
- Version control configuration files (without sensitive data)
Path Configuration
- Use absolute paths in production
- Use
~for user-specific paths - Ensure directories exist before setting paths
- Use dedicated directories for cpm data
- Set appropriate permissions on directories
Security
- Protect configuration file:
chmod 600 ~/.cpm/config.yaml - Don't commit SSH keys to version control
- Use secure paths for sensitive data
- Regularly audit configuration settings
- Limit access to cpm directories
Maintenance
- Regular configuration backups
- Document configuration changes
- Test configuration after changes
- Keep configuration synchronized across systems
- Review and update settings periodically
Environment Variables
Override configuration with environment variables:
# Override main server
export GITM_MAIN_SERVER=git@override.example.com
# Override data directory
export GITM_DATA_DIR=/tmp/cpm-data
# Override SSH key
export GITM_SSH_KEY=/tmp/test-key
# Override database
export GITM_DATABASE=/tmp/test.db
# Use overridden settings
cpm config show