utils

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const USE_STD_STREAM string = "-"

USE_STD_STREAM set as filepath string value indicates that standard streams should be used as I/O targets.

Variables

This section is empty.

Functions

func GeneratePresetsFile

func GeneratePresetsFile() error

GeneratePresetsFile writes an empty presets file to current user's home directory. If the file is already present, it returns an error.

Types

type Params

type Params struct {
	// Path to the input CSV file.
	Input string `json:"input"`

	// Path to the output CSV file.
	Output string `json:"output"`

	// Encoding of the input file.
	Encoding string `json:"encoding"`

	// Pattern that determines how to rewrite the input file.
	Pattern string `json:"pattern"`

	// Character that serves as CSV comma in the input file.
	// If empty, it is assumed that it matches comma in the output.
	InputComma string `json:"input_comma"`

	// String inserted as the first row.
	NewHeader string `json:"new_header"`

	// Omit the first row from the input.
	SkipHeader bool `json:"skip_header"`

	// Overwrite output file if it exists.
	Overwrite bool `json:"overwrite"`

	// Use CRLF instead of LF for line endings.
	UseCRLF bool `json:"crlf"`
}

Params is a collection of parameters required for CSV file rewriting.

func (*Params) ApplyPreset

func (p *Params) ApplyPreset(preset Preset)

ApplyPreset copies values from Preset struct to the corresponding members.

type Preset

type Preset struct {
	// Input file encoding.
	Encoding string `json:"encoding"`

	// Pattern for output CSV file.
	Pattern string `json:"pattern"`

	// Character serving as comma in the input file.
	InputComma string `json:"input_comma"`

	// Indicates whether the header should be skipped.
	SkipHeader bool `json:"skip_header"`

	// This string will be inserted as the first row.
	NewHeader string `json:"new_header"`

	// Use CRLF instead of LF in the output file
	UseCRLF bool `json:"crlf"`
}

Preset stores a combination of pattern and encoding. Presets can be written to the presets file to facilitate reuse.

func LoadPreset

func LoadPreset(name string) (Preset, error)

LoadPreset returns a Preset of the specified name from the presets file. If the Preset is not found, an error message is returned.

Jump to

Keyboard shortcuts

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