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

Introduce a concept of subcommands in CLI #1618

Open
wata727 opened this issue Dec 8, 2022 · 2 comments
Open

Introduce a concept of subcommands in CLI #1618

wata727 opened this issue Dec 8, 2022 · 2 comments
Labels
needs-design Detailed design is required for implementation

Comments

@wata727
Copy link
Member

wata727 commented Dec 8, 2022

Introduction

Currently, TFLint has 4 modes of operation.

  • tflint --init
    • Installing plugins
  • tflint
    • Inspecting a Terraform configuration
  • tflint --langserver
    • Starting a language server
  • tflint --version
    • Printing version

In v0.44, we plan to introduce a --chdir option to move the working directory, similar to Terraform. See also #1612.
In Terraform, the --chdir has a special meaning to other flags. Below is a quote from the PR where --chdir was introduced:

The new option is only accepted at the start of the command line (before the subcommand) as a way to reflect that it is a global command (not specific to a particular subcommand) and that it takes effect before executing the subcommand. This also means it'll be forced to appear before any other command-specific arguments that take file paths, which hopefully communicates that those other arguments are interpreted relative to the overridden path.

hashicorp/terraform#26087

If we adopt a concept similar to this in TFLint, we cannot force the user to assume that the path will be relative to the changed directory, since TFLint has no concept of subcommands.

Proposal

Introduce a subcommand as below and allow --chdir only before the subcommand:

  • tflint --chdir=dir init
  • tflint --chdir=dir inspect
  • tflint --chdir=dir langserver
  • tflint --chdir=dir version

For my personal taste, it feels a bit redundant to always require a subcommand for inspection. To improve the user's first experience, I would like the inspection to work with just running tflint without subcommands.

In terms of compatibility with Terraform, https://github.com/mitchellh/cli would be a good option. Another popular one would be https://github.com/spf13/cobra. What to use should be decided after more detailed research.

References

@wata727 wata727 mentioned this issue Dec 8, 2022
5 tasks
@bendrucker
Copy link
Member

To implement the behavior where -chdir is handled differently than sub-command flags, Terraform manually processes (and strips) it before passing off the args to be parsed as flags:

https://github.com/hashicorp/terraform/blob/a9230c9e7582c353c224cf0f4832d472ce042c0d/main.go#L428

@bendrucker
Copy link
Member

Since there are no sub-commands now, users may just stick chdir on the end:

tflint --init --chdir foo

So it will be somewhat disruptive but probably the right move to require this:

tflint --chdir=foo init

Terraform also requires an equals in -chdir to disambiguate the value from a subcommand. Otherwise you can pass something like this:

tflint -chdir init

This should be rejected as invalid (because chdir requires an argument) rather than treated as tflint -chdir=init inspect.

@wata727 wata727 added the needs-design Detailed design is required for implementation label Dec 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-design Detailed design is required for implementation
Development

No branches or pull requests

2 participants