github.com/opentofu/opentofu@v1.7.1/internal/command/command.go (about) 1 // Copyright (c) The OpenTofu Authors 2 // SPDX-License-Identifier: MPL-2.0 3 // Copyright (c) 2023 HashiCorp, Inc. 4 // SPDX-License-Identifier: MPL-2.0 5 6 package command 7 8 import ( 9 "fmt" 10 "os" 11 "runtime" 12 ) 13 14 // Set to true when we're testing 15 var test bool = false 16 17 // DefaultDataDir is the default directory for storing local data. 18 const DefaultDataDir = ".terraform" 19 20 // PluginPathFile is the name of the file in the data dir which stores the list 21 // of directories supplied by the user with the `-plugin-dir` flag during init. 22 const PluginPathFile = "plugin_path" 23 24 // pluginMachineName is the directory name used in new plugin paths. 25 const pluginMachineName = runtime.GOOS + "_" + runtime.GOARCH 26 27 // DefaultPluginVendorDir is the location in the config directory to look for 28 // user-added plugin binaries. OpenTofu only reads from this path if it 29 // exists, it is never created by tofu. 30 const DefaultPluginVendorDir = "terraform.d/plugins/" + pluginMachineName 31 32 // DefaultStateFilename is the default filename used for the state file. 33 const DefaultStateFilename = "terraform.tfstate" 34 35 // DefaultVarsFilename is the default filename used for vars 36 const DefaultVarsFilename = "terraform.tfvars" 37 38 // DefaultBackupExtension is added to the state file to form the path 39 const DefaultBackupExtension = ".backup" 40 41 // DefaultParallelism is the limit Terraform places on total parallel 42 // operations as it walks the dependency graph. 43 const DefaultParallelism = 10 44 45 // ErrUnsupportedLocalOp is the common error message shown for operations 46 // that require a backend.Local. 47 const ErrUnsupportedLocalOp = `The configured backend doesn't support this operation. 48 49 The "backend" in OpenTofu defines how OpenTofu operates. The default 50 backend performs all operations locally on your machine. Your configuration 51 is configured to use a non-local backend. This backend doesn't support this 52 operation. 53 ` 54 55 // modulePath returns the path to the root module and validates CLI arguments. 56 // 57 // This centralizes the logic for any commands that previously accepted 58 // a module path via CLI arguments. This will error if any extraneous arguments 59 // are given and suggest using the -chdir flag instead. 60 // 61 // If your command accepts more than one arg, then change the slice bounds 62 // to pass validation. 63 func modulePath(args []string) (string, error) { 64 // TODO: test 65 66 if len(args) > 0 { 67 return "", fmt.Errorf("Too many command line arguments. Did you mean to use -chdir?") 68 } 69 70 path, err := os.Getwd() 71 if err != nil { 72 return "", fmt.Errorf("Error getting pwd: %w", err) 73 } 74 75 return path, nil 76 }