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

Use YAML for CLI command generation #666

Merged
merged 17 commits into from
Sep 23, 2024

Conversation

yuandrew
Copy link
Contributor

@yuandrew yuandrew commented Sep 13, 2024

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?

@yuandrew
Copy link
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.

- name: raw
type: bool
description: Print properties without changing their format.
default: true
Copy link
Contributor Author

@yuandrew yuandrew Sep 18, 2024

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
temporalcli/commandsmd/commands.yml Outdated Show resolved Hide resolved
temporalcli/commandsmd/commands.yml Outdated Show resolved Hide resolved
temporalcli/commands.gen.go Outdated Show resolved Hide resolved
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
Collaborator

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
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

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

@josh-berry josh-berry left a comment

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
Collaborator

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
Collaborator

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

Copy link
Member

@cretz cretz left a comment

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.

temporalcli/commandsmd/parse.go Outdated Show resolved Hide resolved
Comment on lines 157 to 158
Log level.
Default is "info" for most commands and "warn" for `server start-dev`.
Copy link
Member

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
Collaborator

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
Member

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
Collaborator

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
Member

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.

temporalcli/commandsmd/commands.yml Outdated Show resolved Hide resolved
temporalcli/commandsmd/parse.go Outdated Show resolved Hide resolved
temporalcli/commandsmd/commands.yml Outdated Show resolved Hide resolved
@@ -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
Member

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

Makefile Outdated
@@ -4,7 +4,7 @@ all: gen build

gen: temporalcli/commands.gen.go

temporalcli/commands.gen.go: temporalcli/commandsmd/commands.md
temporalcli/commands.gen.go: temporalcli/commandsgen/commands.md
Copy link
Member

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
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!

@yuandrew yuandrew merged commit e66af94 into temporalio:main Sep 23, 2024
7 checks passed
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