2 NNCP -- Node to Node copy, utilities for store-and-forward data exchange
3 Copyright (C) 2016-2021 Sergey Matveev <stargrave@stargrave.org>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, version 3 of the License.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 // Convert NNCP Hjson configuration file to the directory layout.
28 "github.com/hjson/hjson-go"
29 "go.cypherpunks.ru/nncp/v8"
33 fmt.Fprintf(os.Stderr, nncp.UsageHeader())
34 fmt.Fprintf(os.Stderr, "nncp-cfgdir -- Convert configuration file to the directory layout.\n\n")
35 fmt.Fprintf(os.Stderr, "Usage: %s [options] [-cfg ...] -dump /path/to/dir\n", os.Args[0])
36 fmt.Fprintf(os.Stderr, " %s [options] -load /path/to/dir > cfg.hjson\nOptions:\n", os.Args[0])
42 doDump = flag.Bool("dump", false, "Dump configuration file to the directory")
43 doLoad = flag.Bool("load", false, "Load directory to create configuration file")
44 cfgPath = flag.String("cfg", nncp.DefaultCfgPath, "Path to configuration file")
45 version = flag.Bool("version", false, "Print version information")
46 warranty = flag.Bool("warranty", false, "Print warranty information")
48 log.SetFlags(log.Lshortfile)
52 fmt.Println(nncp.Warranty)
56 fmt.Println(nncp.VersionGet())
60 if (!*doDump && !*doLoad) || flag.NArg() != 1 {
66 cfgRaw, err := ioutil.ReadFile(*cfgPath)
70 cfg, err := nncp.CfgParse(cfgRaw)
74 if err = nncp.CfgToDir(flag.Arg(0), cfg); err != nil {
79 cfg, err := nncp.DirToCfg(flag.Arg(0))
83 if _, err = nncp.Cfg2Ctx(cfg); err != nil {
86 marshaled, err := hjson.MarshalWithOptions(cfg, hjson.EncoderOptions{
91 AllowMinusZero: false,
96 os.Stdout.Write(marshaled)
97 os.Stdout.WriteString("\n")