File: dump.go

package info (click to toggle)
rclone 1.45-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 24,300 kB
  • sloc: python: 364; sh: 255; makefile: 190; xml: 30
file content (93 lines) | stat: -rw-r--r-- 1,738 bytes parent folder | download
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package fs

import (
	"fmt"
	"strings"

	"github.com/pkg/errors"
)

// DumpFlags describes the Dump options in force
type DumpFlags int

// DumpFlags definitions
const (
	DumpHeaders DumpFlags = 1 << iota
	DumpBodies
	DumpRequests
	DumpResponses
	DumpAuth
	DumpFilters
	DumpGoRoutines
	DumpOpenFiles
)

var dumpFlags = []struct {
	flag DumpFlags
	name string
}{
	{DumpHeaders, "headers"},
	{DumpBodies, "bodies"},
	{DumpRequests, "requests"},
	{DumpResponses, "responses"},
	{DumpAuth, "auth"},
	{DumpFilters, "filters"},
	{DumpGoRoutines, "goroutines"},
	{DumpOpenFiles, "openfiles"},
}

// DumpFlagsList is a list of dump flags used in the help
var DumpFlagsList string

func init() {
	// calculate the dump flags list
	var out []string
	for _, info := range dumpFlags {
		out = append(out, info.name)
	}
	DumpFlagsList = strings.Join(out, ",")
}

// String turns a DumpFlags into a string
func (f DumpFlags) String() string {
	var out []string
	for _, info := range dumpFlags {
		if f&info.flag != 0 {
			out = append(out, info.name)
			f &^= info.flag
		}
	}
	if f != 0 {
		out = append(out, fmt.Sprintf("Unknown-0x%X", int(f)))
	}
	return strings.Join(out, ",")
}

// Set a DumpFlags as a comma separated list of flags
func (f *DumpFlags) Set(s string) error {
	var flags DumpFlags
	parts := strings.Split(s, ",")
	for _, part := range parts {
		found := false
		part = strings.ToLower(strings.TrimSpace(part))
		if part == "" {
			continue
		}
		for _, info := range dumpFlags {
			if part == info.name {
				found = true
				flags |= info.flag
			}
		}
		if !found {
			return errors.Errorf("Unknown dump flag %q", part)
		}
	}
	*f = flags
	return nil
}

// Type of the value
func (f *DumpFlags) Type() string {
	return "string"
}