/
root.go
98 lines (81 loc) · 2.81 KB
/
root.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
94
95
96
97
98
/*
Copyright © 2013 the InMAP authors.
This file is part of InMAP.
InMAP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
InMAP is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with InMAP. If not, see <http://www.gnu.org/licenses/>.
*/
// Package cmd contains commands and subcommands for the InMAP command-line interface.
package cmd
import (
"fmt"
"github.com/spatialmodel/inmap"
"github.com/spf13/cobra"
)
const year = "2016"
var (
configFile string
// Config holds the global configuration data.
Config *ConfigData
)
// RootCmd is the main command.
var RootCmd = &cobra.Command{
Use: "inmap",
Short: "A reduced-form air quality model.",
Long: `InMAP is a reduced-form air quality model for fine particulate matter (PM2.5).
Use the subcommands specified below to access the model functionality.
Additional information is available at http://inmap.spatialmodel.com.`,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return labelErr(Startup(configFile))
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
completedMessage()
},
}
// Startup reads the configuration file and prints a welcome message.
func Startup(configFile string) error {
var err error
Config, err = ReadConfigFile(configFile)
if err != nil {
return err
}
fmt.Println("\n" +
"------------------------------------------------\n" +
" Welcome!\n" +
" (In)tervention (M)odel for (A)ir (P)ollution \n" +
" Version " + inmap.Version + " \n" +
" Copyright 2013-" + year + " \n" +
" the InMAP Authors \n" +
"------------------------------------------------")
return nil
}
func completedMessage() {
fmt.Println("\n" +
"------------------------------------\n" +
" InMAP Completed!\n" +
"------------------------------------")
}
func init() {
RootCmd.AddCommand(versionCmd)
RootCmd.PersistentFlags().StringVar(&configFile, "config", "./inmap.toml", "configuration file location")
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number",
Long: "version prints the version number of this version of InMAP.",
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("InMAP v%s\n", inmap.Version)
},
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
return nil
},
PersistentPostRun: func(cmd *cobra.Command, args []string) {
},
}