list: use homedir rather than os/user
Signed-off-by: Andrea Luzzardi <aluzzardi@gmail.com>
This commit is contained in:
parent
6e215b194e
commit
41620e6383
@ -3,11 +3,11 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
|
"github.com/mitchellh/go-homedir"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"go.dagger.io/dagger/cmd/dagger/cmd/common"
|
"go.dagger.io/dagger/cmd/dagger/cmd/common"
|
||||||
@ -48,14 +48,12 @@ var listCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
func formatPath(p string) string {
|
func formatPath(p string) string {
|
||||||
usr, err := user.Current()
|
dir, err := homedir.Dir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Ignore error
|
// Ignore error
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := usr.HomeDir
|
|
||||||
|
|
||||||
if strings.HasPrefix(p, dir) {
|
if strings.HasPrefix(p, dir) {
|
||||||
return path.Join("~", p[len(dir):])
|
return path.Join("~", p[len(dir):])
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user