-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
93 lines (77 loc) · 2.46 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"fmt"
"log/slog"
"os"
"time"
"flows2fim/cmd/controls"
"flows2fim/cmd/fim"
"flows2fim/cmd/validate"
"flows2fim/internal/config"
"github.com/lmittmann/tint"
"github.com/mattn/go-isatty"
)
var usage string = `Usage of flows2fim:
flows2fim [--version | --help]
flows2fim COMMAND --help
flows2fim COMMAND Args
Available 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.
Dependencies:
- GDAL must be installed and available in the PATH.
Env Variables:
- F2F_LOG_LEVEL: Set the logging level. Options are 'DEBUG', 'INFO', 'WARN', and 'ERROR'. Default is 'INFO'.
- F2F_NO_COLOR: Set to 'TRUE' to disable colored output. Default is 'FALSE'.
CLI Flag Syntax:
The following forms are permitted:
-flag
--flag // double dashes are also permitted
-flag=x
-flag x // non-boolean flags only
`
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) {
if len(args) < 2 {
return fmt.Errorf("missing command. See flows2fim --help for available commands")
}
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:
err = fmt.Errorf("unknown command %s see flows2fim --help for available commands", args[1])
}
return err
}
func main() {
config.LoadConfig()
w := os.Stderr
logger := slog.New(tint.NewHandler(w, &tint.Options{
Level: config.LogLevel(),
TimeFormat: time.Kitchen,
NoColor: !isatty.IsTerminal(w.Fd()) || config.NoColor(),
}))
slog.SetDefault(logger)
if err := run(os.Args); err != nil {
fmt.Fprint(os.Stderr, err, "\n")
os.Exit(1)
}
os.Exit(0)
}