@@ -41,17 +41,20 @@ func login(_ *cobra.Command, _ []string) {
4141 var token string
4242
4343 for {
44- fmt .Print ("OpenProject host URL: " )
44+ printer .Debug (Verbose , "Parsing host URL ..." )
45+ printer .Input ("OpenProject host URL: " )
46+
4547 ok , msg , host := parseHostUrl ()
4648 if ! ok {
47- fmt . Println (msg )
49+ printer . ErrorText (msg )
4850 continue
4951 }
5052
51- requests .Init (host , "" )
53+ printer .Debug (Verbose , "Initializing requests client ..." )
54+ requests .Init (host , "" , Verbose )
5255 ok = checkOpenProjectApi ()
5356 if ! ok {
54- fmt . Println (noOpInstanceError )
57+ printer . ErrorText (noOpInstanceError )
5558 continue
5659 }
5760
@@ -69,7 +72,7 @@ func login(_ *cobra.Command, _ []string) {
6972
7073 token = common .SanitizeLineBreaks (t )
7174
72- requests .Init (hostUrl , token )
75+ requests .Init (hostUrl , token , Verbose )
7376 user , err := users .Me ()
7477 if err != nil {
7578 printer .Error (err )
@@ -92,24 +95,39 @@ func parseHostUrl() (ok bool, errMessage string, host *url.URL) {
9295
9396 input , err := reader .ReadString ('\n' )
9497 if err != nil {
98+ printer .Debug (Verbose , fmt .Sprintf ("Error reading string input: %+v" , err ))
9599 return false , urlInputError , nil
96100 }
97101
102+ printer .Debug (Verbose , fmt .Sprintf ("Parsed input %q." , input ))
103+ printer .Debug (Verbose , "Sanitizing input ..." )
104+
98105 input = common .SanitizeLineBreaks (input )
99106 input = strings .TrimSuffix (input , "/" )
107+
108+ printer .Debug (Verbose , fmt .Sprintf ("Sanitized input '%s'." , input ))
109+ printer .Debug (Verbose , "Parsing input as url ..." )
110+
100111 parsed , err := url .Parse (input )
101112 if err != nil {
113+ printer .Debug (Verbose , fmt .Sprintf ("Error parsing url: %+v" , err ))
102114 return false , urlInputError , nil
103115 }
104116
117+ printer .Debug (Verbose , fmt .Sprintf ("Parsed url '%s'." , parsed ))
118+ printer .Debug (Verbose , "Checking for http host and scheme ..." )
119+
105120 if parsed .Scheme == "" || parsed .Host == "" {
106121 return false , missingSchemeError , nil
107122 }
108123
124+ printer .Debug (Verbose , "Parsing input successful, continuing with next steps." )
109125 return true , "" , parsed
110126}
111127
112128func checkOpenProjectApi () bool {
129+ printer .Debug (Verbose , "Fetching API root to check for instance configuration ..." )
130+
113131 response , err := requests .Get (paths .Root (), nil )
114132 if err != nil {
115133 return false
0 commit comments