()
| 36 | } |
| 37 | |
| 38 | func (f Source) Configure() (string, error) { |
| 39 | f.ui.PrintHeaderText("Content") |
| 40 | f.ui.PrintInformationalText("Please provide the location from where your Kubernetes manifests or Helm chart can be fetched. This will be bundled as a part of the package.") |
| 41 | |
| 42 | vendirConfig := NewVendirConfig(vendirFileName) |
| 43 | err := vendirConfig.Load() |
| 44 | if err != nil { |
| 45 | return "", err |
| 46 | } |
| 47 | |
| 48 | previousFetchOptionSelected := vendirConfig.FetchMode(f.build.HasHelmTemplate()) |
| 49 | if previousFetchOptionSelected == MultipleFetchOptionsSelected { |
| 50 | f.ui.PrintInformationalText("vendir.yml has multiple sources defined. Running vendir sync without overwriting vendir.yml") |
| 51 | return "", nil |
| 52 | } |
| 53 | |
| 54 | options := []string{LocalDirectory, GithubRelease, HelmRepo, Git, ChartFromGit} |
| 55 | choiceOpts := ui.ChoiceOpts{ |
| 56 | Label: "Enter source", |
| 57 | Default: f.getPreviousFetchOptionIndex(options, previousFetchOptionSelected), |
| 58 | Choices: options, |
| 59 | } |
| 60 | currentFetchOptionIndex, err := f.ui.AskForChoice(choiceOpts) |
| 61 | if err != nil { |
| 62 | return "", err |
| 63 | } |
| 64 | currentFetchOptionSelected := options[currentFetchOptionIndex] |
| 65 | |
| 66 | if previousFetchOptionSelected != "" && currentFetchOptionSelected != previousFetchOptionSelected { |
| 67 | return "", fmt.Errorf("Transitioning from one fetch option to another is not allowed. Earlier option selected: %s, Current Option selected: %s", previousFetchOptionSelected, currentFetchOptionSelected) |
| 68 | } |
| 69 | |
| 70 | // For the local directory options, all files/directories in working directory are used while releasing |
| 71 | if currentFetchOptionSelected == LocalDirectory { |
| 72 | return currentFetchOptionSelected, nil |
| 73 | } |
| 74 | |
| 75 | vendirDirectories := vendirConfig.Directories() |
| 76 | switch { |
| 77 | case len(vendirDirectories) > 1: |
| 78 | return currentFetchOptionSelected, fmt.Errorf("More than 1 directory config found in the vendir file. (hint: Run vendir sync manually)") |
| 79 | case len(vendirDirectories) == 0: |
| 80 | err := vendirConfig.InitiatliseDirectories() |
| 81 | if err != nil { |
| 82 | return currentFetchOptionSelected, err |
| 83 | } |
| 84 | default: |
| 85 | directory := vendirDirectories[0] |
| 86 | if len(directory.Contents) > 1 { |
| 87 | return currentFetchOptionSelected, fmt.Errorf("More than 1 content config found in the vendir file. (hint: Run vendir sync manually)") |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | switch currentFetchOptionSelected { |
| 92 | case GithubRelease: |
| 93 | return currentFetchOptionSelected, NewGithubReleaseSource(f.ui, vendirConfig).Configure() |
| 94 | case HelmRepo: |
| 95 | return currentFetchOptionSelected, NewHelmSource(f.ui, vendirConfig).Configure() |
nothing calls this directly
no test coverage detected