cmd

package
v0.1.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const AppHelp = `` /* 187-byte string literal not displayed */

AppHelp is the help template.

View Source
const SubcommandHelp = `` /* 158-byte string literal not displayed */

TODO: Work out how to display global flags here SubcommandHelp is the subcommand help template.

Variables

View Source
var Analyse = cli.Command{
	Name:               "analyse",
	Usage:              "Information about the backup file",
	UsageText:          "Display statistical information about the backup file.",
	Aliases:            []string{"analyze"},
	CustomHelpTemplate: SubcommandHelp,
	Flags:              coreFlags,
	Action: func(c *cli.Context) error {
		bf, err := setup(c)
		if err != nil {
			return err
		}

		a, err := AnalyseTables(bf)
		fmt.Println("This is still largely in flux and reflects whatever task I was having issues with at the time.\n")
		fmt.Println(a)

		fmt.Println("part:", len(examples["insert_into_part"].GetParameters()), examples["insert_into_part"])

		return errors.WithMessage(err, "failed to analyse tables")
	},
}

Analyse fulfils the `analyse` subcommand.

View Source
var Check = cli.Command{
	Name:               "check",
	Usage:              "Verify that a backup is readable",
	UsageText:          "Attempts to decrypt the provided backup and do nothing with it except verify that it's readable\n from start to finish. Enables verbose logging by default.",
	CustomHelpTemplate: SubcommandHelp,
	Flags: []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`",
		},
	},
	Action: func(c *cli.Context) error {
		bf, err := setup(c)
		if err != nil {
			return err
		}

		log.SetOutput(os.Stderr)

		if err := Raw(bf, ioutil.Discard); err != nil {
			return errors.Wrap(err, "Encountered error while checking")
		}

		log.Println("Backup looks okay from here.")
		return nil
	},
}

Check fulfils the `format` subcommand.

View Source
var Extract = cli.Command{
	Name:               "extract",
	Usage:              "Retrieve attachments from the backup",
	UsageText:          "Decrypt files embedded in the backup.",
	CustomHelpTemplate: SubcommandHelp,
	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 {
			return err
		}

		if path := c.String("outdir"); path != "" {
			err := os.MkdirAll(path, 0755)
			if err != nil {
				return errors.Wrap(err, "unable to create output directory")
			}
			err = os.Chdir(path)
			if err != nil {
				return errors.Wrap(err, "unable to change working directory")
			}
		}
		if err = ExtractAttachments(bf); err != nil {
			return errors.Wrap(err, "failed to extract attachment")
		}

		return nil
	},
}

Extract fulfils the `extract` subcommand.

View Source
var Format = cli.Command{
	Name:               "format",
	Usage:              "Read and format the backup file",
	UsageText:          "Parse and transform the backup file into other formats.\nValid formats include: CSV, XML, RAW.",
	CustomHelpTemplate: SubcommandHelp,
	Flags: append([]cli.Flag{
		cli.StringFlag{
			Name:  "format, f",
			Usage: "output the backup as `FORMAT`",
			Value: "xml",
		},
		cli.StringFlag{
			Name:  "message, m",
			Usage: "format `TYPE` messages",
			Value: "sms",
		},
		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 {
			return err
		}

		var out io.Writer
		if c.String("output") != "" {
			var file *os.File
			file, err = os.OpenFile(c.String("output"), os.O_CREATE|os.O_WRONLY, 0644)
			out = io.Writer(file)
			if err != nil {
				return errors.Wrap(err, "unable to open output file")
			}
			defer func() {
				if file.Close() != nil {
					log.Fatalf("unable to close output file: %s", err.Error())
				}
			}()
		} else {
			out = os.Stdout
		}

		switch strings.ToLower(c.String("format")) {
		case "csv":
			err = CSV(bf, strings.ToLower(c.String("message")), out)
		case "xml":
			err = XML(bf, out)
		case "json":

			return errors.New("JSON is still TODO")
		case "raw":
			err = Raw(bf, out)
		default:
			return errors.Errorf("format %s not recognised", c.String("format"))
		}
		if err != nil {
			return errors.Wrap(err, "failed to format output")
		}

		return nil
	},
}

Format fulfils the `format` subcommand.

Functions

func AnalyseTables

func AnalyseTables(bf *types.BackupFile) (map[string]int, error)

AnalyseTables calculates the frequency of all records in the backup file.

func CSV

func CSV(bf *types.BackupFile, message string, out io.Writer) error

CSV dumps the raw backup data into a comma-separated value format.

func E

func E(err error, msg string, code int) *cli.ExitError

E is a wrapper to simply create a cli.ExitError.

func ExtractAttachments

func ExtractAttachments(bf *types.BackupFile) error

ExtractAttachments pulls only the attachments out of the backup file and outputs them in the current working directory.

func JSON

func JSON(bf *types.BackupFile, out io.Writer) error

JSON <undefined>

func Raw added in v0.1.6

func Raw(bf *types.BackupFile, out io.Writer) error

Raw performs an ever plainer dump than CSV, and is largely unusable for any purpose outside debugging.

func XML

func XML(bf *types.BackupFile, out io.Writer) error

XML formats the backup into the same XML format as SMS Backup & Restore uses. Layout described at their website http://synctech.com.au/fields-in-xml-backup-files/

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL