Skip to content

Commit 998e936

Browse files
committed
basics of readme for cli project
This project is going to change so we don't have to make a parser
1 parent 6b22be9 commit 998e936

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

cli-files/README.md

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# CLI & Files
22

3-
Become familiar with go and the toolchain by building a JSON-file reading CLI tool: `get-data path/to/file --path "foo.bar[0].baz"`
3+
Become familiar with go and the toolchain by building a JSON-file reading CLI tool: `get-data ".flowers[0].name" garden.json`
44

55
Timebox: 4 days
66

@@ -16,4 +16,51 @@ Objectives:
1616
- Extract data from a JSON file and print it to the CLI
1717
- Add support for YAML
1818

19+
## Instructions
20+
21+
You're going to build a command-line application that reads data from files.
22+
23+
Let's say you have a `garden.json` file like this, containing data about what's growing in our garden:
24+
25+
```json
26+
{
27+
"flowers": [
28+
{
29+
"name": "Great Maiden's Blush",
30+
"genus": "Rosa",
31+
"species": "Rosa × alba",
32+
"color": "white",
33+
"height": 2.2
34+
},
35+
{
36+
"name": "Bright Gem",
37+
"genus": "Tulipa",
38+
"species": "Tulipa linifolia",
39+
"color": "Yellow/orange",
40+
"height": 0.17
41+
},
42+
{
43+
"name": "Elizabeth",
44+
"genus": "Magnolia",
45+
"species": "M. acuminata × M. denudata",
46+
"color": "Pale yellow",
47+
"height": 9.6
48+
}
49+
]
50+
}
51+
```
52+
53+
The tool you will build will extra data from this file. Here are some examples:
54+
55+
```bash
56+
> get-data ".flowers[0].name" garden.json
57+
"Great Maiden's Blush"
58+
59+
> get-data ".flowers[1].height" garden.json
60+
2.2
61+
62+
> get-data ".flowers[2]" garden.json
63+
{"name": "Elizabeth", "genus": "Magnolia", "species": "M. acuminata × M. denudata", "color": "Pale yellow", "height": 9.6 }
64+
```
65+
1966
[cobra]: https://github.com/spf13/cobra#overview

cli-files/assets/garden.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"flowers": [
3+
{
4+
"name": "Great Maiden's Blush",
5+
"genus": "Rosa",
6+
"species": "Rosa × alba",
7+
"color": "white",
8+
"height": 2.2
9+
},
10+
{
11+
"name": "Bright Gem",
12+
"genus": "Tulipa",
13+
"species": "Tulipa linifolia",
14+
"color": "Yellow/orange",
15+
"height": 0.17
16+
},
17+
{
18+
"name": "Elizabeth",
19+
"genus": "Magnolia",
20+
"species": "M. acuminata × M. denudata",
21+
"color": "Pale yellow",
22+
"height": 9.6
23+
}
24+
]
25+
}

0 commit comments

Comments
 (0)