|
| 1 | + |
| 2 | +# AsyncAPI CLI Configuration Guide |
| 3 | + |
| 4 | +This guide explains how to use the `asyncapi config` command to manage configuration settings for the AsyncAPI CLI. |
| 5 | + |
| 6 | +## Overview |
| 7 | + |
| 8 | +The `asyncapi config` command provides several subcommands to manage different aspects of the CLI configuration: |
| 9 | + |
| 10 | +- **`config`**: Main configuration command |
| 11 | +- **`config analytics`**: Manage analytics settings |
| 12 | +- **`config auth add`**: Add authentication configurations |
| 13 | +- **`config context`**: Manage context configurations (short aliases for AsyncAPI documents) |
| 14 | +- **`config versions`**: Show versions of AsyncAPI tools used |
| 15 | + |
| 16 | +## Using the `asyncapi config` Command |
| 17 | + |
| 18 | +### 1. Managing Analytics Settings |
| 19 | + |
| 20 | +The AsyncAPI CLI collects anonymous usage analytics to improve the product. You can enable, disable, or check the current status of analytics: |
| 21 | + |
| 22 | +```bash |
| 23 | +# Enable analytics |
| 24 | +asyncapi config analytics --enable |
| 25 | + |
| 26 | +# Disable analytics |
| 27 | +asyncapi config analytics --disable |
| 28 | + |
| 29 | +# Check current analytics status |
| 30 | +asyncapi config analytics --status |
| 31 | +``` |
| 32 | + |
| 33 | +### 2. Managing Authentication Configurations |
| 34 | + |
| 35 | +Add authentication configurations for resolving $ref files that require HTTP Authorization: |
| 36 | + |
| 37 | +```bash |
| 38 | +# Add authentication configuration |
| 39 | +asyncapi config auth add PATTERN TOKEN [--auth-type AUTH_TYPE] [--header HEADER] |
| 40 | + |
| 41 | +# Example: Add GitHub authentication |
| 42 | +asyncapi config auth add "github.com/**/*.*" $GITHUB_TOKEN --auth-type Bearer |
| 43 | +``` |
| 44 | + |
| 45 | +**Flags:** |
| 46 | +- `--auth-type`: Authentication type (default is "Bearer") |
| 47 | +- `--header`: Additional header in key=value format (can be used multiple times) |
| 48 | + |
| 49 | +### 3. Managing Context Configurations |
| 50 | + |
| 51 | +Context configurations allow you to create short aliases for full paths to AsyncAPI documents, making it easier to work with multiple specifications. |
| 52 | + |
| 53 | +#### Initialize Context Configuration |
| 54 | + |
| 55 | +```bash |
| 56 | +# Initialize context configuration in the current directory |
| 57 | +asyncapi config context init |
| 58 | + |
| 59 | +# Initialize context configuration in the root of the current repository |
| 60 | +asyncapi config context init ./ |
| 61 | + |
| 62 | +# Initialize context configuration in the user's home directory |
| 63 | +asyncapi config context init ~ |
| 64 | + |
| 65 | +# Initialize context configuration in a specific directory |
| 66 | +asyncapi config context init /path/to/directory |
| 67 | +``` |
| 68 | + |
| 69 | +#### Add a New Context |
| 70 | + |
| 71 | +```bash |
| 72 | +# Add a new context |
| 73 | +asyncapi config context add CONTEXT-NAME SPEC-FILE-PATH |
| 74 | + |
| 75 | +# Example: Add a context named "my-api" pointing to an AsyncAPI spec |
| 76 | +asyncapi config context add my-api ./asyncapi.yaml |
| 77 | + |
| 78 | +# Set the context being added as the current context |
| 79 | +asyncapi config context add my-api ./asyncapi.yaml --set-current |
| 80 | +``` |
| 81 | + |
| 82 | +#### List All Contexts |
| 83 | + |
| 84 | +```bash |
| 85 | +# List all stored contexts |
| 86 | +asyncapi config context list |
| 87 | +``` |
| 88 | + |
| 89 | +#### View Current Context |
| 90 | + |
| 91 | +```bash |
| 92 | +# Show the current context that is being used |
| 93 | +asyncapi config context current |
| 94 | +``` |
| 95 | + |
| 96 | +#### Use a Specific Context |
| 97 | + |
| 98 | +```bash |
| 99 | +# Set a context as current |
| 100 | +asyncapi config context use CONTEXT-NAME |
| 101 | + |
| 102 | +# Example: Use the "my-api" context |
| 103 | +asyncapi config context use my-api |
| 104 | +``` |
| 105 | + |
| 106 | +#### Edit a Context |
| 107 | + |
| 108 | +```bash |
| 109 | +# Edit an existing context |
| 110 | +asyncapi config context edit CONTEXT-NAME NEW-SPEC-FILE-PATH |
| 111 | + |
| 112 | +# Example: Update the "my-api" context with a new spec file |
| 113 | +asyncapi config context edit my-api ./new-asyncapi.yaml |
| 114 | +``` |
| 115 | + |
| 116 | +#### Remove a Context |
| 117 | + |
| 118 | +```bash |
| 119 | +# Delete a context from the store |
| 120 | +asyncapi config context remove CONTEXT-NAME |
| 121 | + |
| 122 | +# Example: Remove the "my-api" context |
| 123 | +asyncapi config context remove my-api |
| 124 | +``` |
| 125 | + |
| 126 | +### 4. Viewing Tool Versions |
| 127 | + |
| 128 | +```bash |
| 129 | +# Show versions of AsyncAPI tools used |
| 130 | +asyncapi config versions |
| 131 | +``` |
| 132 | + |
| 133 | +## Configuration File Location |
| 134 | + |
| 135 | +The configuration files are stored in the following locations: |
| 136 | + |
| 137 | +- **Context files**: Stored in `.asyncapi-cli` file in the current directory, repository root, or user's home directory. The CLI automatically searches for this file in the following locations: |
| 138 | + - Current directory: `.asyncapi-cli` |
| 139 | + - Repository root: `.asyncapi-cli` |
| 140 | + - User's home directory: `~/.asyncapi-cli` |
| 141 | + |
| 142 | +- **Authentication configurations**: Stored in the same `.asyncapi-cli` file as context configurations (JSON format) |
| 143 | +- **Analytics settings**: Stored in the same `.asyncapi-cli` file as context configurations (JSON format) |
| 144 | + |
| 145 | +## Best Practices |
| 146 | + |
| 147 | +1. **Use contexts** to manage multiple AsyncAPI specifications in your projects |
| 148 | +2. **Set a default context** using the `--set-current` flag when adding new contexts |
| 149 | +3. **Use environment variables** for sensitive tokens in authentication configurations |
| 150 | +4. **Check analytics status** periodically to ensure you're comfortable with the data collection |
| 151 | + |
| 152 | +## Troubleshooting |
| 153 | + |
| 154 | +If you encounter issues with configuration: |
| 155 | +- Verify the configuration file locations |
| 156 | +- Check file permissions |
| 157 | +- Ensure you're using the latest version of the AsyncAPI CLI |
| 158 | +- Check the CLI logs for detailed error messages |
| 159 | + |
| 160 | +## Summary |
| 161 | + |
| 162 | +The AsyncAPI CLI provides powerful configuration options to customize your workflow. The `asyncapi config` command allows you to: |
| 163 | +- Manage analytics settings |
| 164 | +- Configure authentication for protected resources |
| 165 | +- Create and manage context aliases for AsyncAPI documents |
| 166 | +- View tool versions |
| 167 | + |
| 168 | +This configuration system helps you maintain a consistent and efficient workflow when working with multiple AsyncAPI specifications. |
| 169 | + |
| 170 | +--- |
| 171 | +Completed configuration guide for [asyncapi/cli] |
0 commit comments