Break the fs package up into smaller parts.
The purpose of this is to make it easier to maintain and eventually to allow the rclone backends to be re-used in other projects without having to use the rclone configuration system. The new code layout is documented in CONTRIBUTING.
This commit is contained in:
parent
92624bbbf1
commit
11da2a6c9b
183 changed files with 5749 additions and 5063 deletions
89
fs/dump.go
Normal file
89
fs/dump.go
Normal file
|
@ -0,0 +1,89 @@
|
|||
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
|
||||
)
|
||||
|
||||
var dumpFlags = []struct {
|
||||
flag DumpFlags
|
||||
name string
|
||||
}{
|
||||
{DumpHeaders, "headers"},
|
||||
{DumpBodies, "bodies"},
|
||||
{DumpRequests, "requests"},
|
||||
{DumpResponses, "responses"},
|
||||
{DumpAuth, "auth"},
|
||||
{DumpFilters, "filters"},
|
||||
}
|
||||
|
||||
// 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"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue