Skip to content

Commit

Permalink
Rework flags and logging
Browse files Browse the repository at this point in the history
Now just append a set of global flags to keep everything in sync.

Verbose logging is now actually a toggle.
  • Loading branch information
xeals committed May 2, 2018
1 parent 08b64ad commit 9c4a035
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 43 deletions.
15 changes: 1 addition & 14 deletions cmd/analyse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 3 additions & 15 deletions cmd/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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]
Expand Down
16 changes: 2 additions & 14 deletions cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 22 additions & 0 deletions cmd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"

"github.com/pkg/errors"
Expand Down Expand Up @@ -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) == "" {
Expand Down

0 comments on commit 9c4a035

Please sign in to comment.