forked from bitstrapped/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmdparser.go
59 lines (53 loc) · 1.21 KB
/
cmdparser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package airbyte
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
)
func getSourceConfigPath() (string, error) {
if os.Args[2] != "--config" {
return "", fmt.Errorf("expect --config")
}
return os.Args[3], nil
}
func getStatePath() (string, error) {
if len(os.Args) <= 6 {
return "", nil
}
if os.Args[6] != "--state" {
return "", fmt.Errorf("expect --state")
}
return os.Args[7], nil
}
func getCatalogPath() (string, error) {
if os.Args[4] != "--catalog" {
return "", fmt.Errorf("expect --catalog")
}
return os.Args[5], nil
}
// UnmarshalFromPath is used to unmarshal json files into respective struct's
// this is most commonly used to unmarshal your State between runs and also unmarshal SourceConfig's
//
// Example usage
// type CustomState struct {
// Timestamp int `json:"timestamp"`
// Foobar string `json:"foobar"`
// }
//
// func (s *CustomSource) Read(stPath string, ...) error {
// var cs CustomState
// err = airbyte.UnmarshalFromPath(stPath, &cs)
// if err != nil {
// // handle error
// }
// // cs is populated
// }
//
func UnmarshalFromPath(path string, v interface{}) error {
b, err := ioutil.ReadFile(path)
if err != nil {
return err
}
return json.Unmarshal(b, v)
}