4848 errEmptyVersion = errors .New ("empty version" )
4949 errNoCompatible = errors .New ("no compatible version found" )
5050 ErrNoCompatibleLocally = errors .New ("no compatible version found locally" )
51+ ErrNoVersionFilesFound = errors .New ("no version files found" )
5152)
5253
5354type ReleaseRetriever interface {
@@ -74,8 +75,15 @@ func Make(conf *config.Config, envPrefix string, folderName string, iacExts []ia
7475}
7576
7677// Detect version (resolve and evaluate, can install depending on auto install env var).
77- func (m VersionManager ) Detect (ctx context.Context , proxyCall bool ) (string , error ) {
78- configVersion , err := m .Resolve (semantic .LatestAllowedKey )
78+ // When noFallback is true, returns ErrNoVersionFilesFound if no version files are found instead of using fallback strategy.
79+ func (m VersionManager ) Detect (ctx context.Context , proxyCall bool , noFallback bool ) (string , error ) {
80+ var configVersion string
81+ var err error
82+ if noFallback {
83+ configVersion , err = m .ResolveStrict ()
84+ } else {
85+ configVersion , err = m .Resolve (semantic .LatestAllowedKey )
86+ }
7987 if err != nil {
8088 m .Conf .Displayer .Flush (proxyCall )
8189
@@ -292,6 +300,35 @@ func (m VersionManager) Resolve(defaultStrategy string) (string, error) {
292300 return defaultStrategy , nil
293301}
294302
303+ // ResolveStrict Search the requested version in version files (with fallbacks and env var overloading, but no default strategy fallback).
304+ // Returns ErrNoVersionFilesFound if no version is found.
305+ func (m VersionManager ) ResolveStrict () (string , error ) {
306+ versionEnvName := m .EnvNames .Version ()
307+ version := m .Conf .Getenv (versionEnvName )
308+ if version != "" {
309+ return types .DisplayDetectionInfo (m .Conf .Displayer , version , versionEnvName ), nil
310+ }
311+
312+ version , err := m .ResolveWithVersionFiles ()
313+ if err != nil {
314+ return "" , err
315+ }
316+ if version != "" {
317+ return version , nil
318+ }
319+
320+ defaultVersionEnvName := m .EnvNames .defaultVersion ()
321+ if version = m .Conf .Getenv (defaultVersionEnvName ); version != "" {
322+ return types .DisplayDetectionInfo (m .Conf .Displayer , version , defaultVersionEnvName ), nil
323+ }
324+
325+ if version , err = flatparser .RetrieveVersion (m .RootVersionFilePath (), m .Conf ); err != nil || version != "" {
326+ return version , err
327+ }
328+
329+ return "" , ErrNoVersionFilesFound
330+ }
331+
295332// Search the requested version in version files.
296333func (m VersionManager ) ResolveWithVersionFiles () (string , error ) {
297334 return semantic .RetrieveVersion (m .VersionFiles , m .Conf )
0 commit comments