-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
67 lines (56 loc) · 1.4 KB
/
cli.go
File metadata and controls
67 lines (56 loc) · 1.4 KB
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
package main
import (
"fmt"
"github.com/pmarcais/transcode-sros/transsros"
"github.com/urfave/cli/v2"
)
type appCfg struct {
unflatConfFile string // file to transcode
short bool // generate short line in service
debug bool // for troubleshooting
}
// NewCLI defines the CLI flags and commands.
func NewCLI() *cli.App {
appC := &appCfg{}
flags := []cli.Flag{
&cli.StringFlag{
Name: "config-file",
Aliases: []string{"f"},
Value: "inventory.yml",
Usage: "Unflatten SROS configuration file",
Destination: &appC.unflatConfFile,
},
&cli.BoolFlag{
Name: "shorten vprn line",
Aliases: []string{"s"},
Value: false,
Usage: "service vprn cli without service and customer name",
Destination: &appC.short,
},
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Value: false,
Usage: "debug mode for troubleshooting",
Destination: &appC.debug,
},
}
app := &cli.App{
Name: "transcode-sros",
Version: "dev",
Usage: "transcode a router CLI configuration file",
Flags: flags,
Action: func(c *cli.Context) error {
return appC.run()
},
}
return app
}
func (app *appCfg) run() error {
result := transsros.Transcode(app.unflatConfFile, app.short, app.debug)
// Printing result to console
for _, line := range result {
fmt.Println(line)
}
return nil
}