MCPcopy
hub / github.com/cortexlabs/cortex / BoolFromFile

Function BoolFromFile

pkg/lib/configreader/bool.go:124–150  ·  view source on GitHub ↗
(filePath string, v *BoolValidation)

Source from the content-addressed store, hash-verified

122}
123
124func BoolFromFile(filePath string, v *BoolValidation) (bool, error) {
125 if !files.IsFile(filePath) {
126 val, err := ValidateBoolMissing(v)
127 if err != nil {
128 return false, errors.Wrap(err, filePath)
129 }
130 return val, nil
131 }
132
133 valStr, err := files.ReadFile(filePath)
134 if err != nil {
135 return false, err
136 }
137 if len(valStr) == 0 {
138 val, err := ValidateBoolMissing(v)
139 if err != nil {
140 return false, errors.Wrap(err, filePath)
141 }
142 return val, nil
143 }
144
145 val, err := BoolFromStr(valStr, v)
146 if err != nil {
147 return false, errors.Wrap(err, filePath)
148 }
149 return val, nil
150}
151
152func BoolFromEnvOrFile(envVarName string, filePath string, v *BoolValidation) (bool, error) {
153 valStr := ReadEnvVar(envVarName)

Callers 2

BoolFromEnvOrFileFunction · 0.85
MustBoolFromFileFunction · 0.85

Calls 5

IsFileFunction · 0.92
WrapFunction · 0.92
ReadFileFunction · 0.92
ValidateBoolMissingFunction · 0.85
BoolFromStrFunction · 0.85

Tested by

no test coverage detected