|
| 1 | +# Coding Conventions |
| 2 | + |
| 3 | +This document outlines the coding conventions used in our project, particularly for bash scripts and AWS CLI commands. |
| 4 | + |
| 5 | +## Bash Scripts |
| 6 | + |
| 7 | +### Function Naming |
| 8 | +- Use lowercase with hyphens for function names (e.g., `vpc-subnets`, `vpc-route-tables`). |
| 9 | +- Function names should be descriptive of their purpose. |
| 10 | + |
| 11 | +### Comments |
| 12 | +- Use `#` for single-line comments. |
| 13 | +- Include a brief description of the function's purpose immediately after the function name. |
| 14 | +- For complex functions, add usage examples in the comments. |
| 15 | + |
| 16 | +### AWS CLI Commands |
| 17 | +- Use `aws` followed by the service name (e.g., `aws ec2`, `aws rds`). |
| 18 | +- Prefer `--output text` for consistent and easily parseable output. |
| 19 | +- Use `--query` with JMESPath expressions for filtering and formatting output. |
| 20 | + |
| 21 | +### Output Formatting |
| 22 | +- Use `columnise` (a custom function) to format output into columns. |
| 23 | +- Sort output when appropriate (e.g., `sort -k 5`). |
| 24 | + |
| 25 | +### Error Handling |
| 26 | +- Check for required arguments using `[[ -z "$vpc_ids" ]] && __bma_usage "vpc-id [vpc-id]" && return 1`. |
| 27 | + |
| 28 | +### Looping |
| 29 | +- Use `for` loops to iterate over multiple VPC IDs or other resources. |
| 30 | + |
| 31 | +### Variable Naming |
| 32 | +- Use lowercase for local variables (e.g., `local vpc_ids`, `local filters`). |
| 33 | +- Use uppercase for environment variables or constants (e.g., `$AWS_DEFAULT_REGION`). |
| 34 | + |
| 35 | +### Input Handling |
| 36 | +- Use `skim-stdin` (a custom function) to handle both piped input and arguments. |
| 37 | + |
| 38 | +## AWS Resource Naming |
| 39 | +- Use the format `resource-type-action` for function names that interact with specific AWS resources (e.g., `vpc-igw`, `vpc-nat-gateways`). |
| 40 | + |
| 41 | +## Output Conventions |
| 42 | +- For listing functions, output should typically include resource IDs and names. |
| 43 | +- Include 'NO_NAME' for resources without a Name tag. |
| 44 | + |
| 45 | +## Security Considerations |
| 46 | +- Be cautious with functions that perform destructive actions (e.g., `vpc-default-delete`). |
| 47 | +- Include safety checks before performing destructive actions. |
| 48 | + |
| 49 | +These conventions are derived from the observed patterns in the lib/vpc-functions file. They should be followed when contributing new functions or modifying existing ones to maintain consistency across the project. |
0 commit comments