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