forked from ar-siddiqui/flows2fim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
72 lines (61 loc) · 1.9 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"fmt"
"os"
"flows2fim/cmd/controls"
"flows2fim/cmd/fim"
"flows2fim/cmd/validate"
"flows2fim/internal/config"
)
var usage string = `Usage of flows2fim:
flows2fim [--version | --help]
flows2fim COMMAND --help
flows2fim COMMAND Args
Commands:
- controls: Given a flow file and a rating curves database, create a control table of reach flows and downstream boundary conditions.
- fim: Given a control table and a fim library folder, create a flood inundation map for the control conditions.
- validate: Given a fim library folder and a rating curves database, validate there is one to one correspondence between the entries of rating curves table and fim library objects.
Notes:
- 'fim' and 'validate' commands need access to GDAL programs. They must be installed separately and available in the system's PATH.
`
var (
GitTag = "unknown" // will be injected at build-time
GitCommit = "unknown" // will be injected at build-time
BuildDate = "unknown" // will be injected at build-time
)
// run handles the main logic and returns an error if something goes wrong.
func run(args []string) (err error) {
config.LoadConfig()
if len(args) < 2 {
fmt.Println("Please provide a command")
fmt.Print(usage)
err = fmt.Errorf("missing command")
return err
}
switch args[1] {
case "-v", "--v", "-version", "--version":
fmt.Println("Software: flows2fim")
fmt.Println("Version:", GitTag)
fmt.Println("Commit:", GitCommit)
fmt.Println("Build Date:", BuildDate)
case "-h", "--h", "-help", "--help":
fmt.Print(usage)
case "controls":
err = controls.Run(args[2:])
case "fim":
_, err = fim.Run(args[2:])
case "validate":
err = validate.Run(args[2:])
default:
fmt.Println("Unknown command:", args[1])
err = fmt.Errorf("unknown command")
}
return err
}
func main() {
if err := run(os.Args); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
os.Exit(0)
}