]> ruderich.org/simon Gitweb - nsscash/nsscash.git/blob - main.go
nsscash: go fmt
[nsscash/nsscash.git] / main.go
1 // Main file for nsscash
2
3 // Copyright (C) 2019  Simon Ruderich
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU Affero General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 // GNU Affero General Public License for more details.
14 //
15 // You should have received a copy of the GNU Affero General Public License
16 // along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
18 package main
19
20 import (
21         "flag"
22         "fmt"
23         "log"
24         "os"
25 )
26
27 func main() {
28         flag.Usage = func() {
29                 fmt.Fprintf(os.Stderr,
30                         "usage: %[1]s [options] fetch <config>\n"+
31                                 "",
32                         os.Args[0])
33                 flag.PrintDefaults()
34         }
35         flag.Parse()
36
37         args := flag.Args()
38         if len(args) == 0 {
39                 flag.Usage()
40                 os.Exit(1)
41         }
42
43         switch args[0] {
44         case "fetch":
45                 if len(args) != 2 {
46                         break
47                 }
48
49                 cfg, err := LoadConfig(args[1])
50                 if err != nil {
51                         log.Fatal(err)
52                 }
53                 state, err := LoadState(cfg.StatePath)
54                 if err != nil {
55                         log.Fatal(err)
56                 }
57
58                 err = handleFiles(cfg, state)
59                 if err != nil {
60                         log.Fatal(err)
61                 }
62
63                 err = WriteStateIfChanged(cfg.StatePath, state)
64                 if err != nil {
65                         log.Fatal(err)
66                 }
67
68                 return
69         }
70
71         flag.Usage()
72         os.Exit(1)
73 }