Skip to content

Commit e6de8ae

Browse files
committed
client/mflag: remove use of docker/docker/pkg/homedir
The homedir package was only used to print default values for flags that contained paths inside the user's home-directory in a slightly nicer way (replace `/users/home` with `~`). Given that this is not critical, we can replace this with golang's function, which does not depend on libcontainer. There's still one use of the homedir package in docker/docker/opts, which is used by the dnet binary (but only requires the homedir package when running in rootless mode) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 28277c0 commit e6de8ae

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

client/mflag/flag.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ import (
9191
"strings"
9292
"text/tabwriter"
9393
"time"
94-
95-
"github.com/docker/docker/pkg/homedir"
9694
)
9795

9896
// ErrHelp is the error returned if the flag -help is invoked but no such flag is defined.
@@ -538,7 +536,7 @@ func isZeroValue(value string) bool {
538536
// otherwise, the default values of all defined flags in the set.
539537
func (fs *FlagSet) PrintDefaults() {
540538
writer := tabwriter.NewWriter(fs.Out(), 20, 1, 3, ' ', 0)
541-
home := homedir.Get()
539+
home, _ := os.UserHomeDir()
542540

543541
// Don't substitute when HOME is /
544542
if runtime.GOOS != "windows" && home == "/" {
@@ -561,7 +559,7 @@ func (fs *FlagSet) PrintDefaults() {
561559
val := flag.DefValue
562560

563561
if home != "" && strings.HasPrefix(val, home) {
564-
val = homedir.GetShortcutString() + val[len(home):]
562+
val = getShortcutString() + val[len(home):]
565563
}
566564

567565
if isZeroValue(val) {
@@ -579,6 +577,13 @@ func (fs *FlagSet) PrintDefaults() {
579577
writer.Flush()
580578
}
581579

580+
func getShortcutString() string {
581+
if runtime.GOOS == "windows" {
582+
return "%USERPROFILE%"
583+
}
584+
return "~"
585+
}
586+
582587
// PrintDefaults prints to standard error the default values of all defined command-line flags.
583588
func PrintDefaults() {
584589
CommandLine.PrintDefaults()

0 commit comments

Comments
 (0)