mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	pkg/homedir: implement GetShortcutString()
Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>
This commit is contained in:
		
							parent
							
								
									27a73a98b7
								
							
						
					
					
						commit
						8ca37e4760
					
				
					 2 changed files with 16 additions and 0 deletions
				
			
		| 
						 | 
				
			
			@ -14,3 +14,12 @@ func Get() string {
 | 
			
		|||
	}
 | 
			
		||||
	return os.Getenv("HOME")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// GetShortcutString returns the string that is shortcut to user's home directory
 | 
			
		||||
// in the native shell of the platform running on.
 | 
			
		||||
func GetShortcutString() string {
 | 
			
		||||
	if runtime.GOOS == "windows" {
 | 
			
		||||
		return "%USERPROFILE%" // be careful while using in format functions
 | 
			
		||||
	}
 | 
			
		||||
	return "~"
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,3 +15,10 @@ func TestGet(t *testing.T) {
 | 
			
		|||
		t.Fatalf("returned path is not absolute: %s", home)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func TestGetShortcutString(t *testing.T) {
 | 
			
		||||
	shortcut := GetShortcutString()
 | 
			
		||||
	if shortcut == "" {
 | 
			
		||||
		t.Fatal("returned shortcut string is empty")
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue