Prepare for release
This commit is contained in:
parent
f104f2a19a
commit
9101b2e2f0
17
CHANGELOG.md
17
CHANGELOG.md
|
@ -3,6 +3,23 @@
|
||||||
All notable changes to this project will be documented in this file. `Scout` adheres to [Semantic Versioning](http://semver.org).
|
All notable changes to this project will be documented in this file. `Scout` adheres to [Semantic Versioning](http://semver.org).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
## [4.0.0](https://github.com/ABridoux/scout/tree/3.0.3) (28/04/2021)
|
||||||
|
### Added
|
||||||
|
- Conversion from CSV input to one of the available formats [#181]
|
||||||
|
- `Data` and `Date` values support [#197]
|
||||||
|
- Set and add features support `Codable` values [#199]
|
||||||
|
- Possibility to read XML attributes
|
||||||
|
- Better integration with Zsh arrays and associative arrays [#235]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
- `PathExplorer` is now implemented by `ExplorerValue` for Plist, JSON and YAML [#199]
|
||||||
|
- Moved from serialisation to `Codable` using `ExplorerValue` for Plist, JSON and YAML. [#206]
|
||||||
|
- ”Add” features will no more create values on the fly. Only when a key/index is final will it be created/inserted. The method is now to first add an empty array or dictionary. [#210]
|
||||||
|
- `Path` parsing is now done with a parser rather than with regular expressions [#227]
|
||||||
|
- Command-line: `--format|-f` now required to specify the input format
|
||||||
|
- Command-line: `--csv` removed and `--csv-spe` renamed `--csv-exp`
|
||||||
|
- `PathExplorerXML` renamed to `ExplorerXML` and implements Copy on Write.
|
||||||
|
|
||||||
## [3.0.3](https://github.com/ABridoux/scout/tree/3.0.3) (08/04/2021)
|
## [3.0.3](https://github.com/ABridoux/scout/tree/3.0.3) (08/04/2021)
|
||||||
### Fixed
|
### Fixed
|
||||||
- Reading from standard input temporary fix for deprecation issue [#191]
|
- Reading from standard input temporary fix for deprecation issue [#191]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# Commands example
|
# Commands example
|
||||||
Use these commands with the People files in the playground.
|
Use these commands with the People files in the playground.
|
||||||
The commands work regardless of the file format you choose with the `-i | --input` option: People.json, People.plist, People.yml or People.xml.
|
The commands work regardless of the file format you choose with the `-i | --input` option: People.json, People.plist, People.yml or People.xml. The `--format|-f` on the other hand is required to specify the format of the input.
|
||||||
|
|
||||||
**Summary**
|
**Summary**
|
||||||
- [Read a value](#read)
|
- [Read a value](#read)
|
||||||
|
@ -16,38 +16,38 @@ The commands work regardless of the file format you choose with the `-i | --inpu
|
||||||
|
|
||||||
Output Tom's height: 175
|
Output Tom's height: 175
|
||||||
```bash
|
```bash
|
||||||
scout read "Tom.height" -i People.json
|
scout read -i People.json -f json "Tom.height"
|
||||||
```
|
```
|
||||||
|
|
||||||
Output Tom's first hobby: cooking
|
Output Tom's first hobby: cooking
|
||||||
```bash
|
```bash
|
||||||
scout read "Tom.hobbies[0]" -i People.xml
|
scout read -i People.xml -f xml "Tom.hobbies[0]"
|
||||||
```
|
```
|
||||||
|
|
||||||
Output Tom's last hobby: guitar
|
Output Tom's last hobby: guitar
|
||||||
```bash
|
```bash
|
||||||
scout read "Tom.hobbies[-1]" -i People.json
|
scout read -i People.json -f json "Tom.hobbies[-1]"
|
||||||
```
|
```
|
||||||
|
|
||||||
Output Suzanne first movie title: Tomorrow is so far
|
Output Suzanne first movie title: Tomorrow is so far
|
||||||
```bash
|
```bash
|
||||||
scout read "Suzanne.movies[0].title" -i People.yml
|
scout read -i People.yml -f yaml "Suzanne.movies[0].title"
|
||||||
```
|
```
|
||||||
|
|
||||||
Output Suzanne second movie title from the end: "Yesterday will never go"
|
Output Suzanne second movie title from the end: "Yesterday will never go"
|
||||||
```bash
|
```bash
|
||||||
scout read "Suzanne.movies[-2].title" -i People.yml
|
scout read -i People.yml -f yaml "Suzanne.movies[-2].title"
|
||||||
```
|
```
|
||||||
|
|
||||||
Output Robert running records second record first value: 9
|
Output Robert running records second record first value: 9
|
||||||
```bash
|
```bash
|
||||||
scout read "Robert.running_records[1][0]" -i People.json
|
scout read -i People.json -f json "Robert.running_records[1][0]"
|
||||||
```
|
```
|
||||||
|
|
||||||
The following:
|
The following:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout read "Tom" -i People.json
|
scout read -i People.json -f json "Tom"
|
||||||
```
|
```
|
||||||
outputs Tom dictionary:
|
outputs Tom dictionary:
|
||||||
|
|
||||||
|
@ -68,12 +68,12 @@ Get a dictionary or an array count with the `[#]` symbol.
|
||||||
|
|
||||||
Get people count: 3
|
Get people count: 3
|
||||||
```bash
|
```bash
|
||||||
scout read "[#]" -i People.plist
|
scout read -i People.plist -f plist "[#]"
|
||||||
```
|
```
|
||||||
|
|
||||||
Get Suzanne's movies count: 3
|
Get Suzanne's movies count: 3
|
||||||
```bash
|
```bash
|
||||||
scout read "Suzanne.movies[#]" -i People.xml
|
scout read -i People.xml -f xml "Suzanne.movies[#]"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Get a dictionary keys
|
### Get a dictionary keys
|
||||||
|
@ -82,13 +82,13 @@ You can get a dictionary or an array count with the `{#}` symbol. The keys are r
|
||||||
|
|
||||||
Get Tom dictionary keys list
|
Get Tom dictionary keys list
|
||||||
```bash
|
```bash
|
||||||
scout read -i People.yml "Tom{#}"
|
scout read -i People.yml -f yaml "Tom{#}"
|
||||||
```
|
```
|
||||||
|
|
||||||
Useful to iterate over a dictionary with the `--csv-sep` export option:
|
Useful to iterate over a dictionary with the `-e array` export option:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
keys=(`scout read -i People.json ”Tom{#}” —csv-sep ” ”`)
|
keys=(`scout read -i People.json -f json ”Tom{#}” —e array`)
|
||||||
|
|
||||||
for key in $keys; do
|
for key in $keys; do
|
||||||
scout read -i People.json ”Tom.$key”;
|
scout read -i People.json ”Tom.$key”;
|
||||||
|
@ -105,17 +105,17 @@ done
|
||||||
|
|
||||||
Get Robert first two hobbies
|
Get Robert first two hobbies
|
||||||
```bash
|
```bash
|
||||||
scout read -i People.json "Robert.hobbies[:1]"
|
scout read -i People.json -f json "Robert.hobbies[:1]"
|
||||||
```
|
```
|
||||||
|
|
||||||
Get Robert last two hobbies
|
Get Robert last two hobbies
|
||||||
```bash
|
```bash
|
||||||
scout read -i People.yml "Robert.hobbies[-2:]"
|
scout read -i People.yml -f yaml "Robert.hobbies[-2:]"
|
||||||
```
|
```
|
||||||
|
|
||||||
Get Suzanne movies titles
|
Get Suzanne movies titles
|
||||||
```bash
|
```bash
|
||||||
scout read -i People.plist "Suzanne.movies[:].title"
|
scout read -i People.plist -f plist "Suzanne.movies[:].title"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Dictionary filtering
|
#### Dictionary filtering
|
||||||
|
@ -124,19 +124,19 @@ scout read -i People.plist "Suzanne.movies[:].title"
|
||||||
|
|
||||||
Get Tom keys beginning by "h"
|
Get Tom keys beginning by "h"
|
||||||
```bash
|
```bash
|
||||||
scout read -i People.json "Tom.#h.*#"
|
scout read -i People.json -f json "Tom.#h.*#"
|
||||||
```
|
```
|
||||||
|
|
||||||
Get Tom and Robert hobbies
|
Get Tom and Robert hobbies
|
||||||
```bash
|
```bash
|
||||||
scout read -i People.xml "#Tom|Robert#.hobbies"
|
scout read -i People.xml -f xml "#Tom|Robert#.hobbies"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Mixing slicing and filtering
|
#### Mixing slicing and filtering
|
||||||
|
|
||||||
Get Tom and Robert first two hobbies
|
Get Tom and Robert first two hobbies
|
||||||
```bash
|
```bash
|
||||||
scout read -i People.yml "#Tom|Robert#.hobbies[:1]"
|
scout read -i People.yml -f yaml "#Tom|Robert#.hobbies[:1]"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set
|
## Set
|
||||||
|
@ -147,40 +147,49 @@ scout read -i People.yml "#Tom|Robert#.hobbies[:1]"
|
||||||
|
|
||||||
Set Robert age to: 60
|
Set Robert age to: 60
|
||||||
```bash
|
```bash
|
||||||
scout set "Robert.age"=60 -i People.plist
|
scout set -i People.plist -f plist "Robert.age=60"
|
||||||
```
|
```
|
||||||
|
|
||||||
Set Suzanne second movie title to: Never gonna die
|
Set Suzanne second movie title to: Never gonna die
|
||||||
```bash
|
```bash
|
||||||
scout set "Suzanne.movies[1].title"="Never gonna die" -i People.yml
|
scout set -i People.yml -f yaml "Suzanne.movies[1].title=Never gonna die"
|
||||||
```
|
```
|
||||||
|
|
||||||
Set Tom last hobby to "play music". Set Suzanne job to: comedian.
|
Set Tom last hobby to "play music". Set Suzanne job to: comedian.
|
||||||
```bash
|
```bash
|
||||||
scout set \
|
scout set -i People.plist -f plist \
|
||||||
"Tom.hobbies[-1]"="play music" \
|
"Tom.hobbies[-1]=play music" \
|
||||||
"Suzanne.job=comedian" \
|
"Suzanne.job=comedian"
|
||||||
-i People.plist
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Set Robert running records first record third value to: 15
|
Set Robert running records first record third value to: 15
|
||||||
```bash
|
```bash
|
||||||
scout set "Robert.running_records[0][2]"=15 -i People.xml
|
scout set -i People.xml -f xml "Robert.running_records[0][2]=15"
|
||||||
```
|
```
|
||||||
|
|
||||||
Set Tom height to the **String** value: 165
|
Set Tom height to the **String** value: 165
|
||||||
```bash
|
```bash
|
||||||
scout set "Tom.height=/165/" -i People.json
|
scout set -i People.json -f json "Tom.height=/165/"
|
||||||
```
|
```
|
||||||
|
|
||||||
Set Tom height to the **Real** value: 165 (only useful for Plist files)
|
Set Tom height to the **Real** value: 165 (only useful for Plist files)
|
||||||
```bash
|
```bash
|
||||||
scout set "Tom.height=~165~" -i People.plist
|
scout set -i People.plist -f plist "Tom.height=~165~"
|
||||||
```
|
```
|
||||||
|
|
||||||
Set Tom height key name to "centimeters"
|
Set Tom height key name to "centimeters"
|
||||||
```bash
|
```bash
|
||||||
scout set "Tom.height=#centimeters#" -i People.json
|
scout set -i People.json -f json "Tom.height=#centimeters#"
|
||||||
|
```
|
||||||
|
|
||||||
|
Set Suzanne first movie awards to an empty array
|
||||||
|
```bash
|
||||||
|
scout set -i People.yml -f yaml "Suzanne.movies[0].awards=[]"
|
||||||
|
```
|
||||||
|
|
||||||
|
Set Suzanne first movie awards to the array made of values: grammy, oscar, cesar
|
||||||
|
```bash
|
||||||
|
scout set -i People.yml -f yaml "Suzanne.movies[0].awards=[grammy, oscar, cesar]"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Delete
|
## Delete
|
||||||
|
@ -188,28 +197,28 @@ scout set "Tom.height=#centimeters#" -i People.json
|
||||||
- Will output an error if a key in the given path does not exist.
|
- Will output an error if a key in the given path does not exist.
|
||||||
- You can delete multiple values in one command.
|
- You can delete multiple values in one command.
|
||||||
- A negative index can be used to subscript an array starting from the end.
|
- A negative index can be used to subscript an array starting from the end.
|
||||||
- The `-r|--recursive` flag can be used to delete an rray or dictionary when it is left empty (i.e. it's last value has been deleted)
|
- The `-r|--recursive` flag can be used to delete an array or dictionary when it is left empty (i.e. it's last value has been deleted)
|
||||||
|
|
||||||
Delete Robert second hobby: party
|
Delete Robert second hobby: party
|
||||||
```bash
|
```bash
|
||||||
scout delete "Robert.hobbies[1]" -i People.xml
|
scout delete -i People.xml -f xml "Robert.hobbies[1]"
|
||||||
```
|
```
|
||||||
|
|
||||||
Delete Tom last hobby and Suzanne second movie awards
|
Delete Tom last hobby and Suzanne second movie awards
|
||||||
```bash
|
```bash
|
||||||
scout delete \
|
scout delete -i People.json -f json \
|
||||||
"Tom.hobbies[-1]" \
|
"Tom.hobbies[-1]" \
|
||||||
"Suzanne.movies[1].awards" \
|
"Suzanne.movies[1].awards"
|
||||||
-i People.json
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Delete Robert hobbies array
|
Delete Robert hobbies array
|
||||||
```bash
|
```bash
|
||||||
scout delete "Robert.hobbies" -i People.yml
|
scout delete -i People.yml -f yaml "Robert.hobbies"
|
||||||
```
|
```
|
||||||
|
|
||||||
Delete all Tom hobbies and recursively the hobbies array
|
Delete all Tom hobbies and recursively the hobbies array
|
||||||
```bash
|
```bash
|
||||||
scout delete "Tom.hobbies[1]" "Tom.hobbies[0]" -ir People.plist
|
scout delete -ir People.plist -f plist "Tom.hobbies[1]" "Tom.hobbies[0]"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Delete a group sample
|
### Delete a group sample
|
||||||
|
@ -222,22 +231,22 @@ scout delete "Tom.hobbies[1]" "Tom.hobbies[0]" -ir People.plist
|
||||||
|
|
||||||
Delete Robert first two hobbies
|
Delete Robert first two hobbies
|
||||||
```bash
|
```bash
|
||||||
scout delete -i People.json "Robert.hobbies[:1]"
|
scout delete -i People.json -f json "Robert.hobbies[:1]"
|
||||||
```
|
```
|
||||||
|
|
||||||
Delete Robert last two hobbies
|
Delete Robert last two hobbies
|
||||||
```bash
|
```bash
|
||||||
scout delete -i People.xml "Robert.hobbies[-2:]"
|
scout delete -i People.xml -f xml "Robert.hobbies[-2:]"
|
||||||
```
|
```
|
||||||
|
|
||||||
Delete Suzanne movies titles
|
Delete Suzanne movies titles
|
||||||
```bash
|
```bash
|
||||||
scout delete -i People.plist "Suzanne.movies[:].title"
|
scout delete -i People.plist -f plist "Suzanne.movies[:].title"
|
||||||
```
|
```
|
||||||
|
|
||||||
Delete Suzanne movies titles and remove the last movie element as it only as a "title" key with the `-r|--recursive` flag
|
Delete Suzanne movies titles and remove the last movie element as it only as a "title" key with the `-r|--recursive` flag
|
||||||
```bash
|
```bash
|
||||||
scout delete -ir People.plist "Suzanne.movies[:].title"
|
scout delete -ir People.plist -f plist "Suzanne.movies[:].title"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Dictionary filtering
|
#### Dictionary filtering
|
||||||
|
@ -246,65 +255,61 @@ scout delete -ir People.plist "Suzanne.movies[:].title"
|
||||||
|
|
||||||
Delete Tom keys beginning by "h"
|
Delete Tom keys beginning by "h"
|
||||||
```bash
|
```bash
|
||||||
scout delete -i People.xml "Tom.#h.*#"
|
scout delete -i People.xml -f xml "Tom.#h.*#"
|
||||||
```
|
```
|
||||||
|
|
||||||
Delete Tom and Robert hobbies
|
Delete Tom and Robert hobbies
|
||||||
```bash
|
```bash
|
||||||
scout delete -i People.plist "#Tom|Robert#.hobbies"
|
scout delete -i People.plist -f plist "#Tom|Robert#.hobbies"
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Mixing slicing and filtering
|
#### Mixing slicing and filtering
|
||||||
|
|
||||||
Delete Tom and Robert first two hobbies
|
Delete Tom and Robert first two hobbies
|
||||||
```bash
|
```bash
|
||||||
scout delete -i People.json "#Tom|Robert#.hobbies[:1]"
|
scout delete -i People.json -f json "#Tom|Robert#.hobbies[:1]"
|
||||||
```
|
```
|
||||||
|
|
||||||
Delete Tom and Robert first two hobbies and Tom hobbies key recursively
|
Delete Tom and Robert first two hobbies and Tom hobbies key recursively
|
||||||
```bash
|
```bash
|
||||||
scout delete -ir People.json "#Tom|Robert#.hobbies[:1]"
|
scout delete -ir People.json -f json "#Tom|Robert#.hobbies[:1]"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Add
|
## Add
|
||||||
- If a key in the given path does not exist, it will be created. Thus, to add a dictionary or an array, one child key has to be specified. Otherwise the program will consider that it is a single value that should be added.
|
- Only when a key is the last element in the path will it be created
|
||||||
|
- When an index is the last element in the path, the new value will be inserted at the index position
|
||||||
- A negative index can be used to subscript an array starting from the end.
|
- A negative index can be used to subscript an array starting from the end.
|
||||||
- Using the count element `[#]` after an array allows to specify that the value should be added at the end of the array
|
- Using the count element `[#]` after an array allows to specify that the value should be added at the end of the array
|
||||||
- You can set multiple values in one command.
|
- Multiple values can be set in one command.
|
||||||
|
|
||||||
Add a surname for Robert: Bob
|
Add a surname for Robert: Bob
|
||||||
```bash
|
```bash
|
||||||
scout add "Robert.surname"=Bob -i People.xml
|
scout add -i People.xml -f xml "Robert.surname=Bob"
|
||||||
```
|
```
|
||||||
|
|
||||||
Add a movie to Suzanne's movies with the title: "Never gonna die"
|
Add a movie to Suzanne's movies with the title: "Never gonna die"
|
||||||
```bash
|
```bash
|
||||||
scout add "Suzanne.movies[#].title"="Never gonna die" -i People.json
|
scout add -i People.json -f json \
|
||||||
```
|
"Suzanne.movies[#]={}" \
|
||||||
|
"Suzanne.movies[-1].title=Never gonna die"
|
||||||
Add a new array for Suzanne with one element: Candies. Add a new surname for Robert: Bob. Add a new hobby for Tom at the end of the hobbies array: sleeping.
|
|
||||||
```bash
|
|
||||||
scout add \
|
|
||||||
"Suzanne.secretLoves[0]=Candies" \
|
|
||||||
"Robert.surname=Bob" \
|
|
||||||
"Tom.hobbies[#]=sleeping" \
|
|
||||||
-i People.plist
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Add a new value at the end of the array to Robert running records second record
|
Add a new value at the end of the array to Robert running records second record
|
||||||
```bash
|
```bash
|
||||||
scout add "Robert.running_records[1][#]"=20 -i People.yml
|
scout add -i People.yml -f yaml "Robert.running_records[1][#]=20"
|
||||||
```
|
```
|
||||||
|
|
||||||
(Tricky one) Add a new record to Robert running records and add a new value into it: 15
|
Add a new record to Robert running records and add a new value into it: 15
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout add "Robert.running_records[#][0]"=15 -i People.xml
|
scout add -i People.xml -f xml \
|
||||||
|
"Robert.running_records[#]=[]" \
|
||||||
|
"Robert.running_records[-1][#]=15"
|
||||||
```
|
```
|
||||||
|
|
||||||
Add a new **String** value at the end the array to Robert running records first record
|
Add a new **String** value at the end the array to Robert running records first record
|
||||||
```bash
|
```bash
|
||||||
scout add "Robert.running_records[0][#]=/15/" -i People.plist
|
scout add -i People.plist -f plist "Robert.running_records[0][#]='15'"
|
||||||
```
|
```
|
||||||
|
|
||||||
## Listing paths
|
## Listing paths
|
||||||
|
@ -316,7 +321,7 @@ scout add "Robert.running_records[0][#]=/15/" -i People.plist
|
||||||
|
|
||||||
List all the paths in the data
|
List all the paths in the data
|
||||||
```bash
|
```bash
|
||||||
scout paths -i People.yml
|
scout paths -i People.yml -f yaml
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```
|
```
|
||||||
|
@ -359,7 +364,7 @@ Tom.hobbies[1]
|
||||||
List all the paths ending with a "hobbies" key.
|
List all the paths ending with a "hobbies" key.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout paths -i People.xml -k "hobbies"
|
scout paths -i People.xml -f xml -k "hobbies"
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```
|
```
|
||||||
|
@ -375,7 +380,7 @@ Tom.hobbies[1]
|
||||||
List all the paths ending with a "hobbies" key and whose value is a single value
|
List all the paths ending with a "hobbies" key and whose value is a single value
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout paths -i People.plist -k "hobbies" --single
|
scout paths -i People.plist -f plist -k "hobbies" --single
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```
|
```
|
||||||
|
@ -389,7 +394,7 @@ Tom.hobbies[1]
|
||||||
List all the paths whose value is below 70
|
List all the paths whose value is below 70
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout paths -i People.yml -v "value < 70"
|
scout paths -i People.yml -f yaml -v "value < 70"
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```
|
```
|
||||||
|
@ -407,7 +412,7 @@ Tom.age
|
||||||
List all the paths whose value is above 20 and below 70
|
List all the paths whose value is above 20 and below 70
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout paths -i People.json -v "value > 20 && value < 70"
|
scout paths -i People.json -f json -v "value > 20 && value < 70"
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```
|
```
|
||||||
|
@ -418,7 +423,7 @@ Tom.age
|
||||||
List all the paths whose value is below 70 and whose key start with "a"
|
List all the paths whose value is below 70 and whose key start with "a"
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout paths -i People.yml -v "value < 70" -k "a.*"
|
scout paths -i People.yml -f yaml -v "value < 70" -k "a.*"
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```
|
```
|
||||||
|
@ -429,7 +434,7 @@ Tom.age
|
||||||
List all the paths in Tom dictionary
|
List all the paths in Tom dictionary
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout paths -i People.plist "Tom"
|
scout paths -i People.plist -f plist "Tom"
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```
|
```
|
||||||
|
@ -443,7 +448,7 @@ Tom.hobbies[1]
|
||||||
List all the paths in Tom and Robert dictionaries leading to group values
|
List all the paths in Tom and Robert dictionaries leading to group values
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout paths -i People.xml "#Tom|Robert#" --group
|
scout paths -i People.xml -f xml "#Tom|Robert#" --group
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```
|
```
|
||||||
|
@ -459,7 +464,7 @@ Tom.hobbies
|
||||||
List the paths leading to Suzanne first two movies titles.
|
List the paths leading to Suzanne first two movies titles.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout paths -i People.yml "Suzanne.movies[:1].title"
|
scout paths -i People.yml -f yaml "Suzanne.movies[:1].title"
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
```
|
```
|
||||||
|
@ -476,44 +481,93 @@ The conversion from XML can change the data structure when a tag has one ore mor
|
||||||
|
|
||||||
Output the file People.json as Plist
|
Output the file People.json as Plist
|
||||||
```
|
```
|
||||||
scout read -i People.json -e plist
|
scout read -i People.json -f json -e plist
|
||||||
```
|
```
|
||||||
or
|
or
|
||||||
|
|
||||||
```
|
```
|
||||||
scout -i People.json -e plist
|
scout -i People.json -f json -e plist
|
||||||
```
|
```
|
||||||
|
|
||||||
Set a key and output the data as XML
|
Set a key and output the data as XML
|
||||||
```
|
```
|
||||||
scout set "Robert.age=30" -i People.yml -e xml
|
scout set "Robert.age=30" -i People.yml -f yaml -e xml
|
||||||
```
|
```
|
||||||
|
|
||||||
Delete a key and output the data as JSON
|
Delete a key and output the data as JSON
|
||||||
```bash
|
```bash
|
||||||
scout delete "Robert.age" -i People.xml -e json
|
scout delete "Robert.age" -i People.xml -f xml -e json
|
||||||
```
|
```
|
||||||
|
|
||||||
### CSV
|
### CSV export
|
||||||
Output an array or a dictionary of arrays as CSV with the `--csv` flag or `--csv-sep` option.
|
Output an array or a dictionary of arrays as CSV with the `--csv-exp` option.
|
||||||
|
|
||||||
Output Robbert's hobbies as CSV with the default separator.
|
Output Robbert's hobbies as CSV with the default separator.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout read -i People.json "Robert.hobbies" --csv
|
scout read -i People.json "Robert.hobbies" --csv-exp ";"
|
||||||
```
|
```
|
||||||
will output
|
will output
|
||||||
|
|
||||||
```
|
```
|
||||||
video games;party;tennis
|
video games;party;tennis
|
||||||
```
|
```
|
||||||
will output
|
|
||||||
```bash
|
|
||||||
scout read -i People.json "#Robert|Tom#.hobbies" --csv-sep " "
|
|
||||||
```
|
|
||||||
will output
|
|
||||||
|
|
||||||
|
|
||||||
|
### CSV import
|
||||||
|
The `csv` command will import a CSV input to JSON, Plist, YAML or XML.
|
||||||
|
A cool feature when working with named headers is that they will be treated as paths. This can shape very precisely the structure of the converted data.
|
||||||
|
For instance, the following CSV
|
||||||
|
|
||||||
|
```csv
|
||||||
|
name.first;name.last;hobbies[0];hobbies[1]
|
||||||
|
Robert;Roni;acting;driving
|
||||||
|
Suzanne;Calvin;singing;play
|
||||||
|
Tom;Cattle;surfing;watching movies
|
||||||
```
|
```
|
||||||
Tom_hobbies cooking guitar
|
|
||||||
Robert_hobbies "video games" party tennis
|
will be converted to the following Json structure.
|
||||||
|
|
||||||
|
```json
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"hobbies" : [
|
||||||
|
"acting",
|
||||||
|
"driving"
|
||||||
|
],
|
||||||
|
"name" : {
|
||||||
|
"first" : "Robert",
|
||||||
|
"last" : "Roni"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hobbies" : [
|
||||||
|
"singing",
|
||||||
|
"play"
|
||||||
|
],
|
||||||
|
"name" : {
|
||||||
|
"first" : "Suzanne",
|
||||||
|
"last" : "Calvin"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name" : {
|
||||||
|
"first" : "Tom",
|
||||||
|
"last" : "Cattle"
|
||||||
|
},
|
||||||
|
"hobbies" : [
|
||||||
|
"surfing",
|
||||||
|
"watching movies"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
When there are no headers, the input will be treated as a one or two dimension(s) array.
|
||||||
|
|
||||||
|
#### Command-line
|
||||||
|
```bash
|
||||||
|
scout csv -i people.csv -s ";" -f json --headers
|
||||||
|
```
|
||||||
|
|
||||||
|
The `headers|--no-headers` flag is needed to specify whether the CSV string begins with named headers.
|
||||||
|
It’s also possible to use the standard input to provide the CSV data.
|
23
README.md
23
README.md
|
@ -54,8 +54,8 @@ Supported formats:
|
||||||
The wiki can be found [here](https://www.woodys-findings.com/scout/wiki/home).
|
The wiki can be found [here](https://www.woodys-findings.com/scout/wiki/home).
|
||||||
|
|
||||||
### News
|
### News
|
||||||
- Checkout what's new in **Scout** 3.0.0 [here](https://www.woodys-findings.com/scout/news-3.0.0).
|
- Checkout what's new in **Scout** 4.0.0 [here](https://www.woodys-findings.com/scout/news-4.0.0).
|
||||||
- Checkout what's new in **Scout** 2.0.0 [here](https://www.woodys-findings.com/scout/news-2.0.0).
|
- Checkout what’s new in **Scout** 3.0.0 [here](https://www.woodys-findings.com/scout/news-3.0.0).
|
||||||
|
|
||||||
## Why?
|
## Why?
|
||||||
|
|
||||||
|
@ -81,6 +81,7 @@ Don't get me wrong, **awk** is a wonderful tool. It can do so many things. But i
|
||||||
- Force a type
|
- Force a type
|
||||||
- Dictionary and array count
|
- Dictionary and array count
|
||||||
- Dictionary keys
|
- Dictionary keys
|
||||||
|
- XML attributes reading
|
||||||
- Delete array or dictionary when deleting all its values
|
- Delete array or dictionary when deleting all its values
|
||||||
- Array slicing for *read* and *delete* commands
|
- Array slicing for *read* and *delete* commands
|
||||||
- Dictionary filtering for *read* and *delete* commands
|
- Dictionary filtering for *read* and *delete* commands
|
||||||
|
@ -89,6 +90,8 @@ Don't get me wrong, **awk** is a wonderful tool. It can do so many things. But i
|
||||||
- Find best match in case of a typo
|
- Find best match in case of a typo
|
||||||
- Data formats conversion (e.g. JSON -> Plist, YAML -> XML)
|
- Data formats conversion (e.g. JSON -> Plist, YAML -> XML)
|
||||||
- CSV export for arrays and dictionaries of arrays
|
- CSV export for arrays and dictionaries of arrays
|
||||||
|
- CSV import with precise data structure shaping
|
||||||
|
- Export to a Zsh array or associative array
|
||||||
- Syntax highlighting
|
- Syntax highlighting
|
||||||
- Folding at a depth level
|
- Folding at a depth level
|
||||||
- Auto-completion for commands
|
- Auto-completion for commands
|
||||||
|
@ -138,9 +141,9 @@ You can [learn more](https://www.woodys-findings.com/scout/wiki/list-paths) abou
|
||||||
#### Stream or file input
|
#### Stream or file input
|
||||||
Set the input as a file with the input option `-i | --input` or as the last process/command output with a pipe:
|
Set the input as a file with the input option `-i | --input` or as the last process/command output with a pipe:
|
||||||
```bash
|
```bash
|
||||||
scout "path.to.value" -i File
|
scout "path.to.value" -i File.yml -f yaml
|
||||||
# is the same as
|
# is the same as
|
||||||
cat File | scout "path.to.value"
|
cat File | scout "path.to.value" -f yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Find best match in case of a typo
|
#### Find best match in case of a typo
|
||||||
|
@ -158,7 +161,7 @@ curl --silent "https://api.github.com/repos/ABridoux/scout/releases/latest" | sc
|
||||||
Another example with one of the playground files and the following command:
|
Another example with one of the playground files and the following command:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
scout -i People.plist "people.Robert.age=2"
|
scout read -i People.plist -f plist "people.Robert.age=2"
|
||||||
```
|
```
|
||||||
|
|
||||||
When dealing with large files (although it is not recommended to output large files in the terminal), highlighting the output might bring to slowdowns. It's possible to deactivate the colorisation with the flag `--no-color` or `--nc`. This is automatic when writing the output in a file or when the program output is piped.
|
When dealing with large files (although it is not recommended to output large files in the terminal), highlighting the output might bring to slowdowns. It's possible to deactivate the colorisation with the flag `--no-color` or `--nc`. This is automatic when writing the output in a file or when the program output is piped.
|
||||||
|
@ -168,7 +171,13 @@ The library offer a conversion feature from a supported format to another one li
|
||||||
[Learn more](https://www.woodys-findings.com/scout/wiki/conversion)
|
[Learn more](https://www.woodys-findings.com/scout/wiki/conversion)
|
||||||
|
|
||||||
#### CSV export
|
#### CSV export
|
||||||
Export data when dealing with arrays or a dictionary of arrays. Default separator ';' or customisable.
|
Export data when dealing with arrays or a dictionary of arrays.
|
||||||
|
|
||||||
|
#### CSV import
|
||||||
|
Convert CSV input to one of the available formats. When the CSV has named headers, specify how the data structure should be built (array, dictionary) using paths.
|
||||||
|
|
||||||
|
#### Zsh arrays
|
||||||
|
Export a 1-dimension array to a Zsh array with the `-e array` option and to an associative array with the `-e dictionary` option.
|
||||||
|
|
||||||
##### Customise colors
|
##### Customise colors
|
||||||
You can specify your own colors set as explained [here](https://www.woodys-findings.com/scout/wiki/highlighting). Also, some presets for the macOS terminal default styles can be found in the [Highlight presets folder](Highlight-presets)
|
You can specify your own colors set as explained [here](https://www.woodys-findings.com/scout/wiki/highlighting). Also, some presets for the macOS terminal default styles can be found in the [Highlight presets folder](Highlight-presets)
|
||||||
|
@ -254,7 +263,7 @@ The same goes for the [Yams](https://www.woodys-findings.com/scout/wiki/home) an
|
||||||
|
|
||||||
Thanks also to the team at Apple behind the [ArgumentParser](https://github.com/apple/swift-argument-parser) library. They have done an incredible work to make command line tools in Swift easy to implement.
|
Thanks also to the team at Apple behind the [ArgumentParser](https://github.com/apple/swift-argument-parser) library. They have done an incredible work to make command line tools in Swift easy to implement.
|
||||||
|
|
||||||
Finally, thanks to [Thijs Xhaflaire](https://github.com/txhaflaire/) and [Armin Briegel](https://github.com/scriptingosx) for your ideas and your helpful feedback.
|
Finally, thanks to [Thijs Xhaflaire](https://github.com/txhaflaire/) and [Armin Briegel](https://github.com/scriptingosx) for their ideas and helpful feedback.
|
||||||
|
|
||||||
### References
|
### References
|
||||||
Font used for the logo: Ver Army by [Damien Gosset](http://sweeep.fr/cv/index.php?c=fonts).
|
Font used for the logo: Ver Army by [Damien Gosset](http://sweeep.fr/cv/index.php?c=fonts).
|
||||||
|
|
|
@ -4,5 +4,5 @@
|
||||||
// MIT license, see LICENSE file for details
|
// MIT license, see LICENSE file for details
|
||||||
|
|
||||||
public enum ScoutVersion {
|
public enum ScoutVersion {
|
||||||
public static let current = "3.0.3"
|
public static let current = "4.0.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ extension AEXMLElement {
|
||||||
return newElement
|
return newElement
|
||||||
}
|
}
|
||||||
|
|
||||||
children.forEach { newElement.addChild($0.copyFlat()) }
|
children.forEach { newElement.addChild($0.copy()) }
|
||||||
return newElement
|
return newElement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue