From 4f557aec5ccc447bc80c8d340d8e7abc1ca79167 Mon Sep 17 00:00:00 2001 From: Ivan Ilves Date: Sun, 27 Oct 2024 08:51:05 +0100 Subject: [PATCH] feat(issues/57): use ${EDITOR} variable to edit files --- cmd/travelgrunt/main.go | 8 +++++++- pkg/config/config.go | 2 ++ pkg/directory/directory.go | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cmd/travelgrunt/main.go b/cmd/travelgrunt/main.go index 4c6bfbf..ad3cf86 100644 --- a/cmd/travelgrunt/main.go +++ b/cmd/travelgrunt/main.go @@ -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") flag.BoolVar(&top, "top", false, "get to the repository top level (root) path") flag.BoolVar(&version, "version", false, "print application version and exit") } @@ -132,6 +134,8 @@ func main() { cfg = cfg.WithNameEx(expression) } + cfg.UseFiles = editFile + entries, paths, err := directory.Collect(rootPath, cfg) if err != nil { @@ -149,7 +153,9 @@ func main() { if outFile != "" { path := getEntryPath(entries, selected, rootPath) - tag(path) + if !editFile { + tag(path) + } writeFileAndExit(outFile, path) } diff --git a/pkg/config/config.go b/pkg/config/config.go index f16a6d5..2dd306b 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -16,6 +16,7 @@ type Config struct { Rules []rule.Rule `yaml:"rules"` IsDefault bool + UseFiles bool } // DefaultConfig returns default travelgrunt repo-level configuration @@ -23,6 +24,7 @@ func DefaultConfig() Config { return Config{ Rules: []rule.Rule{{ModeFn: mode.IsTerragrunt}}, IsDefault: true, + UseFiles: false, } } diff --git a/pkg/directory/directory.go b/pkg/directory/directory.go index fa499cb..70f59e2 100644 --- a/pkg/directory/directory.go +++ b/pkg/directory/directory.go @@ -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 + } if isInScope(absPath, rootPath) { relPath := strings.TrimPrefix(absPath, rootPath+"/")