( inputConfig bufconfig.InputConfig, )
| 203 | } |
| 204 | |
| 205 | func (a *refParser) getRawRefForInputConfig( |
| 206 | inputConfig bufconfig.InputConfig, |
| 207 | ) (*RawRef, error) { |
| 208 | rawRef := &RawRef{ |
| 209 | Path: inputConfig.Location(), |
| 210 | UnrecognizedOptions: make(map[string]string), |
| 211 | } |
| 212 | if a.rawRefProcessor != nil { |
| 213 | if err := a.rawRefProcessor(rawRef); err != nil { |
| 214 | return nil, err |
| 215 | } |
| 216 | } |
| 217 | switch inputConfig.Type() { |
| 218 | case bufconfig.InputConfigTypeModule: |
| 219 | rawRef.Format = "mod" |
| 220 | case bufconfig.InputConfigTypeDirectory: |
| 221 | rawRef.Format = "dir" |
| 222 | case bufconfig.InputConfigTypeGitRepo: |
| 223 | rawRef.Format = "git" |
| 224 | case bufconfig.InputConfigTypeProtoFile: |
| 225 | rawRef.Format = "protofile" |
| 226 | case bufconfig.InputConfigTypeTarball: |
| 227 | rawRef.Format = "tar" |
| 228 | case bufconfig.InputConfigTypeZipArchive: |
| 229 | rawRef.Format = "zip" |
| 230 | case bufconfig.InputConfigTypeBinaryImage: |
| 231 | rawRef.Format = "binpb" |
| 232 | case bufconfig.InputConfigTypeJSONImage: |
| 233 | rawRef.Format = "json" |
| 234 | case bufconfig.InputConfigTypeTextImage: |
| 235 | rawRef.Format = "txtpb" |
| 236 | case bufconfig.InputConfigTypeYAMLImage: |
| 237 | rawRef.Format = "yaml" |
| 238 | default: |
| 239 | return nil, syserror.Newf("unknown InputConfigType: %v", inputConfig.Type()) |
| 240 | } |
| 241 | // This cannot be set ahead of time, it can only happen after all options are read. |
| 242 | if inputConfig.Type() == bufconfig.InputConfigTypeGitRepo { |
| 243 | // TODO FUTURE: might change rawRef.Depth into a pointer or use some other way to handle the case where 0 is specified |
| 244 | if inputConfig.Depth() != nil { |
| 245 | if *inputConfig.Depth() == 0 { |
| 246 | return nil, NewDepthZeroError() |
| 247 | } |
| 248 | rawRef.GitDepth = *inputConfig.Depth() |
| 249 | } |
| 250 | rawRef.GitBranch = inputConfig.Branch() |
| 251 | rawRef.GitCommitOrTag = inputConfig.CommitOrTag() |
| 252 | rawRef.GitRef = inputConfig.Ref() |
| 253 | rawRef.GitRecurseSubmodules = inputConfig.RecurseSubmodules() |
| 254 | if rawRef.GitDepth == 0 { |
| 255 | // Default to 1 |
| 256 | rawRef.GitDepth = 1 |
| 257 | if rawRef.GitRef != "" { |
| 258 | // Default to 50 when using ref |
| 259 | rawRef.GitDepth = 50 |
| 260 | } |
| 261 | } |
| 262 | } |
no test coverage detected