You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Become familiar with go and the toolchain by building a JSON-file reading CLI tool: `get-data ".flowers[0].name" garden.json`
3
+
In this project you're going to get familiar with the [Go programming language][go] by rebuilding two very common tools that programmers and computer administrators use all the time: [cat][cat] and [ls][ls].
4
4
5
5
Timebox: 4 days
6
6
@@ -11,56 +11,57 @@ Objectives:
11
11
- Understand what a process is & the basics of process - lifecycle
12
12
- Accept arguments on the CLI
13
13
- Open, read (and close) files from CLI arguments
14
-
- Learn about JSON and parsing
15
-
- Read strings from arguments
16
-
- Extract data from a JSON file and print it to the CLI
17
-
- Add support for YAML
14
+
- Reading directories for files
18
15
19
16
## Instructions
20
17
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
-
}
18
+
You're going to build a command-line application that reads data the computers file system.
19
+
20
+
Let's say you have a few files containing poems in a directory:
21
+
22
+
-`dew.txt`
23
+
-`for_you.txt`
24
+
-`rain.txt`
25
+
26
+
The `ls` tool will list the files in that directory:
27
+
28
+
```
29
+
> ls
30
+
dew.txt
31
+
for_you.txt
32
+
rain.txt
51
33
```
52
34
53
-
The tool you will build will extra data from this file. Here are some examples:
35
+
While the `cat` command will output the contents of a file to you:
36
+
37
+
```
38
+
> cat dew.txt
39
+
“A World of Dew” by Kobayashi Issa
40
+
41
+
A world of dew,
42
+
And within every dewdrop
43
+
A world of struggle.
44
+
```
45
+
46
+
As you can see, `cat` takes an argument, namely the file to be written out. You'll learn how to do this too.
0 commit comments