Documentation
¶
Index ¶
- Variables
- func DconfDump(path string) (content []byte, dumpErr error)
- func RemoveFromStringArr(arr []string, removeString string) []string
- func TrimSectionSlashes(section string) string
- type Modification
- type Schema
- func (schema *Schema) AddSection(section string, sT *SchemaKV) (addErr error)
- func (schema *Schema) DeleteSections(sections ...string)
- func (schema *Schema) DeleteSectionsWithPrefix(sections ...string)
- func (schema *Schema) GetSection(section string) (kv *SchemaKV, getErr error)
- func (schema *Schema) HasSection(section string) (exists bool)
- func (schema *Schema) ImportIntoDconf() (importErr error)
- func (schema *Schema) MigrateSectionsWithName(source string, dest string, exact bool)
- func (schema *Schema) String() (schemaString string)
- type SchemaKV
- func (kv *SchemaKV) AddKey(key string, t *SchemaType) error
- func (kv *SchemaKV) DeleteKeys(keys ...string)
- func (kv *SchemaKV) Duplicate() *SchemaKV
- func (kv *SchemaKV) GetVal(key string) (*SchemaType, error)
- func (kv *SchemaKV) HasKey(key string) bool
- func (kv *SchemaKV) ModifyKey(key string, mod Modification) (modErr error)
- func (kv *SchemaKV) MoveKey(source string, dest string) error
- type SchemaType
Constants ¶
This section is empty.
Variables ¶
var ( // ErrKeyAlreadyExists is an error we return when we already have a key in a schema key-value store. Mostly useful for validating during section adding. ErrKeyAlreadyExists = errors.New("key already exists in schemakv") // ErrKeyNotExists is an error we return when we do not have a key in a schema ErrKeyNotExists = errors.New("key does not exist") // ErrModCannotDoReplace is an error we return when we cannot do a replacement of a value ErrModCannotDoReplace = errors.New("cannot perform replace modification, schematype is not of ArrayAsString or string") // ErrModNoReplaceValueOrValue is an error we return if we cannot perform a modification without a value ErrModNoReplaceValueOrValue = errors.New("cannot perform modification, no replacevalue or value specified") // ErrNoContentProvided is an error we return when no content is provided when attempt to import ErrNoContentProvided error = errors.New("no content provided as a byte slice") // ErrNoDconfInPath is an error we return if we could not find dconf in the path during a dconf operation ErrNoDconfInPath error = errors.New("no dconf found in path") // ErrSectionDoesNotExist is an error we return if a section requested does not exist ErrSectionDoesNotExist = errors.New("section does not exist") // ErrSectionExists is an error we return if a section exists ErrSectionExists = errors.New("section exists") )
var ( // SectionRegexp is our regular expression for a section name SectionRegexp = regexp.MustCompile(`^\[([A-Za-z0-9-_\:\.\/{}]+)\]`) )
Functions ¶
func DconfDump ¶
DconfDump will attempt to dump the contents of the provided path If no path is provided, / (root) is used
func RemoveFromStringArr ¶
RemoveFromStringArr will remove the specified string from our array
func TrimSectionSlashes ¶
TrimSectionSlashes will trim the provided section string of any prefixed and suffixed forward slash
Types ¶
type Modification ¶
type Modification struct { // ReplaceValues is an array of RegExp (regular expression) for search to the replacement value // This is expected to be a length of two, the first being the value we are looking for and the second is the value we are replacing it with // The first value can be an exact string or regex ReplaceValues []string `toml:"replaceValue"` // Value is the raw value we are applying as the value for the modification Value string `toml:"value"` }
Modification defines a desired change to a SchemaType
type Schema ¶
type Schema struct { Order []string // Our fixed order Map map[string]*SchemaKV // Our Map of Sections (like com/solus-project/budgie-desktop/instance/icon-tasklist) Path string // Path for the Schema }
Schema is a map of paths to key values
func NewSchema ¶
NewSchema will attempt to create a new Schema based on the root of the dconf directory content is optional. If no content is specified, we will attempt to do a dconf dump instead This will be done user running the command. If we fail to dump or parse the schema, we will return an error
func (*Schema) AddSection ¶
AddSection will attempt to add the provided SchemaKV as the provided section name This will return an error if the section already exists
func (*Schema) DeleteSections ¶
DeleteSections will delete all sections specified should they match exactly If you want to match by prefix, use the DeleteSectionsWithPrefix func
func (*Schema) DeleteSectionsWithPrefix ¶
DeleteSectionsWithPrefix will delete all sections specified and all sections which begin with the section prefixed
func (*Schema) GetSection ¶
GetSection will attempt to get the SchemaKV associated with the provided section
func (*Schema) HasSection ¶
HasSection will check if our Schema has the provided section
func (*Schema) ImportIntoDconf ¶
ImportIntoDconf will import this Schema into its path via dconf load
func (*Schema) MigrateSectionsWithName ¶
MigrateSectionsWithName will migrate sections with the source prefix specified, remapping them to have the destination prefix. If exact is set to true, we will only migrate the section if it is an exact match
type SchemaKV ¶
type SchemaKV struct { Order []string // Our fixed order Keys map[string]*SchemaType // Our Map of Keys in each Section }
SchemaKV is a map of keys to our SchemaType
func (*SchemaKV) AddKey ¶
func (kv *SchemaKV) AddKey(key string, t *SchemaType) error
AddKey will attempt to add the SchemaType for the provided key to the SchemaKV This will return an error if the key already exists
func (*SchemaKV) DeleteKeys ¶
DeleteKeys will delete all specified keys from a SchemaKV
func (*SchemaKV) GetVal ¶
func (kv *SchemaKV) GetVal(key string) (*SchemaType, error)
GetVal will get the SchemaType value for the provided key, or return an error
type SchemaType ¶
type SchemaType struct { Type string BoolVal bool FloatHadTrailingZero bool FloatVal float64 IntVal int32 UintVal uint32 Val string }
SchemaType is our defined type This type will have a defined Type (e.g. "bool") as Type and the designated type set This allows us to perform less type checking and reflection during marshal and unmarshalling
func NewSchemaType ¶
func NewSchemaType(rawVal string) (sT *SchemaType, parseErr error)
NewSchemaType will attempt to convert the provided key/val into a SchemaType
func ParseSchemaLine ¶
func ParseSchemaLine(line string) (key string, t *SchemaType)
ParseSchemaLine will parse our key=val line in an attempt to figure out its type
func (*SchemaType) Duplicate ¶
func (sT *SchemaType) Duplicate() *SchemaType
Duplicate will duplicate this SchemaType
func (*SchemaType) Matches ¶
func (sT *SchemaType) Matches(oST *SchemaType) (matches bool)
Matches will check if the provided SchemaType matches this one
func (*SchemaType) String ¶
func (sT *SchemaType) String() string
String will convert our SchemaType back to a string Note this only converts the value itself and not the key