Skip to content

feat(detect): add --no-fallback option#539

Open
railgun-0402 wants to merge 2 commits intotofuutils:mainfrom
railgun-0402:feat/no-fallback-detect
Open

feat(detect): add --no-fallback option#539
railgun-0402 wants to merge 2 commits intotofuutils:mainfrom
railgun-0402:feat/no-fallback-detect

Conversation

@railgun-0402
Copy link

Summary

  • Add --no-fallback flag to tenv tofu detect and tenv tf detect commands
  • When set, return exit code 1 if no version files are found instead of falling back to default strategy

Motivation

Closes #502

Users need to distinguish whether a folder is configured for OpenTofu or Terraform. Currently, tenv tofu detect and tenv tf detect return exit code 0 even when no version files are found, because
a fallback mechanism triggers to select a default version.

Changes

  • versionmanager/manager.go: Add ErrNoVersionFilesFound error and ResolveStrict() method
  • cmd/tenv/subcmd.go: Add --no-fallback flag to detect command
  • versionmanager/proxy/proxy.go: Update Detect() call signature
  • versionmanager/tenvlib/lib.go: Update Detect() call signature

Test plan

# In a directory without version files                                                                                                                                                                  
cd /tmp/test-dir                                                                                                                                                                                        
tenv tofu detect --no-fallback                                                                                                                                                                          
echo $?  # Returns 1                                                                                                                                                                                    
                                                                                                                                                                                                        
# With version file                                                                                                                                                                                     
echo "1.6.0" > .opentofu-version                                                                                                                                                                        
tenv tofu detect --no-fallback                                                                                                                                                                          
echo $?  # Returns 0                      

Signed-off-by: railgun-0402 <april-life.f-441-2011@docomo.ne.jp>
@kvendingoldo
Copy link
Collaborator

Hi! Thank you for PR!
Me or @dvaumoron will check it soon

Signed-off-by: railgun-0402 <april-life.f-441-2011@docomo.ne.jp>
@railgun-0402 railgun-0402 force-pushed the feat/no-fallback-detect branch from 3b42a84 to 88228d6 Compare February 3, 2026 08:41
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.

Allow disabling fallback for detect commands

2 participants