@@ -150,43 +150,39 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
150
150
app .Flag ("user" , "user name used within the Jira service" ).Short ('u' ).SetValue (& globals .User )
151
151
app .Flag ("login" , "login name that corresponds to the user used for authentication" ).SetValue (& globals .Login )
152
152
153
- o = o .WithPreCallback (
154
- func (req * http.Request ) (* http.Request , error ) {
155
- if globals .AuthMethod () == "api-token" {
156
- // need to set basic auth header with user@domain:api-token
157
- token := globals .GetPass ()
158
- authHeader := fmt .Sprintf ("Basic %s" , base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf ("%s:%s" , globals .Login .Value , token ))))
159
- req .Header .Add ("Authorization" , authHeader )
160
- }
161
- return req , nil
162
- },
163
- )
164
-
165
- o = o .WithPostCallback (
166
- func (req * http.Request , resp * http.Response ) (* http.Response , error ) {
167
- if globals .AuthMethod () == "session" {
168
- authUser := resp .Header .Get ("X-Ausername" )
169
- if authUser == "" || authUser == "anonymous" {
170
- // preserve the --quiet value, we need to temporarily disable it so
171
- // the normal login output is surpressed
172
- defer func (quiet bool ) {
173
- globals .Quiet .Value = quiet
174
- }(globals .Quiet .Value )
175
- globals .Quiet .Value = true
176
-
177
- // we are not logged in, so force login now by running the "login" command
178
- app .Parse ([]string {"login" })
179
-
180
- // rerun the original request
181
- return o .Do (req )
182
- }
183
- } else if globals .AuthMethod () == "api-token" && resp .StatusCode == 401 {
184
- globals .SetPass ("" )
153
+ o = o .WithPreCallback (func (req * http.Request ) (* http.Request , error ) {
154
+ if globals .AuthMethod () == "api-token" {
155
+ // need to set basic auth header with user@domain:api-token
156
+ token := globals .GetPass ()
157
+ authHeader := fmt .Sprintf ("Basic %s" , base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf ("%s:%s" , globals .Login .Value , token ))))
158
+ req .Header .Add ("Authorization" , authHeader )
159
+ }
160
+ return req , nil
161
+ })
162
+
163
+ o = o .WithPostCallback (func (req * http.Request , resp * http.Response ) (* http.Response , error ) {
164
+ if globals .AuthMethod () == "session" {
165
+ authUser := resp .Header .Get ("X-Ausername" )
166
+ if authUser == "" || authUser == "anonymous" {
167
+ // preserve the --quiet value, we need to temporarily disable it so
168
+ // the normal login output is surpressed
169
+ defer func (quiet bool ) {
170
+ globals .Quiet .Value = quiet
171
+ }(globals .Quiet .Value )
172
+ globals .Quiet .Value = true
173
+
174
+ // we are not logged in, so force login now by running the "login" command
175
+ app .Parse ([]string {"login" })
176
+
177
+ // rerun the original request
185
178
return o .Do (req )
186
179
}
187
- return resp , nil
188
- },
189
- )
180
+ } else if globals .AuthMethod () == "api-token" && resp .StatusCode == 401 {
181
+ globals .SetPass ("" )
182
+ return o .Do (req )
183
+ }
184
+ return resp , nil
185
+ })
190
186
191
187
for _ , command := range globalCommandRegistry {
192
188
copy := command
@@ -238,14 +234,12 @@ func register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree) {
238
234
copy .Entry .UsageFunc (fig , cmd )
239
235
}
240
236
241
- cmd .Action (
242
- func (_ * kingpin.ParseContext ) error {
243
- if logging .GetLevel ("" ) > logging .DEBUG {
244
- o = o .WithTrace (true )
245
- }
246
- return copy .Entry .ExecuteFunc (o , & globals )
247
- },
248
- )
237
+ cmd .Action (func (_ * kingpin.ParseContext ) error {
238
+ if logging .GetLevel ("" ) > logging .DEBUG {
239
+ o = o .WithTrace (true )
240
+ }
241
+ return copy .Entry .ExecuteFunc (o , & globals )
242
+ })
249
243
}
250
244
}
251
245
@@ -321,35 +315,42 @@ func (o *CommonOptions) editFile(fileName string) (changes bool, err error) {
321
315
}
322
316
323
317
// now we just need to diff the files to see if there are any changes
324
- var oldHandle , newHandle * os.File
325
- var oldStat , newStat os.FileInfo
326
- if oldHandle , err = os .Open (tmpFileNameOrig ); err == nil {
327
- if newHandle , err = os .Open (fileName ); err == nil {
328
- if oldStat , err = oldHandle .Stat (); err == nil {
329
- if newStat , err = newHandle .Stat (); err == nil {
330
- // different sizes, so must have changes
331
- if oldStat .Size () != newStat .Size () {
332
- return true , err
333
- }
334
- oldBuf , newBuf := make ([]byte , 1024 ), make ([]byte , 1024 )
335
- var oldCount , newCount int
336
- // loop though 1024 bytes at a time comparing the buffers for changes
337
- for err != io .EOF {
338
- oldCount , _ = oldHandle .Read (oldBuf )
339
- newCount , err = newHandle .Read (newBuf )
340
- if oldCount != newCount {
341
- return true , nil
342
- }
343
- if ! bytes .Equal (oldBuf [:oldCount ], newBuf [:newCount ]) {
344
- return true , nil
345
- }
346
- }
347
- return false , nil
348
- }
349
- }
318
+ f1 , err := os .Open (tmpFileNameOrig )
319
+ if err != nil {
320
+ return false , err
321
+ }
322
+ f2 , err := os .Open (fileName )
323
+ if err != nil {
324
+ return false , err
325
+ }
326
+
327
+ stat1 , err := f1 .Stat ()
328
+ if err != nil {
329
+ return false , err
330
+ }
331
+ stat2 , err := f2 .Stat ()
332
+ if err != nil {
333
+ return false , err
334
+ }
335
+ // different sizes, so must have changes
336
+ if stat1 .Size () != stat2 .Size () {
337
+ return true , nil
338
+ }
339
+
340
+ p1 , p2 := make ([]byte , 1024 ), make ([]byte , 1024 )
341
+ var n1 , n2 int
342
+ // loop though 1024 bytes at a time comparing the buffers for changes
343
+ for err != io .EOF {
344
+ n1 , _ = f1 .Read (p1 )
345
+ n2 , err = f2 .Read (p2 )
346
+ if n1 != n2 {
347
+ return true , nil
348
+ }
349
+ if ! bytes .Equal (p1 [:n1 ], p2 [:n2 ]) {
350
+ return true , nil
350
351
}
351
352
}
352
- return false , err
353
+ return false , nil
353
354
}
354
355
355
356
var EditLoopAbort = fmt .Errorf ("edit Loop aborted by request" )
0 commit comments