diff --git a/cmd/analyse.go b/cmd/analyse.go index f94991a..79b81f1 100644 --- a/cmd/analyse.go +++ b/cmd/analyse.go @@ -17,20 +17,7 @@ var Analyse = cli.Command{ UsageText: "Display statistical information about the backup file.", Aliases: []string{"analyze"}, CustomHelpTemplate: SubcommandHelp, - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "log, l", - Usage: "write logging output to `FILE`", - }, - cli.StringFlag{ - Name: "password, p", - Usage: "use `PASS` as password for backup file", - }, - cli.StringFlag{ - Name: "pwdfile, P", - Usage: "read password from `FILE`", - }, - }, + Flags: coreFlags, Action: func(c *cli.Context) error { bf, err := setup(c) if err != nil { diff --git a/cmd/extract.go b/cmd/extract.go index 0c4b12c..f6ab144 100644 --- a/cmd/extract.go +++ b/cmd/extract.go @@ -18,24 +18,12 @@ var Extract = cli.Command{ Usage: "Retrieve attachments from the backup", UsageText: "Decrypt files embedded in the backup.", CustomHelpTemplate: SubcommandHelp, - Flags: []cli.Flag{ - cli.StringFlag{ - Name: "log, l", - Usage: "write logging output to `FILE`", - }, - cli.StringFlag{ - Name: "password, p", - Usage: "use `PASS` as password for backup file", - }, - cli.StringFlag{ - Name: "pwdfile, P", - Usage: "read password from `FILE`", - }, + Flags: append([]cli.Flag{ cli.StringFlag{ Name: "outdir, o", Usage: "output attachments to `DIRECTORY`", }, - }, + }, coreFlags...), Action: func(c *cli.Context) error { bf, err := setup(c) if err != nil { @@ -77,7 +65,7 @@ func ExtractAttachments(bf *types.BackupFile) error { } if a := f.GetAttachment(); a != nil { - log.Printf("found attachment binary %v\n\n", *a.AttachmentId) + log.Printf("found attachment binary %v\n", *a.AttachmentId) id := *a.AttachmentId mime, hasMime := aEncs[id] diff --git a/cmd/format.go b/cmd/format.go index 1a43abf..c71773d 100644 --- a/cmd/format.go +++ b/cmd/format.go @@ -20,34 +20,22 @@ var Format = cli.Command{ Usage: "Read and format the backup file", UsageText: "Parse and transform the backup file into other formats.\nValid formats include: CSV, XML.", CustomHelpTemplate: SubcommandHelp, - Flags: []cli.Flag{ + Flags: append([]cli.Flag{ cli.StringFlag{ Name: "format, f", Usage: "output the backup as `FORMAT`", Value: "xml", }, - cli.StringFlag{ - Name: "log, l", - Usage: "write logging output to `FILE`", - }, cli.StringFlag{ Name: "message, m", Usage: "format `TYPE` messages", Value: "sms", }, - cli.StringFlag{ - Name: "password, p", - Usage: "use `PASS` as password for backup file", - }, - cli.StringFlag{ - Name: "pwdfile, P", - Usage: "read password from `FILE`", - }, cli.StringFlag{ Name: "output, o", Usage: "write decrypted format to `FILE`", }, - }, + }, coreFlags...), Action: func(c *cli.Context) error { bf, err := setup(c) if err != nil { diff --git a/cmd/util.go b/cmd/util.go index 99ae8b8..c515340 100644 --- a/cmd/util.go +++ b/cmd/util.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "io/ioutil" + "log" "os" "github.com/pkg/errors" @@ -32,7 +33,28 @@ const SubcommandHelp = `Usage: {{.HelpName}} [OPTION...] BACKUPFILE {{end}}{{end}} ` +var coreFlags = []cli.Flag{ + cli.StringFlag{ + Name: "password, p", + Usage: "use `PASS` as password for backup file", + }, + cli.StringFlag{ + Name: "pwdfile, P", + Usage: "read password from `FILE`", + }, + cli.BoolFlag{ + Name: "verbose, v", + Usage: "enable verbose logging output", + }, +} + func setup(c *cli.Context) (*types.BackupFile, error) { + // -- Enable logging + + if !c.Bool("verbose") { + log.SetOutput(ioutil.Discard) + } + // -- Verify if c.Args().Get(0) == "" {