From 68db516e316c0b6290d1be9914ff96f1bb131afe Mon Sep 17 00:00:00 2001 From: Sanooj Mananghat Date: Tue, 6 Oct 2020 13:17:59 +0530 Subject: [PATCH 1/3] Adding -o short option for argocli get command --- cmd/argo/commands/get.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/cmd/argo/commands/get.go b/cmd/argo/commands/get.go index b73a0ac279bc..3d22a9cebc3f 100644 --- a/cmd/argo/commands/get.go +++ b/cmd/argo/commands/get.go @@ -86,7 +86,7 @@ func NewGetCommand() *cobra.Command { }, } - command.Flags().StringVarP(&getArgs.output, "output", "o", "", "Output format. One of: json|yaml|wide") + command.Flags().StringVarP(&getArgs.output, "output", "o", "", "Output format. One of: json|yaml|short|wide") command.Flags().BoolVar(&noColor, "no-color", false, "Disable colorized output") command.Flags().StringVar(&getArgs.status, "status", "", "Filter by status (Pending, Running, Succeeded, Skipped, Failed, Error)") command.Flags().StringVar(&getArgs.nodeFieldSelectorString, "node-field-selector", "", "selector of node to display, eg: --node-field-selector phase=abc") @@ -107,7 +107,7 @@ func printWorkflow(wf *wfv1.Workflow, getArgs getFlags) { case "yaml": outBytes, _ := yaml.Marshal(wf) fmt.Print(string(outBytes)) - case "wide", "": + case "wide", "short", "": fmt.Print(printWorkflowHelper(wf, getArgs)) default: log.Fatalf("Unknown output format: %s", getArgs.output) @@ -189,6 +189,8 @@ func printWorkflowHelper(wf *wfv1.Workflow, getArgs getFlags) string { // apply a dummy FgDefault format to align tab writer with the rest of the columns if getArgs.output == "wide" { _, _ = fmt.Fprintf(w, "%s\tTEMPLATE\tPODNAME\tDURATION\tARTIFACTS\tMESSAGE\tRESOURCESDURATION\tNODENAME\n", ansiFormat("STEP", FgDefault)) + } else if getArgs.output == "short" { + _, _ = fmt.Fprintf(w, "%s\tDURATION\tMESSAGE\tRESOURCESDURATION\tNODENAME\n", ansiFormat("STEP", FgDefault)) } else { _, _ = fmt.Fprintf(w, "%s\tTEMPLATE\tPODNAME\tDURATION\tMESSAGE\n", ansiFormat("STEP", FgDefault)) } @@ -209,7 +211,12 @@ func printWorkflowHelper(wf *wfv1.Workflow, getArgs getFlags) string { onExitRoot.renderNodes(w, wf, 0, " ", " ", getArgs) } _ = w.Flush() - out += writerBuffer.String() + if getArgs.output == "short" { + out = writerBuffer.String() + } else { + out += writerBuffer.String() + } + } return out } @@ -512,6 +519,14 @@ func printNode(w *tabwriter.Writer, node wfv1.NodeStatus, nodePrefix string, get args[len(args)-1] = node.HostNodeName } _, _ = fmt.Fprintf(w, "%s%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", args...) + } else if getArgs.output == "short" { + args[2] = args[len(args)-3] + args[3] = args[len(args)-2] + args[4] = node.ResourcesDuration + if node.Type == wfv1.NodeTypePod { + args[len(args)-2] = node.HostNodeName + } + _, _ = fmt.Fprintf(w, "%s%s\t%s\t%s\t%s\t%s\t%s\n", args...) } else { _, _ = fmt.Fprintf(w, "%s%s\t%s\t%s\t%s\t%s\t%s\n", args...) } From 870abf84fa936d540c63cc383de74029c60bbb8f Mon Sep 17 00:00:00 2001 From: Sanooj Mananghat Date: Tue, 6 Oct 2020 13:38:49 +0530 Subject: [PATCH 2/3] Updating doc with -o short option for argocli get command --- docs/cli/argo_get.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cli/argo_get.md b/docs/cli/argo_get.md index 9cf6f0062af8..acb67ab0a1cf 100644 --- a/docs/cli/argo_get.md +++ b/docs/cli/argo_get.md @@ -28,7 +28,7 @@ argo get WORKFLOW... [flags] -h, --help help for get --no-color Disable colorized output --node-field-selector string selector of node to display, eg: --node-field-selector phase=abc - -o, --output string Output format. One of: json|yaml|wide + -o, --output string Output format. One of: json|yaml|short|wide --status string Filter by status (Pending, Running, Succeeded, Skipped, Failed, Error) ``` From 29e9199f313614d9d72ef69985395b6e48f6245b Mon Sep 17 00:00:00 2001 From: Sanooj Mananghat Date: Sat, 31 Oct 2020 22:34:07 +0530 Subject: [PATCH 3/3] Adding Unit test cases --- cmd/argo/commands/get.go | 7 ++----- cmd/argo/commands/get_test.go | 3 +++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cmd/argo/commands/get.go b/cmd/argo/commands/get.go index b600e4f22ac4..d3aed547b153 100644 --- a/cmd/argo/commands/get.go +++ b/cmd/argo/commands/get.go @@ -191,7 +191,7 @@ func printWorkflowHelper(wf *wfv1.Workflow, getArgs getFlags) string { if getArgs.output == "wide" { _, _ = fmt.Fprintf(w, "%s\tTEMPLATE\tPODNAME\tDURATION\tARTIFACTS\tMESSAGE\tRESOURCESDURATION\tNODENAME\n", ansiFormat("STEP", FgDefault)) } else if getArgs.output == "short" { - _, _ = fmt.Fprintf(w, "%s\tDURATION\tMESSAGE\tRESOURCESDURATION\tNODENAME\n", ansiFormat("STEP", FgDefault)) + _, _ = fmt.Fprintf(w, "%s\tTEMPLATE\tPODNAME\tDURATION\tMESSAGE\tNODENAME\n", ansiFormat("STEP", FgDefault)) } else { _, _ = fmt.Fprintf(w, "%s\tTEMPLATE\tPODNAME\tDURATION\tMESSAGE\n", ansiFormat("STEP", FgDefault)) } @@ -521,11 +521,8 @@ func printNode(w *tabwriter.Writer, node wfv1.NodeStatus, nodePrefix string, get } _, _ = fmt.Fprintf(w, "%s%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n", args...) } else if getArgs.output == "short" { - args[2] = args[len(args)-3] - args[3] = args[len(args)-2] - args[4] = node.ResourcesDuration if node.Type == wfv1.NodeTypePod { - args[len(args)-2] = node.HostNodeName + args[len(args)-1] = node.HostNodeName } _, _ = fmt.Fprintf(w, "%s%s\t%s\t%s\t%s\t%s\t%s\n", args...) } else { diff --git a/cmd/argo/commands/get_test.go b/cmd/argo/commands/get_test.go index 4c729ba371cb..a51eb613f141 100644 --- a/cmd/argo/commands/get_test.go +++ b/cmd/argo/commands/get_test.go @@ -93,6 +93,9 @@ func TestPrintNode(t *testing.T) { } testPrintNodeImpl(t, fmt.Sprintf("%s %s\t%s/%s\t%s\t%s\t%s\t%s\n", nodeTypeIconMap[wfv1.NodeTypeSuspend], nodeName, nodeTemplateRefName, nodeTemplateRefName, "", "", nodeMessage, ""), node, nodePrefix, getArgs) + getArgs.output = "short" + testPrintNodeImpl(t, fmt.Sprintf("%s %s\t%s/%s\t%s\t%s\t%s\t\n", nodeTypeIconMap[wfv1.NodeTypeSuspend], nodeName, nodeTemplateRefName, nodeTemplateRefName, "", "", nodeMessage), node, nodePrefix, getArgs) + getArgs.output = "wide" testPrintNodeImpl(t, fmt.Sprintf("%s %s\t%s/%s\t%s\t%s\t%s\t%s\t%s\t\n", nodeTypeIconMap[wfv1.NodeTypeSuspend], nodeName, nodeTemplateRefName, nodeTemplateRefName, "", "", getArtifactsString(node), nodeMessage, ""), node, nodePrefix, getArgs)