mirror of
https://github.com/mikefarah/yq.git
synced 2026-08-24 00:04:50 +08:00
Add --shell-key-separator flag for customizable shell output format
- Add ShellVariablesPreferences struct with KeySeparator field (default: '_') - Update shellVariablesEncoder to use configurable separator - Add --shell-key-separator CLI flag - Add comprehensive tests for custom separator functionality - Update documentation with example usage for custom separator This feature allows users to specify a custom separator (e.g. '__') when outputting shell variables, which helps disambiguate nested keys from keys that contain underscores in their names. Example: yq -o=shell --shell-key-separator='__' file.yaml Fixes ambiguity when original YAML keys contain underscores.
This commit is contained in:
@@ -84,3 +84,23 @@ will output
|
||||
name='Miles O'"'"'Brien'
|
||||
```
|
||||
|
||||
## Encode shell variables: custom separator
|
||||
Use --shell-key-separator to specify a custom separator between keys. This is useful when the original keys contain underscores.
|
||||
|
||||
Given a sample.yml file of:
|
||||
```yaml
|
||||
my_app:
|
||||
db_config:
|
||||
host: localhost
|
||||
port: 5432
|
||||
```
|
||||
then
|
||||
```bash
|
||||
yq -o=shell --shell-key-separator="__" sample.yml
|
||||
```
|
||||
will output
|
||||
```sh
|
||||
my_app__db_config__host=localhost
|
||||
my_app__db_config__port=5432
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user