Skip to content

Introduce a concept of subcommands in CLI #1618

Open
@wata727

Description

@wata727

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-designDetailed design is required for implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions