Skip to content

Commit

Permalink
add -o short option for argo cli get command (#5533)
Browse files Browse the repository at this point in the history
  • Loading branch information
vivek-26 authored Apr 7, 2021
1 parent 0edd32b commit 2baae1d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
17 changes: 14 additions & 3 deletions cmd/argo/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,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().BoolVar(&noUtf8, "no-utf8", false, "Use plain 7-bits ascii characters")
command.Flags().StringVar(&getArgs.status, "status", "", "Filter by status (Pending, Running, Succeeded, Skipped, Failed, Error)")
Expand All @@ -106,7 +106,7 @@ func printWorkflow(wf *wfv1.Workflow, getArgs getFlags) {
case "yaml":
outBytes, _ := yaml.Marshal(wf)
fmt.Print(string(outBytes))
case "wide", "":
case "short", "wide", "":
fmt.Print(printWorkflowHelper(wf, getArgs))
default:
log.Fatalf("Unknown output format: %s", getArgs.output)
Expand Down Expand Up @@ -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\tTEMPLATE\tPODNAME\tDURATION\tMESSAGE\tNODENAME\n", ansiFormat("STEP", FgDefault))
} else {
_, _ = fmt.Fprintf(w, "%s\tTEMPLATE\tPODNAME\tDURATION\tMESSAGE\n", ansiFormat("STEP", FgDefault))
}
Expand All @@ -209,7 +211,11 @@ 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()
}
}
writerBuffer := new(bytes.Buffer)
printer.PrintSecurityNudges(*wf, writerBuffer)
Expand Down Expand Up @@ -539,6 +545,11 @@ 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" {
if node.Type == wfv1.NodeTypePod {
args[len(args)-1] = 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...)
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/argo/commands/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func TestPrintNode(t *testing.T) {
node.Type = wfv1.NodeTypePod
testPrintNodeImpl(t, fmt.Sprintf("%s %s\t%s/%s\t%s\t%s\t%s\t%s\t%s\t%s\n", jobStatusIconMap[wfv1.NodeRunning], nodeName, nodeTemplateRefName, nodeTemplateRefName, nodeID, "0s", getArtifactsString(node), nodeMessage, "", kubernetesNodeName), node, getArgs)

getArgs.output = "short"
testPrintNodeImpl(t, fmt.Sprintf("%s %s\t%s/%s\t%s\t%s\t%s\t%s\n", nodeTypeIconMap[wfv1.NodeTypeSuspend], nodeName, nodeTemplateRefName, nodeTemplateRefName, nodeID, "0s", nodeMessage, kubernetesNodeName), node, getArgs)

getArgs.status = "foobar"
testPrintNodeImpl(t, "", node, getArgs)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/cli/argo_get.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ argo get WORKFLOW... [flags]
--no-color Disable colorized output
--no-utf8 Use plain 7-bits ascii characters
--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)
```

Expand Down

0 comments on commit 2baae1d

Please sign in to comment.