Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adding -o short option for argocli get command #4222

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions cmd/argo/commands/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down Expand Up @@ -190,6 +190,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" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit test?

_, _ = 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 @@ -210,7 +212,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
}
Expand Down Expand Up @@ -513,6 +520,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 @@ -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)

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 @@ -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)
```

Expand Down