forked from uchiiii/csv2md
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (45 loc) · 960 Bytes
/
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
package main
import (
"log"
"os"
"sort"
"github.com/urfave/cli/v2"
)
func main() {
args := &Args{}
app := &cli.App{
Name: "csv2md",
Usage: "convert csv to markdown",
Flags: []cli.Flag{
&cli.IntFlag{
Name: "padding",
Aliases: []string{"p"},
Value: 2,
Usage: "The number of spaces to add between table cells and column dividers.",
Destination: &args.Pad,
},
&cli.StringFlag{
Name: "delimiter",
Aliases: []string{"d"},
Value: ",",
Usage: "CSV delimiter, expected values: ',', ';'.",
Destination: &args.Delim,
},
},
Action: func(c *cli.Context) error {
args.Files = c.Args().Slice()
if err := args.ValidateAll(); err != nil {
return err
}
if err := ConvertAll(args); err != nil {
return err
}
return nil
},
}
sort.Sort(cli.FlagsByName(app.Flags))
err := app.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}