-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.go
65 lines (56 loc) · 1.35 KB
/
app.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
package main
import (
"fmt"
"os"
"github.com/farzadmf/termask/pkg/mask"
"github.com/urfave/cli/v2"
)
var (
flags = []cli.Flag{
&cli.StringFlag{
Name: "mode",
Usage: "(tf|json) mode determines the type of the input",
Aliases: []string{"m"},
Required: true,
},
&cli.StringSliceFlag{
Name: "property",
Usage: "property whose value we want to mask (can be specified multiple times)",
Aliases: []string{"p"},
},
&cli.BoolFlag{
Name: "ignore-case",
Usage: "case insensitive match",
Aliases: []string{"i"},
},
&cli.BoolFlag{
Name: "partial-match",
Usage: "match if property partially contains the specified string",
Aliases: []string{"l"},
},
}
app = cli.App{
Name: "termask",
Usage: "Mask values in the terminal",
Flags: flags,
Action: func(c *cli.Context) error {
mode := c.String("m")
ignoreCase := c.Bool("i")
properties := c.StringSlice("p")
partial := c.Bool("l")
config := mask.NewConfig(os.Stdin, os.Stdout)
switch mode {
case "tf":
masker := mask.NewTFMasker(properties, ignoreCase, partial)
masker.Mask(config)
return nil
case "json":
masker := mask.NewJSONMasker(properties, ignoreCase, partial)
masker.Mask(config)
return nil
default:
return cli.NewExitError(fmt.Sprintf("unknown mode: %q", mode), 1)
}
},
}
)