cmd

package
v0.1.17 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package cmd defines commands which generally read, transform, and write ADIF logfiles. Commands are invoked by a main program like adifmt, which configures a Context value. Most commands read ADIF files by name and print an ADIF logfile to standard output, but some have different input and output behavior.

Index

Constants

View Source
const (
	OpEqual            operator = "="
	OpLessThan                  = "<"
	OpLessThanEqual             = "<="
	OpGreaterThan               = ">"
	OpGreaterThanEqual          = ">="
)

Variables

View Source
var Cat = Command{Name: "cat", Run: runCat,
	Description: "Concatenate all input files to standard output"}
View Source
var Edit = Command{Name: "edit", Run: runEdit, Help: helpEdit,
	Description: "Add, change, remove, or adjust field values"}
View Source
var Find = Command{Name: "find", Run: runFind, Help: helpFind,
	Description: "Include only records matching a condition"}
View Source
var Fix = Command{Name: "fix", Run: runFix, Help: helpFix,
	Description: "Correct field formats to match the ADIF specification"}
View Source
var Flatten = Command{Name: "flatten", Run: runFlatten, Help: helpFlatten,
	Description: "Flatten multi-instance fields to multiple records"}
View Source
var Infer = Command{Name: "infer", Run: runInfer, Help: helpInfer,
	Description: "Add missing fields based on present fields"}
View Source
var Save = Command{Name: "save", Run: runSave, Help: helpSave,
	Description: "Save standard input to file(s) with format inferred by extension"}
View Source
var Select = Command{Name: "select", Run: runSelect, Help: helpSelect,
	Description: "Print only specific fields from the input"}
View Source
var Sort = Command{Name: "sort", Run: runSort, Help: helpSort,
	Description: "Sort records by a list of fields"}
View Source
var Validate = Command{Name: "validate", Run: runValidate, Help: helpValidate,
	Description: "Validate field values; non-zero exit and no stdout if invalid"}

Functions

func ValidateAlphanumName

func ValidateAlphanumName(name, value string) error

Types

type Command

type Command struct {
	Name        string
	Description string
	Run         func(ctx *Context, args []string) error
	Help        func() string
}

type Condition added in v0.1.7

type Condition interface {
	Evaluate(EvaluationContext) bool // maybe (bool, error)?
	String() string
}

type ConditionValue added in v0.1.7

type ConditionValue struct {
	// contains filtered or unexported fields
}

func (*ConditionValue) Get added in v0.1.7

func (cv *ConditionValue) Get() junction

func (*ConditionValue) IfFlag added in v0.1.7

func (cv *ConditionValue) IfFlag() flag.Value

func (*ConditionValue) IfNotFlag added in v0.1.7

func (cv *ConditionValue) IfNotFlag() flag.Value

func (*ConditionValue) OrIfFlag added in v0.1.7

func (cv *ConditionValue) OrIfFlag() flag.Value

func (*ConditionValue) OrIfNotFlag added in v0.1.7

func (cv *ConditionValue) OrIfNotFlag() flag.Value

type Context

type Context struct {
	InputFormat        adif.Format
	OutputFormat       adif.Format
	Readers            map[adif.Format]adif.Reader
	Writers            map[adif.Format]adif.Writer
	Out                io.Writer
	Locale             language.Tag
	CommandCtx         any
	FieldOrder         FieldList
	UserdefFields      UserdefFieldList
	SuppressAppHeaders bool
	Prepare            func(*adif.Logfile)
	// contains filtered or unexported fields
}

type EditContext

type EditContext struct {
	Add         FieldAssignments
	Set         FieldAssignments
	Rename      FieldAssignments
	Remove      FieldList
	RemoveBlank bool
	Cond        ConditionValue
	FromZone    TimeZone
	ToZone      TimeZone
}

type EvaluationContext added in v0.1.7

type EvaluationContext interface {
	Compare(a, b adif.Field) (int, error)
	Get(name string) adif.Field
	Cast(name, value string) adif.Field
}

type FieldAssignments

type FieldAssignments struct {
	// contains filtered or unexported fields
}

func NewFieldAssignments

func NewFieldAssignments(validate func(k, v string) error) FieldAssignments

func (*FieldAssignments) Get

func (*FieldAssignments) Set

func (f *FieldAssignments) Set(s string) error

func (*FieldAssignments) String

func (a *FieldAssignments) String() string

type FieldDelimiters added in v0.1.15

type FieldDelimiters map[string]string

func (FieldDelimiters) Get added in v0.1.15

func (FieldDelimiters) Set added in v0.1.15

func (f FieldDelimiters) Set(s string) error

func (FieldDelimiters) String added in v0.1.15

func (f FieldDelimiters) String() string

type FieldList

type FieldList []string

func (*FieldList) Get

func (f *FieldList) Get() FieldList

func (*FieldList) Set

func (f *FieldList) Set(s string) error

func (*FieldList) String

func (f *FieldList) String() string

type FindContext added in v0.1.7

type FindContext struct {
	Cond ConditionValue
}

type FlattenContext added in v0.1.13

type FlattenContext struct {
	Fields     FieldList
	Delimiters FieldDelimiters
}

type InferContext

type InferContext struct {
	Fields     FieldList
	CommentLog bool
}

type NamedReader

type NamedReader interface {
	io.ReadCloser
	Name() string
}

NamedReader is an io.Reader with a name. os.File implements this interface and stringReader is provided for testing.

type SaveContext

type SaveContext struct {
	OverwriteExisting bool
	WriteIfEmpty      bool
	CreateDirectory   bool
	Quiet             bool
}

type SelectContext

type SelectContext struct {
	Fields FieldList
}

type SortContext added in v0.1.7

type SortContext struct {
	Fields FieldList
}

type TimeZone

type TimeZone struct {
	// contains filtered or unexported fields
}

func (*TimeZone) Get

func (z *TimeZone) Get() *time.Location

func (*TimeZone) Set

func (z *TimeZone) Set(s string) error

func (*TimeZone) String

func (z *TimeZone) String() string

type UserdefFieldList

type UserdefFieldList []adif.UserdefField

func (*UserdefFieldList) Get

func (*UserdefFieldList) Set

func (f *UserdefFieldList) Set(s string) error

func (*UserdefFieldList) String

func (f *UserdefFieldList) String() string

type ValidateContext added in v0.1.11

type ValidateContext struct {
	RequiredFields FieldList
}

Jump to

Keyboard shortcuts

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