config

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package config is responsible for setting the program config from command-line arguments

Index

Constants

View Source
const (
	EnvNoColor   = "NO_COLOR"
	EnvF2NoColor = "F2_NO_COLOR"
)
View Source
const (
	DefaultFixConflictsPattern = "(%d)"
	DefaultWorkingDir          = "."
)

Variables

View Source
var (
	Stdin  io.Reader = os.Stdin
	Stdout io.Writer = os.Stdout
	Stderr io.Writer = os.Stderr
)

Functions

func IsATTY

func IsATTY(fd uintptr) bool

IsATTY checks if the given file descriptor is associated with a terminal.

Types

type Backup

type Backup struct {
	Changes     file.Changes `json:"changes"`
	CleanedDirs []string     `json:"cleaned_dirs,omitempty"`
}

func (Backup) RenderJSON

func (b Backup) RenderJSON(w io.Writer) error

type Config

type Config struct {
	Date                     time.Time      `json:"date"`
	BackupLocation           io.Writer      `json:"-"`
	ExcludeDirRegex          *regexp.Regexp `json:"exclude_dir_regex"`
	ExcludeRegex             *regexp.Regexp `json:"exclude_regex"`
	Search                   *Search        `json:"search_regex"`
	FixConflictsPatternRegex *regexp.Regexp `json:"fix_conflicts_pattern_regex"`
	Replacement              string         `json:"replacement"`
	WorkingDir               string         `json:"working_dir"`
	FixConflictsPattern      string         `json:"fix_conflicts_pattern"`
	CSVFilename              string         `json:"csv_filename"`
	BackupFilename           string         `json:"backup_filename"`
	TargetDir                string         `json:"target_dir"`
	SortVariable             string         `json:"sort_variable"`
	ExiftoolOpts             ExiftoolOpts   `json:"exiftool_opts"`
	PairOrder                []string       `json:"pair_order"`
	FindSlice                []string       `json:"find_slice"`
	FilesAndDirPaths         []string       `json:"files_and_dir_paths"`
	ReplacementSlice         []string       `json:"replacement_slice"`
	ReplaceLimit             int            `json:"replace_limit"`
	StartNumber              int            `json:"start_number"`
	MaxDepth                 int            `json:"max_depth"`
	Sort                     Sort           `json:"sort"`
	Revert                   bool           `json:"revert"`
	IncludeDir               bool           `json:"include_dir"`
	IgnoreExt                bool           `json:"ignore_ext"`
	IgnoreCase               bool           `json:"ignore_case"`
	Verbose                  bool           `json:"verbose"`
	IncludeHidden            bool           `json:"include_hidden"`
	Quiet                    bool           `json:"quiet"`
	NoColor                  bool           `json:"no_color"`
	AutoFixConflicts         bool           `json:"auto_fix_conflicts"`
	Exec                     bool           `json:"exec"`
	StringLiteralMode        bool           `json:"string_literal_mode"`
	JSON                     bool           `json:"json"`
	Debug                    bool           `json:"debug"`
	Recursive                bool           `json:"recursive"`
	ResetIndexPerDir         bool           `json:"reset_index_per_dir"`
	OnlyDir                  bool           `json:"only_dir"`
	PipeOutput               bool           `json:"is_output_to_pipe"`
	ReverseSort              bool           `json:"reverse_sort"`
	AllowOverwrites          bool           `json:"allow_overwrites"`
	Pair                     bool           `json:"pair"`
	SortPerDir               bool           `json:"sort_per_dir"`
	Clean                    bool           `json:"clean"`
}

Config represents the program configuration.

func Get

func Get() *Config

Get retrives an already set config or panics if the configuration has not yet been initialized.

func Init

func Init(ctx *cli.Context, pipeOutput bool) (*Config, error)

Get retrieves the current configuration or panics if not initialized.

func (*Config) SetFindStringRegex

func (c *Config) SetFindStringRegex(replacementIndex int) error

SetFindStringRegex compiles a regular expression for the find string of the corresponding replacement index (if any). Otherwise, the created regex will match the entire file name. It takes into account the StringLiteralMode and IgnoreCase options.

If a find string exists for the given replacementIndex, it's used as the pattern. Otherwise, the pattern defaults to ".*" to match the entire file name.

Returns an error if the regex compilation fails.

type ExiftoolOpts

type ExiftoolOpts struct {
	API             string `long:"api"             json:"api"`              // corresponds to the `-api` flag
	Charset         string `long:"charset"         json:"charset"`          // corresponds to the `-charset` flag
	CoordFormat     string `long:"coordFormat"     json:"coord_format"`     // corresponds to the `-coordFormat` flag
	DateFormat      string `long:"dateFormat"      json:"date_format"`      // corresponds to the `-dateFormat` flag
	ExtractEmbedded bool   `long:"extractEmbedded" json:"extract_embedded"` // corresponds to the `-extractEmbedded` flag
}

ExiftoolOpts defines supported options for customizing Exitool's output.

type Search struct {
	Regex *regexp.Regexp `json:"regex"`
	// Replacement index
	Index int `json:"index"`
}

type Sort

type Sort int
const (
	SortDefault Sort = iota
	SortSize
	SortNatural
	SortMtime
	SortBtime
	SortAtime
	SortCtime
	SortTimeVar
	SortIntVar
	SortStringVar
)

func (Sort) String

func (s Sort) String() string

Jump to

Keyboard shortcuts

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