From 49f6cdc54e120b99030b5ba9ad6516fd50b82eb9 Mon Sep 17 00:00:00 2001 From: Cory Bennett Date: Mon, 4 Sep 2017 19:09:38 -0700 Subject: [PATCH] tweak auto-login so it does not print the standard `jira login` command output --- cmd/jira/main.go | 12 ------------ jiracli/cli.go | 21 +++++++++++++++++++++ t/.jira.d/config.yml | 13 ++----------- 3 files changed, 23 insertions(+), 23 deletions(-) mode change 100755 => 100644 t/.jira.d/config.yml diff --git a/cmd/jira/main.go b/cmd/jira/main.go index 70fbe85..aa60a5f 100644 --- a/cmd/jira/main.go +++ b/cmd/jira/main.go @@ -2,7 +2,6 @@ package main import ( "fmt" - "net/http" "os" "path/filepath" "regexp" @@ -92,17 +91,6 @@ func main() { } o := oreo.New().WithCookieFile(filepath.Join(jiracli.Homedir(), fig.ConfigDir, "cookies.js")) - o = o.WithPostCallback( - func(req *http.Request, resp *http.Response) (*http.Response, error) { - authUser := resp.Header.Get("X-Ausername") - if authUser == "" || authUser == "anonymous" { - // we are not logged in, so force login now by running the "login" command - app.Parse([]string{"login"}) - return o.Do(req) - } - return resp, nil - }, - ) registry := []jiracli.CommandRegistry{ jiracli.CommandRegistry{ diff --git a/jiracli/cli.go b/jiracli/cli.go index 5ec4fb9..843024c 100644 --- a/jiracli/cli.go +++ b/jiracli/cli.go @@ -89,6 +89,27 @@ func Register(app *kingpin.Application, o *oreo.Client, fig *figtree.FigTree, re return nil }) + o = o.WithPostCallback( + func(req *http.Request, resp *http.Response) (*http.Response, error) { + authUser := resp.Header.Get("X-Ausername") + if authUser == "" || authUser == "anonymous" { + // preserve the --quiet value, we need to temporarily disable it so + // the normal login output is surpressed + defer func(quiet bool) { + globals.Quiet.Value = quiet + }(globals.Quiet.Value) + globals.Quiet.Value = true + + // we are not logged in, so force login now by running the "login" command + app.Parse([]string{"login"}) + + // rerun the original request + return o.Do(req) + } + return resp, nil + }, + ) + for _, command := range reg { copy := command commandFields := strings.Fields(copy.Command) diff --git a/t/.jira.d/config.yml b/t/.jira.d/config.yml old mode 100755 new mode 100644 index 3869875..36df77e --- a/t/.jira.d/config.yml +++ b/t/.jira.d/config.yml @@ -1,14 +1,5 @@ -#!/bin/sh -cat <