-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
70 lines (62 loc) · 1.29 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
package main
import (
"errors"
"fmt"
"os"
"github.com/jutkko/mindown/input"
"github.com/jutkko/mindown/output"
"github.com/jutkko/mindown/util"
"github.com/urfave/cli"
)
func main() {
app := cli.NewApp()
app.Name = "mindown"
app.Usage = "convert mind to files"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "input-format",
Value: "opml",
Usage: "the input file format",
},
cli.StringFlag{
Name: "input-file",
Value: "input.txt",
Usage: "input file name",
},
cli.StringFlag{
Name: "output-file",
Value: "output.txt",
Usage: "output file name",
},
cli.BoolFlag{
Name: "f",
Usage: "provide this flag to overwrite the output file if it exists",
},
}
app.Action = func(c *cli.Context) error {
var (
graph *util.Graph
err error
)
switch c.String("input-format") {
case "yml":
graph, err = input.ParseYaml(c.String("input-file"))
if err != nil {
return err
}
case "opml":
graph, err = input.ParseOpml(c.String("input-file"))
if err != nil {
return err
}
default:
return errors.New(fmt.Sprintf("input-format not supported: %s", c.String("input-format")))
}
err = output.WriteMarkdown(c.String("output-file"), c.Bool("f"), graph)
if err != nil {
return err
}
return nil
}
app.Run(os.Args)
}