diff options
| author | Ophestra <cat@gensokyo.uk> | 2026-07-07 13:26:58 +0900 |
|---|---|---|
| committer | Ophestra <cat@gensokyo.uk> | 2026-07-07 13:26:58 +0900 |
| commit | 810b806a15f0964dec97357e49a17002ecdf65f1 (patch) | |
| tree | 90ffca8a4ff84a0b7429ffe2d57099959785bc76 /cmd | |
| parent | 4a42657d889f11d90a0a0c13bcdd8ef5b6448a83 (diff) | |
cmd/app: omit hidden files
This avoids vim swap files breaking scripts.
Signed-off-by: Ophestra <cat@gensokyo.uk>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/app/app.go | 17 | ||||
| -rw-r--r-- | cmd/app/main.go | 25 |
2 files changed, 19 insertions, 23 deletions
diff --git a/cmd/app/app.go b/cmd/app/app.go index 4e4f314d..9679413f 100644 --- a/cmd/app/app.go +++ b/cmd/app/app.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "io" + "os" "strconv" "strings" @@ -335,3 +336,19 @@ func parse( return &c, nil } + +// list prints names of non-hidden entries in pathname. +func list(pathname *check.Absolute, dir bool) error { + dents, err := os.ReadDir(pathname.String()) + if err != nil { + return err + } + for _, dent := range dents { + name := dent.Name() + if (dent.IsDir() != dir) || (len(name) > 0 && name[0] == '.') { + continue + } + fmt.Println(dent.Name()) + } + return nil +} diff --git a/cmd/app/main.go b/cmd/app/main.go index 146a5546..00bceb57 100644 --- a/cmd/app/main.go +++ b/cmd/app/main.go @@ -7,7 +7,6 @@ package main import ( "context" "errors" - "fmt" "io" "log" "os" @@ -77,17 +76,7 @@ func main() { "enter", "Enter mutable state template", func(args []string) error { if len(args) != 1 { - dents, err := os.ReadDir(template.String()) - if err != nil { - return err - } - for _, dent := range dents { - if !dent.IsDir() { - continue - } - fmt.Println(dent.Name()) - } - return nil + return list(template, true) } config := hst.Config{ @@ -159,17 +148,7 @@ func main() { "run", "Start the named application", func(args []string) error { if len(args) < 1 { - dents, err := os.ReadDir(base.Append("app").String()) - if err != nil { - return err - } - for _, dent := range dents { - if dent.IsDir() { - continue - } - fmt.Println(dent.Name()) - } - return nil + return list(base.Append("app"), false) } var config *hst.Config |
