File tree Expand file tree Collapse file tree 4 files changed +79
-6
lines changed Expand file tree Collapse file tree 4 files changed +79
-6
lines changed Original file line number Diff line number Diff line change 1+ # jq
2+
3+ > A command-line JSON processor that uses a domain-specific language.
4+ > More information: < https://stedolan.github.io/jq > .
5+
6+ - Output a JSON file, in pretty-print format:
7+
8+ ` jq . {{file.json}} `
9+
10+ - Output all elements from arrays (or all the values from objects) in a JSON file:
11+
12+ ` jq '.[]' {{file.json}} `
13+
14+ - Read JSON objects from a file into an array, and output it (inverse of ` jq .[] ` ):
15+
16+ ` jq --slurp . {{file.json}} `
17+
18+ - Output the first element in a JSON file:
19+
20+ ` jq '.[0]' {{file.json}} `
21+
22+ - Output the value of a given key of each element in a JSON text from stdin:
23+
24+ ` cat {{file.json}} | jq 'map(.{{key_name}})' `
25+
26+ - Output the value of multiple keys as a new JSON object (assuming the input JSON has the keys ` key_name ` and ` other_key_name ` ):
27+
28+ ` cat {{file.json}} | jq '{{{my_new_key}}: .{{key_name}}, {{my_other_key}}: .{{other_key_name}}}' `
29+
30+ - Combine multiple filters:
31+
32+ ` cat {{file.json}} | jq 'unique | sort | reverse' `
33+
34+ - Output the value of a given key to a string (and disable JSON output):
35+
36+ ` cat {{file.json}} | jq --raw-output '"some text: \(.{{key_name}})"' `
37+
Original file line number Diff line number Diff line change 1+
2+ [1mjq[0m
3+
4+ A command-line JSON processor that uses a domain-specific language.[0m
5+ More information: https://stedolan.github.io/jq.[0m
6+
7+ [32m- Output a JSON file, in pretty-print format:[0m
8+ [31mjq . [0mfile.json[0m[31m[0m
9+
10+ [32m- Output all elements from arrays (or all the values from objects) in a JSON file:[0m
11+ [31mjq '.[]' [0mfile.json[0m[31m[0m
12+
13+ [32m- Read JSON objects from a file into an array, and output it (inverse of `jq .[]`):[0m
14+ [31mjq --slurp . [0mfile.json[0m[31m[0m
15+
16+ [32m- Output the first element in a JSON file:[0m
17+ [31mjq '.[0]' [0mfile.json[0m[31m[0m
18+
19+ [32m- Output the value of a given key of each element in a JSON text from stdin:[0m
20+ [31mcat [0mfile.json[0m[31m | jq 'map(.[0mkey_name[0m[31m)'[0m
21+
22+ [32m- Output the value of multiple keys as a new JSON object (assuming the input JSON has the keys `key_name` and `other_key_name`):[0m
23+ [31mcat [0mfile.json[0m[31m | jq '[0m{my_new_key[0m[31m: .[0mkey_name[0m[31m, [0mmy_other_key[0m[31m: .[0mother_key_name[0m}[31m'[0m
24+
25+ [32m- Combine multiple filters:[0m
26+ [31mcat [0mfile.json[0m[31m | jq 'unique | sort | reverse'[0m
27+
28+ [32m- Output the value of a given key to a string (and disable JSON output):[0m
29+ [31mcat [0mfile.json[0m[31m | jq --raw-output '"some text: \(.[0mkey_name[0m[31m)"'[0m
30+
Original file line number Diff line number Diff line change 66import types
77from unittest import mock
88
9+ # gem is a basic test of page rendering
10+ # jq is a more complicated test for token parsing
11+ page_names = ('gem' , 'jq' )
912
10- def test_whole_page ():
11- with open ("tests/data/gem.md" , "rb" ) as f_original :
12- with open ("tests/data/gem_rendered" , "rb" ) as f_rendered :
13+
14+ @pytest .mark .parametrize ("page_name" , page_names )
15+ def test_whole_page (page_name ):
16+ with open (f"tests/data/{ page_name } .md" , "rb" ) as f_original :
17+ with open (f"tests/data/{ page_name } _rendered" , "rb" ) as f_rendered :
1318 old_stdout = sys .stdout
1419 sys .stdout = io .StringIO ()
1520 sys .stdout .buffer = types .SimpleNamespace ()
@@ -24,8 +29,9 @@ def test_whole_page():
2429 assert tldr_output == correct_output
2530
2631
27- def test_markdown_mode ():
28- with open ("tests/data/gem.md" , "rb" ) as f_original :
32+ @pytest .mark .parametrize ("page_name" , page_names )
33+ def test_markdown_mode (page_name ):
34+ with open (f"tests/data/{ page_name } .md" , "rb" ) as f_original :
2935 d_original = f_original .read ()
3036 old_stdout = sys .stdout
3137 sys .stdout = io .StringIO ()
Original file line number Diff line number Diff line change @@ -296,7 +296,7 @@ def get_page(
296296
297297LEADING_SPACES_NUM = 2
298298
299- COMMAND_SPLIT_REGEX = re .compile (r'(?P<param>{{.+?}})' )
299+ COMMAND_SPLIT_REGEX = re .compile (r'(?P<param>{{.+?}*} })' )
300300PARAM_REGEX = re .compile (r'(?:{{)(?P<param>.+?)(?:}})' )
301301
302302
You can’t perform that action at this time.
0 commit comments