Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 14 additions & 29 deletions cmd/list.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package cmd

import (
"fmt"
"log"
"os"
"path/filepath"
"strings"

"github.com/arl/dirtree"
"github.com/notnmeyer/daylog-cli/internal/daylog"
"github.com/spf13/cobra"
)
Expand All @@ -27,9 +25,20 @@ to quickly create a Cobra application.`,
log.Fatal(err)
}

err = filepath.Walk(dl.ProjectPath, visit(dl.ProjectPath))
err = dirtree.Write(
os.Stdout,
dl.ProjectPath,
dirtree.Type("f"),
dirtree.ExcludeRoot,
dirtree.PrintMode(0),
// uhhhhhh, kind of lame
dirtree.Ignore(".git/*"),
dirtree.Ignore(".git/*/*"),
dirtree.Ignore(".git/*/*/*"),
dirtree.Ignore(".git/*/*/*/*"),
)
if err != nil {
fmt.Printf("error walking the path %v: %v\n", dl.ProjectPath, err)
log.Fatal(err)
}
},
}
Expand All @@ -47,27 +56,3 @@ func init() {
// is called directly, e.g.:
// listCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

func visit(root string) filepath.WalkFunc {
rootDepth := strings.Count(root, string(os.PathSeparator))

return func(path string, info os.FileInfo, err error) error {
// print the error, but we want to continue the traversal
if err != nil {
fmt.Println(err)
return nil
}

depth := strings.Count(path, string(os.PathSeparator)) - rootDepth

var item string
if info.IsDir() {
item = info.Name() + "/"
} else {
item = info.Name()
}

fmt.Println(strings.Repeat(" ", depth), item)
return nil
}
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.21

require (
github.com/adrg/xdg v0.4.0
github.com/arl/dirtree v0.1.3
github.com/charmbracelet/glamour v0.6.0
github.com/markusmobius/go-dateparser v1.2.1
github.com/spf13/cobra v1.7.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/adrg/xdg v0.4.0 h1:RzRqFcjH4nE5C6oTAxhBtoE2IRyjBSa62SCbyPidvls=
github.com/adrg/xdg v0.4.0/go.mod h1:N6ag73EX4wyxeaoeHctc1mas01KZgsj5tYiAIwqJE/E=
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
github.com/arl/dirtree v0.1.3 h1:Q1ldIP0t4CQH3vUujlSgHEKwa6TqloXuxLNQRJHpl5w=
github.com/arl/dirtree v0.1.3/go.mod h1:uVPZKJm2M2hHWWUw+47yimVo48wNHtXEs19wwQOmy/U=
github.com/aymanbagabas/go-osc52 v1.0.3 h1:DTwqENW7X9arYimJrPeGZcV0ln14sGMt3pHZspWD+Mg=
github.com/aymanbagabas/go-osc52 v1.0.3/go.mod h1:zT8H+Rk4VSabYN90pWyugflM3ZhpTZNC7cASDfUCdT4=
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
Expand Down