Skip to content

Commit

Permalink
update config
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoisaiah committed Oct 2, 2024
1 parent 3304f6c commit 19dea56
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ const (
EnvF2NoColor = "F2_NO_COLOR"
)

const (
DefaultFixConflictsPattern = "(%d)"
DefaultWorkingDir = "."
)

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

var (
defaultFixConflictsPattern = "(%d)"
defaultFixConflictsPatternRegex = regexp.MustCompile(`\((\d+)\)$`)
customFixConfictsPatternRegex = regexp.MustCompile(`^(\D?(%(\d+)?d)\D?)$`)
)
Expand Down Expand Up @@ -101,6 +105,12 @@ type Config struct {
// 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.
func (c *Config) SetFindStringRegex(replacementIndex int) error {
// findPattern is set to match the entire file name by default
// except if a find string for the corresponding replacement index
Expand Down Expand Up @@ -162,7 +172,7 @@ func (c *Config) setOptions(ctx *cli.Context) error {

// Default to the current working directory if no path arguments are provided
if len(c.FilesAndDirPaths) == 0 {
c.FilesAndDirPaths = append(c.FilesAndDirPaths, ".")
c.FilesAndDirPaths = append(c.FilesAndDirPaths, DefaultWorkingDir)
}

// Ensure that each findString has a corresponding replacement.
Expand Down Expand Up @@ -205,7 +215,7 @@ func (c *Config) setDefaultOpts(ctx *cli.Context) error {
}

if c.FixConflictsPattern == "" {
c.FixConflictsPattern = defaultFixConflictsPattern
c.FixConflictsPattern = DefaultFixConflictsPattern
c.FixConflictsPatternRegex = defaultFixConflictsPatternRegex
} else if !customFixConfictsPatternRegex.MatchString(c.FixConflictsPattern) {
return errParsingFixConflictsPattern.Fmt(c.FixConflictsPattern)
Expand Down Expand Up @@ -325,7 +335,7 @@ func (c *Config) configureOutput() {
func Init(ctx *cli.Context, pipeOutput bool) (*Config, error) {
conf = &Config{
Date: time.Now(),
FilesAndDirPaths: []string{"."},
FilesAndDirPaths: []string{DefaultWorkingDir},
Sort: SortDefault,
PipeOutput: pipeOutput,
}
Expand All @@ -344,7 +354,7 @@ func Init(ctx *cli.Context, pipeOutput bool) (*Config, error) {

if conf.WorkingDir == "" {
// Get the current working directory
conf.WorkingDir, err = filepath.Abs(".")
conf.WorkingDir, err = filepath.Abs(DefaultWorkingDir)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 19dea56

Please sign in to comment.