@@ -15,22 +15,23 @@ const (
15
15
profileExtention = "profile"
16
16
)
17
17
18
- // Create directory if it doesn't exists
18
+ // Create directory if it doesn't exists.
19
19
func createDirIfNotExist (dir string ) error {
20
20
if _ , err := os .Stat (dir ); os .IsNotExist (err ) {
21
- err = os .MkdirAll (dir , 0755 )
21
+ err = os .MkdirAll (dir , 0o755 ) //nolint:gomnd //Rights used only there so it doesn't make sense to move it to const
22
+
22
23
return err
23
24
}
24
25
25
26
return nil
26
27
}
27
28
28
- // Get configuration directory relative path
29
+ // Get configuration directory relative path.
29
30
func getConfigDirRelativePath () string {
30
31
return viper .GetString ("configDir" )
31
32
}
32
33
33
- // Get configuration directory absolute path
34
+ // Get configuration directory absolute path.
34
35
func getConfigDirAbsolutePath () (string , error ) {
35
36
configDir , err := homedir .Expand (getConfigDirRelativePath ())
36
37
if err != nil {
@@ -40,40 +41,45 @@ func getConfigDirAbsolutePath() (string, error) {
40
41
return configDir , nil
41
42
}
42
43
43
- // Prompts string with label
44
+ // Prompts string with label.
44
45
func prompt (label string ) string {
45
46
reader := bufio .NewReader (os .Stdin )
47
+
46
48
fmt .Printf ("%s: " , label )
49
+
47
50
str , err := reader .ReadString ('\n' )
48
51
if err != nil {
49
52
fmt .Println ("Prompt failed:" )
50
53
fmt .Println (err )
51
54
os .Exit (1 )
52
55
}
56
+
53
57
return str [:len (str )- 1 ]
54
58
}
55
59
56
- // Prompts empty GitUser fields
60
+ // Prompts empty GitUser fields.
57
61
func promptGitUser (user * profile.GitUser ) {
58
62
user .Name = prompt ("Name" )
59
63
user .Email = prompt ("Email" )
60
64
user .SigningKey = prompt ("Signing Key" )
61
65
}
62
66
63
- // Prompts yes or now answer
67
+ // Prompts yes or now answer.
64
68
func promptYesNo (label string ) bool {
65
69
answer := prompt (label + " [y/N]" )
70
+
66
71
return (answer == "y" || answer == "Y" )
67
72
}
68
73
69
- // Get profile file path
74
+ // Get profile file path.
70
75
func getProfilePath (configDir , profileName string ) string {
71
76
return filepath .Join (configDir , profileName + "." + profileExtention )
72
77
}
73
78
74
- // Check if file exists
79
+ // Check if file exists.
75
80
func isFileExist (path string ) bool {
76
81
absolutePath , _ := homedir .Expand (path )
77
82
_ , err := os .Stat (absolutePath )
83
+
78
84
return ! os .IsNotExist (err )
79
85
}
0 commit comments