Sitelet https://github.com/temporalio/cli/pull/666
Skip to content

Use YAML for CLI command generation - #666

Merged
yuandrew merged 17 commits into
temporalio:mainfrom
yuandrew:command-yaml-generation
Sep 23, 2024
Merged

yuandrew merged 17 commits into
temporalio:mainfrom
yuandrew:command-yaml-generation

Conversation

@yuandrew

@yuandrew yuandrew commented Sep 13, 2024 •

Copy link
Copy Markdown
Contributor

What was changed

Moved from Markdown to YAML for CLI command generation.

This switch also fixes a bug where option set aliases weren't being persisted to commands that use them (i.e. NewTemporalScheduleCreateCommand)

Why?

More standardized format, easier to parse and add to

Checklist

  1. Closes Switch to a common format for CLI command generation #620

  2. How was this tested:

Passes all CI tests

  1. Any docs updates needed?

Comment thread temporalcli/commandsmd/commands.yml
@yuandrew

Copy link
Copy Markdown
Contributor Author

the new format does not allow enum options for a string[] type, so all of the options mentioned in #670 will be temporarily changed to honor their current type (i.e. string[] will accept any string value), with the description containing the enum options.

Comment thread temporalcli/commandsmd/commands.yml Outdated
- name: raw
type: bool
description: Print properties without changing their format.
default: true

@yuandrew yuandrew Sep 18, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Description for this option used to be

* `--raw` (bool) -
  Print properties without changing their format.
  Defaults to true.

Which states defaults to true, but the code didn't seem to support that. Should this be removed from the description? A bool that defaults to true feels weird/doesn't make sense.

@yuandrew
yuandrew marked this pull request as ready for review September 18, 2024 18:35
Comment thread temporalcli/commandsmd/commands.yml
Comment thread temporalcli/commandsmd/commands.yml
Comment thread temporalcli/commands.gen.go Outdated
Comment thread temporalcli/commands.gen.go Outdated
s.Command.Flags().StringVar(&s.Description, "description", "", "Endpoint description in markdown format (encoded using the configured codec server).")
s.Command.Flags().StringVar(&s.DescriptionFile, "description-file", "", "Endpoint description file in markdown format (encoded using the configured codec server).")
s.Command.Flags().StringVar(&s.Description, "description", "", "Endpoint description in markdown format (encoded using the configured codec server).\n")
s.Command.Flags().StringVar(&s.DescriptionFile, "description-file", "", "Endpoint description file in markdown format (encoded using the configured codec server).\n")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same question as above—with options, I would expect this to be more of a problem, since it might mess up the formatting/spacing of options if some have a trailing \n and some don't.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point, I've removed all \n from the options, generated output should match previous markdown formatting

Comment thread temporalcli/commands.gen.go Outdated
Comment thread temporalcli/commandsmd/parse.go Outdated
Comment thread temporalcli/commandsmd/parse.go Outdated
@yuandrew
yuandrew force-pushed the command-yaml-generation branch from 15a7549 to ee16399 Compare September 19, 2024 20:31

@josh-berry josh-berry left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'll be honest that I didn't read the parser/generator changes super closely; I mostly looked at the generated output, which seems good to me. There's only one small comment about the log-format flag that's not a blocker for merging IMO. Otherwise LGTM!

Comment on lines -54 to +273
s.Command.PersistentFlags().StringVar(&s.LogFormat, "log-format", "", "Log format. Options are: text, json. Defaults to: text.")
s.Command.PersistentFlags().StringVar(&s.LogFormat, "log-format", "text", "Log format. Options are: text, json.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There was some reason we didn't want the default to be programmatically-encoded that I can't remember. Can you double-check this and make sure it's not changing behavior somehow?

@josh-berry

Copy link
Copy Markdown

Actually, one other thought: let's wait for @cretz to take a look before merging in case he spots something I didn't.

@cretz cretz left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks great and basically exactly how I would have done it. Only comment worth noting is the request to change the package/dir name, everything else is non-blocking. Don't forget to update CONTRIBUTING.md.

Comment thread temporalcli/commandsmd/parse.go Outdated
Comment on lines +157 to +158
Log level.
Default is "info" for most commands and "warn" for `server start-dev`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are we expected to retain the one-sentence-per-line approach? If so, how come done in options description but not command description? (do not need to fix, more for general discussion)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No, I want to get rid of this eventually and use a proper Markdown renderer for both the description and flags. The reason it was needed for flags is because newlines show up in the generated output, so having newlines inserted in (to-the-user) random places really doesn't look good. I think Andrew has since fixed this? In which case I have no opinion.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think we should have a general/consistent rule for Markdown description. Right now it seems a bit inconsistent.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Agree, eventually; we can make this consistent once we have a proper Markdown formatter IMO.

type: string
description: |
Log format.
Options are: text, json.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

There are more options than this, but I know this is a docs problem. No need to fix, can ignore. Henceforth in this PR I won't be commenting on things that are already a problem in main.

Comment thread temporalcli/commandsmd/commands.yml
Comment thread temporalcli/commandsmd/parse.go Outdated
Comment thread temporalcli/commandsmd/commands.yml
Comment thread temporalcli/commandsgen/parse.go Outdated
@@ -0,0 +1,192 @@
// Package commandsgen is built to read the markdown format described in
// temporalcli/commands.md and generate code from it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This statement is not accurate anymore

Comment thread Makefile Outdated
gen: temporalcli/commands.gen.go

temporalcli/commands.gen.go: temporalcli/commandsmd/commands.md
temporalcli/commands.gen.go: temporalcli/commandsgen/commands.md

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This still references commands.md. In a perfect world this would have failed CI with something like:

No rule to make target 'temporalcli/commandsgen/commands.md', needed by 'temporalcli/commands.gen.go'

But unfortunately this Makefile is an untested/undocumented thing just sitting in the repo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

oops, thanks for catching this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Switch to a common format for CLI command generation

3 participants