瀏覽代碼

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 <github@gone.nl>
Sebastiaan van Stijn 5 年之前
父節點
當前提交
9fd12a5e31
共有 1 個文件被更改,包括 9 次插入4 次删除
  1. 9 4
      libnetwork/client/mflag/flag.go

+ 9 - 4
libnetwork/client/mflag/flag.go

@@ -91,8 +91,6 @@ import (
 	"strings"
 	"text/tabwriter"
 	"time"
-
-	"github.com/docker/docker/pkg/homedir"
 )
 
 // 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 {
 // otherwise, the default values of all defined flags in the set.
 func (fs *FlagSet) PrintDefaults() {
 	writer := tabwriter.NewWriter(fs.Out(), 20, 1, 3, ' ', 0)
-	home := homedir.Get()
+	home, _ := os.UserHomeDir()
 
 	// Don't substitute when HOME is /
 	if runtime.GOOS != "windows" && home == "/" {
@@ -561,7 +559,7 @@ func (fs *FlagSet) PrintDefaults() {
 			val := flag.DefValue
 
 			if home != "" && strings.HasPrefix(val, home) {
-				val = homedir.GetShortcutString() + val[len(home):]
+				val = getShortcutString() + val[len(home):]
 			}
 
 			if isZeroValue(val) {
@@ -579,6 +577,13 @@ func (fs *FlagSet) PrintDefaults() {
 	writer.Flush()
 }
 
+func getShortcutString() string {
+	if runtime.GOOS == "windows" {
+		return "%USERPROFILE%"
+	}
+	return "~"
+}
+
 // PrintDefaults prints to standard error the default values of all defined command-line flags.
 func PrintDefaults() {
 	CommandLine.PrintDefaults()