Skip to content

Commit

Permalink
feat(issues/57): use ${EDITOR} variable to edit files
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Oct 27, 2024
1 parent 3410b8a commit 4f557ae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
8 changes: 7 additions & 1 deletion cmd/travelgrunt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ var appVersion = "default"

var outFile string
var expression string
var editFile bool
var top bool
var version bool

func init() {
flag.StringVar(&outFile, "out-file", "", "output selected path into the file specified")
flag.StringVar(&expression, "x", "", "use arbitrary expression passed instead of configured rules")
flag.BoolVar(&editFile, "e", false, "edit file selected instead of changing working directory")

Check warning on line 32 in cmd/travelgrunt/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/travelgrunt/main.go#L32

Added line #L32 was not covered by tests
flag.BoolVar(&top, "top", false, "get to the repository top level (root) path")
flag.BoolVar(&version, "version", false, "print application version and exit")
}
Expand Down Expand Up @@ -132,6 +134,8 @@ func main() {
cfg = cfg.WithNameEx(expression)
}

cfg.UseFiles = editFile

Check warning on line 138 in cmd/travelgrunt/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/travelgrunt/main.go#L137-L138

Added lines #L137 - L138 were not covered by tests
entries, paths, err := directory.Collect(rootPath, cfg)

if err != nil {
Expand All @@ -149,7 +153,9 @@ func main() {
if outFile != "" {
path := getEntryPath(entries, selected, rootPath)

tag(path)
if !editFile {
tag(path)
}

Check warning on line 158 in cmd/travelgrunt/main.go

View check run for this annotation

Codecov / codecov/patch

cmd/travelgrunt/main.go#L156-L158

Added lines #L156 - L158 were not covered by tests

writeFileAndExit(outFile, path)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ type Config struct {
Rules []rule.Rule `yaml:"rules"`

IsDefault bool
UseFiles bool
}

// DefaultConfig returns default travelgrunt repo-level configuration
func DefaultConfig() Config {
return Config{
Rules: []rule.Rule{{ModeFn: mode.IsTerragrunt}},
IsDefault: true,
UseFiles: false,
}
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/directory/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func Collect(rootPath string, cfg config.Config) (entries map[string]string, pat
}

absPath := filepath.Dir(path)
if cfg.UseFiles {
absPath = path
}

Check warning on line 37 in pkg/directory/directory.go

View check run for this annotation

Codecov / codecov/patch

pkg/directory/directory.go#L36-L37

Added lines #L36 - L37 were not covered by tests

if isInScope(absPath, rootPath) {
relPath := strings.TrimPrefix(absPath, rootPath+"/")
Expand Down

0 comments on commit 4f557ae

Please sign in to comment.