Development guidelines for the cws-lib-bash cloud-native shell library. Covers project structure, coding patterns, function naming conventions, error handling, and debugging workflows.
This skill provides development guidelines for contributing to the cws-lib-bash project, a cloud-native shell utility library.
cws-lib-bash is a modular bash library for cloud-native operations. It provides reusable shell functions organized by domain (networking, Docker, Kubernetes, etc.) with consistent error handling and logging.
```
cws-lib-bash/
├── bin/
│ ├── cws_bash_setup # Installation script
│ ├── cws_bash_env # Environment loader
│ └── cws_bash_run # Function executor
├── profile.d/ # Core functions loaded at shell startup
└── scripts/ # Domain-specific modules
├── network.sh
├── docker.sh
└── ...
```
Use `snake_case` with the pattern `domain_action`:
```bash
network_test_connectivity
docker_list_containers
kubernetes_get_pods
```
Always validate required parameters:
```bash
function example_function() {
local var=${1:-}
[ -z "$var" ] && log error "Missing required parameter" && return ${RETURN_FAILURE:-1}
# Function logic here
}
```
Check for required commands before using them:
```bash
have docker || { log error "docker not found"; return ${RETURN_FAILURE:-1}; }
have kubectl || { log error "kubectl not found"; return ${RETURN_FAILURE:-1}; }
```
Use the `log` function with severity levels:
```bash
log info "Starting operation"
log notice "Configuration changed"
log warn "Deprecated feature used"
log error "Operation failed"
log fatal "Critical system error"
```
Use consistent return codes:
```bash
return ${RETURN_SUCCESS:-0} # Success
return ${RETURN_FAILURE:-1} # Failure
```
Use `safe_pushd` and `safe_popd` for directory changes:
```bash
safe_pushd /target/directory || return ${RETURN_FAILURE:-1}
safe_popd || return ${RETURN_FAILURE:-1}
```
```bash
./bin/cws_bash_setup
```
```bash
source ./bin/cws_bash_env
```
```bash
./bin/cws_bash_run <function_name> [arguments]
```
```bash
bash -n scripts/<file>.sh
```
Use VS Code task: "shellcheck: current file"
1. Create `scripts/<domain>.sh`
2. Follow the core patterns outlined above
3. Add domain-specific functions using `domain_action` naming
4. Include proper error handling and logging
5. Add dependency checks for required commands
Handle platform-specific logic:
```bash
if is_linux; then
# Linux-specific code
elif is_macos; then
# macOS-specific code
fi
```
```bash
function example_clone() {
local dir=${1:-}
local url=${2:-}
# Validate parameters
[ -z "$dir" ] || [ -z "$url" ] && {
log error "Usage: example_clone <dir> <url>"
return ${RETURN_FAILURE:-1}
}
# Check dependencies
have git || {
log error "git not found"
return ${RETURN_FAILURE:-1}
}
# Execute operation
git_clone_into "$dir" "$url"
return ${RETURN_SUCCESS:-0}
}
```
1. **Always validate inputs** before using them
2. **Check dependencies** before executing commands
3. **Use consistent logging** throughout your functions
4. **Handle errors gracefully** with meaningful messages
5. **Return appropriate exit codes** for success/failure
6. **Document complex logic** with inline comments
7. **Test on both Linux and macOS** when possible
8. **Use safe directory operations** with pushd/popd wrappers
All functions are invoked through the `cws_bash_run` entry point, ensuring consistent environment setup and error handling.
When adding new functionality:
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/cws-lib-bash-development/raw