Skip to content

Commit 9c4a035

Browse files
author
xeals
committed
Rework flags and logging
Now just append a set of global flags to keep everything in sync. Verbose logging is now actually a toggle.
1 parent 08b64ad commit 9c4a035

4 files changed

Lines changed: 28 additions & 43 deletions

File tree

cmd/analyse.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,7 @@ var Analyse = cli.Command{
1717
UsageText: "Display statistical information about the backup file.",
1818
Aliases: []string{"analyze"},
1919
CustomHelpTemplate: SubcommandHelp,
20-
Flags: []cli.Flag{
21-
cli.StringFlag{
22-
Name: "log, l",
23-
Usage: "write logging output to `FILE`",
24-
},
25-
cli.StringFlag{
26-
Name: "password, p",
27-
Usage: "use `PASS` as password for backup file",
28-
},
29-
cli.StringFlag{
30-
Name: "pwdfile, P",
31-
Usage: "read password from `FILE`",
32-
},
33-
},
20+
Flags: coreFlags,
3421
Action: func(c *cli.Context) error {
3522
bf, err := setup(c)
3623
if err != nil {

cmd/extract.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,12 @@ var Extract = cli.Command{
1818
Usage: "Retrieve attachments from the backup",
1919
UsageText: "Decrypt files embedded in the backup.",
2020
CustomHelpTemplate: SubcommandHelp,
21-
Flags: []cli.Flag{
22-
cli.StringFlag{
23-
Name: "log, l",
24-
Usage: "write logging output to `FILE`",
25-
},
26-
cli.StringFlag{
27-
Name: "password, p",
28-
Usage: "use `PASS` as password for backup file",
29-
},
30-
cli.StringFlag{
31-
Name: "pwdfile, P",
32-
Usage: "read password from `FILE`",
33-
},
21+
Flags: append([]cli.Flag{
3422
cli.StringFlag{
3523
Name: "outdir, o",
3624
Usage: "output attachments to `DIRECTORY`",
3725
},
38-
},
26+
}, coreFlags...),
3927
Action: func(c *cli.Context) error {
4028
bf, err := setup(c)
4129
if err != nil {
@@ -77,7 +65,7 @@ func ExtractAttachments(bf *types.BackupFile) error {
7765
}
7866

7967
if a := f.GetAttachment(); a != nil {
80-
log.Printf("found attachment binary %v\n\n", *a.AttachmentId)
68+
log.Printf("found attachment binary %v\n", *a.AttachmentId)
8169
id := *a.AttachmentId
8270

8371
mime, hasMime := aEncs[id]

cmd/format.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,22 @@ var Format = cli.Command{
2020
Usage: "Read and format the backup file",
2121
UsageText: "Parse and transform the backup file into other formats.\nValid formats include: CSV, XML.",
2222
CustomHelpTemplate: SubcommandHelp,
23-
Flags: []cli.Flag{
23+
Flags: append([]cli.Flag{
2424
cli.StringFlag{
2525
Name: "format, f",
2626
Usage: "output the backup as `FORMAT`",
2727
Value: "xml",
2828
},
29-
cli.StringFlag{
30-
Name: "log, l",
31-
Usage: "write logging output to `FILE`",
32-
},
3329
cli.StringFlag{
3430
Name: "message, m",
3531
Usage: "format `TYPE` messages",
3632
Value: "sms",
3733
},
38-
cli.StringFlag{
39-
Name: "password, p",
40-
Usage: "use `PASS` as password for backup file",
41-
},
42-
cli.StringFlag{
43-
Name: "pwdfile, P",
44-
Usage: "read password from `FILE`",
45-
},
4634
cli.StringFlag{
4735
Name: "output, o",
4836
Usage: "write decrypted format to `FILE`",
4937
},
50-
},
38+
}, coreFlags...),
5139
Action: func(c *cli.Context) error {
5240
bf, err := setup(c)
5341
if err != nil {

cmd/util.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"fmt"
66
"io/ioutil"
7+
"log"
78
"os"
89

910
"github.com/pkg/errors"
@@ -32,7 +33,28 @@ const SubcommandHelp = `Usage: {{.HelpName}} [OPTION...] BACKUPFILE
3233
{{end}}{{end}}
3334
`
3435

36+
var coreFlags = []cli.Flag{
37+
cli.StringFlag{
38+
Name: "password, p",
39+
Usage: "use `PASS` as password for backup file",
40+
},
41+
cli.StringFlag{
42+
Name: "pwdfile, P",
43+
Usage: "read password from `FILE`",
44+
},
45+
cli.BoolFlag{
46+
Name: "verbose, v",
47+
Usage: "enable verbose logging output",
48+
},
49+
}
50+
3551
func setup(c *cli.Context) (*types.BackupFile, error) {
52+
// -- Enable logging
53+
54+
if !c.Bool("verbose") {
55+
log.SetOutput(ioutil.Discard)
56+
}
57+
3658
// -- Verify
3759

3860
if c.Args().Get(0) == "" {

0 commit comments

Comments
 (0)