Skip to content

Commit

Permalink
New flag: workflow show --event-details
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed May 10, 2024
1 parent f806427 commit ecd75a3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 21 deletions.
6 changes: 4 additions & 2 deletions temporalcli/commands.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ func NewTemporalWorkflowExecuteCommand(cctx *CommandContext, parent *TemporalWor
s.SharedWorkflowStartOptions.buildFlags(cctx, s.Command.Flags())
s.WorkflowStartOptions.buildFlags(cctx, s.Command.Flags())
s.PayloadInputOptions.buildFlags(cctx, s.Command.Flags())
s.Command.Flags().BoolVar(&s.EventDetails, "event-details", false, "If set when using text output, this will print the event details instead of just the event during workflow progress. If set when using JSON output, this will include the entire \"history\" JSON key of the started run (does not follow runs).")
s.Command.Flags().BoolVar(&s.EventDetails, "event-details", false, "If set when using text output, include event details JSON in printed output. If set when using JSON output, this will include the entire \"history\" JSON key of the started run (does not follow runs).")
s.Command.Run = func(c *cobra.Command, args []string) {
if err := s.run(cctx, args); err != nil {
cctx.Options.Fail(err)
Expand Down Expand Up @@ -1936,7 +1936,8 @@ type TemporalWorkflowShowCommand struct {
Parent *TemporalWorkflowCommand
Command cobra.Command
WorkflowReferenceOptions
Follow bool
Follow bool
EventDetails bool
}

func NewTemporalWorkflowShowCommand(cctx *CommandContext, parent *TemporalWorkflowCommand) *TemporalWorkflowShowCommand {
Expand All @@ -1953,6 +1954,7 @@ func NewTemporalWorkflowShowCommand(cctx *CommandContext, parent *TemporalWorkfl
s.Command.Args = cobra.NoArgs
s.WorkflowReferenceOptions.buildFlags(cctx, s.Command.Flags())
s.Command.Flags().BoolVarP(&s.Follow, "follow", "f", false, "Follow the progress of a Workflow Execution in real time (does not apply to JSON output).")
s.Command.Flags().BoolVar(&s.EventDetails, "event-details", false, "If set when using text output, include event details JSON in printed output.")
s.Command.Run = func(c *cobra.Command, args []string) {
if err := s.run(cctx, args); err != nil {
cctx.Options.Fail(err)
Expand Down
2 changes: 1 addition & 1 deletion temporalcli/commands.workflow_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (c *TemporalWorkflowShowCommand) run(cctx *CommandContext, _ []string) erro
client: cl,
workflowID: c.WorkflowId,
runID: c.RunId,
includeDetails: true,
includeDetails: c.EventDetails,
follow: c.Follow,
}
if !cctx.JSONOutput {
Expand Down
43 changes: 28 additions & 15 deletions temporalcli/commands.workflow_view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ func (s *SharedServerSuite) TestWorkflow_Describe_ResetPoints() {
}

func (s *SharedServerSuite) TestWorkflow_Show_Follow() {
s.testWorkflowShowFollow(true)
s.testWorkflowShowFollow(false)
}

func (s *SharedServerSuite) testWorkflowShowFollow(eventDetails bool) {
s.Worker().OnDevWorkflow(func(ctx workflow.Context, a any) (any, error) {
sigs := 0
for {
Expand All @@ -171,15 +176,19 @@ func (s *SharedServerSuite) TestWorkflow_Show_Follow() {
doneFollowingCh := make(chan struct{})
// Follow the workflow
go func() {
res := s.Execute(
"workflow", "show",
args := []string{"workflow", "show",
"--address", s.Address(),
"-w", run.GetID(),
"--follow",
)
"--follow"}
if eventDetails {
args = append(args, "--event-details")
}
res := s.Execute(args...)
s.NoError(res.Err)
out := res.Stdout.String()
s.Contains(out, "my-signal")
if eventDetails {
s.Contains(out, "my-signal")
}
s.Contains(out, "Result \"hi!\"")
close(doneFollowingCh)
}()
Expand All @@ -194,6 +203,10 @@ func (s *SharedServerSuite) TestWorkflow_Show_Follow() {
}

func (s *SharedServerSuite) TestWorkflow_Show_NoFollow() {
s.testWorkflowShowNoFollow(true)
s.testWorkflowShowNoFollow(false)
}
func (s *SharedServerSuite) testWorkflowShowNoFollow(eventDetails bool) {
s.Worker().OnDevWorkflow(func(ctx workflow.Context, a any) (any, error) {
sigs := 0
for {
Expand All @@ -215,11 +228,13 @@ func (s *SharedServerSuite) TestWorkflow_Show_NoFollow() {
)
s.NoError(err)

res := s.Execute(
"workflow", "show",
args := []string{"workflow", "show",
"--address", s.Address(),
"-w", run.GetID(),
)
"-w", run.GetID()}
if eventDetails {
args = append(args, "--event-details")
}
res := s.Execute(args...)
s.NoError(res.Err)
out := res.Stdout.String()
s.NotContains(out, "my-signal")
Expand All @@ -230,14 +245,12 @@ func (s *SharedServerSuite) TestWorkflow_Show_NoFollow() {
s.NoError(s.Client.SignalWorkflow(s.Context, run.GetID(), "", "my-signal", nil))
s.NoError(run.Get(s.Context, nil))

res = s.Execute(
"workflow", "show",
"--address", s.Address(),
"-w", run.GetID(),
)
res = s.Execute(args...)
s.NoError(res.Err)
out = res.Stdout.String()
s.Contains(out, "my-signal")
if eventDetails {
s.Contains(out, "my-signal")
}
s.Contains(out, "Result \"hi!\"")
}

Expand Down
6 changes: 3 additions & 3 deletions temporalcli/commandsmd/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,8 @@ temporal workflow execute

#### Options

* `--event-details` (bool) - If set when using text output, this will print the event details instead of just the event
during workflow progress. If set when using JSON output, this will include the entire "history" JSON key of the
started run (does not follow runs).
* `--event-details` (bool) - If set when using text output, include event details JSON in printed output. If set when
using JSON output, this will include the entire "history" JSON key of the started run (does not follow runs).

Includes options set for [shared workflow start](#options-set-for-shared-workflow-start).
Includes options set for [workflow start](#options-set-for-workflow-start).
Expand Down Expand Up @@ -926,6 +925,7 @@ Use the options listed below to change the command's behavior.

* `--follow`, `-f` (bool) - Follow the progress of a Workflow Execution in real time (does not apply
to JSON output).
* `--event-details` (bool) - If set when using text output, include event details JSON in printed output.

Includes options set for [workflow reference](#options-set-for-workflow-reference).

Expand Down

0 comments on commit ecd75a3

Please sign in to comment.