mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Terraform supports multiple output formats for several sub-commands. The default format is user-readable text, but many sub-commands support a `-json` flag to output a machine-readable format for the result. The output command also supports a `-raw` flag for a simpler, scripting- focused machine readable format. This commit adds a "views" abstraction, intended to help ensure consistency between the various output formats. This extracts the render specific code from the command package, and moves it into a views package. Each command is expected to create an interface for its view, and one or more implementations of that interface. By doing so, we separate the concerns of generating the sub-command result from rendering the result in the specified output format. This should make it easier to ensure that all output formats will be updated together when changes occur in the result-generating phase. There are some other consequences of this restructuring: - Views now directly access the terminal streams, rather than the now-redundant cli.Ui instance; - With the reorganization of commands, parsing CLI arguments is now the responsibility of a separate "arguments" package. For now, views are added only for the output sub-command, as an example. Because this command uses code which is shared with the apply and refresh commands, those are also partially updated.
17 lines
325 B
Go
17 lines
325 B
Go
package arguments
|
|
|
|
import (
|
|
"flag"
|
|
"io/ioutil"
|
|
)
|
|
|
|
// defaultFlagSet creates a FlagSet with the common settings to override
|
|
// the flag package's noisy defaults.
|
|
func defaultFlagSet(name string) *flag.FlagSet {
|
|
f := flag.NewFlagSet(name, flag.ContinueOnError)
|
|
f.SetOutput(ioutil.Discard)
|
|
f.Usage = func() {}
|
|
|
|
return f
|
|
}
|