Skip to content

Commit

Permalink
refactor: use new helper
Browse files Browse the repository at this point in the history
  • Loading branch information
dpastoor committed Jul 1, 2022
1 parent 7e906f1 commit 89c0764
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions cmd/ls.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"os"
"path/filepath"
"sort"

"github.com/dpastoor/qvm/internal/config"
Expand Down Expand Up @@ -36,10 +35,6 @@ func newLs(lsOpts lsOpts) error {
fmt.Printf("%s | %s | %s\n", r.GetTagName(), createdAt.Format("2006-01-02"), r.GetName())
}
} else {
activePath, err := filepath.EvalSymlinks(filepath.Join(config.GetPathToActiveBinDir(), "quarto"))
if err != nil && !errors.Is(err, os.ErrNotExist) {
return err
}
entries, err := os.ReadDir(config.GetPathToVersionsDir())
if errors.Is(err, os.ErrNotExist) {
fmt.Println("No installed quarto versions found")
Expand All @@ -61,11 +56,14 @@ func newLs(lsOpts lsOpts) error {
sort.Slice(entries, func(i, j int) bool {
return entries[i].Name() > entries[j].Name()
})
// no need to worry about errors since just need to know version
// for matching below and won't match if doesn't exist
activeVersion, _ := config.GetActiveVersion()
for _, e := range entries {
if e.IsDir() {
dinfo, _ := e.Info()
name := e.Name()
if filepath.Base(filepath.Dir(filepath.Dir(activePath))) == e.Name() {
if activeVersion == e.Name() {
name += " (active)"
} else {
name += " "
Expand Down

0 comments on commit 89c0764

Please sign in to comment.