()
| 84 | } |
| 85 | |
| 86 | func (o *actionsUseCodegenOptions) run() error { |
| 87 | var op errors.Op = "commands.actionsUseCodegenOptions.run" |
| 88 | o.EC.Spin("Ensuring codegen-assets repo is updated...") |
| 89 | defer o.EC.Spinner.Stop() |
| 90 | // ensure the the actions-codegen repo is updated |
| 91 | err := o.EC.CodegenAssetsRepo.EnsureUpdated() |
| 92 | if err != nil { |
| 93 | o.EC.Logger.Warnf("unable to update codegen-assets repo, got %v", err) |
| 94 | } |
| 95 | |
| 96 | newCodegenExecutionConfig := o.EC.Config.ActionConfig.Codegen |
| 97 | newCodegenExecutionConfig.Framework = "" |
| 98 | |
| 99 | o.EC.Spin("Fetching frameworks...") |
| 100 | allFrameworks, err := getCodegenFrameworks() |
| 101 | if err != nil { |
| 102 | return errors.E(op, fmt.Errorf("error in fetching codegen frameworks: %w", err)) |
| 103 | } |
| 104 | |
| 105 | o.EC.Spinner.Stop() |
| 106 | if o.framework == "" { |
| 107 | // if framework flag is not provided, display a list and allow them to choose |
| 108 | var frameworkList []string |
| 109 | for _, f := range allFrameworks { |
| 110 | frameworkList = append(frameworkList, f.Name) |
| 111 | } |
| 112 | sort.Strings(frameworkList) |
| 113 | newCodegenExecutionConfig.Framework, err = util.GetSelectPrompt("Choose a codegen framework to use", frameworkList) |
| 114 | if err != nil { |
| 115 | return errors.E(op, fmt.Errorf("error in selecting framework: %w", err)) |
| 116 | } |
| 117 | } else { |
| 118 | for _, f := range allFrameworks { |
| 119 | if o.framework == f.Name { |
| 120 | newCodegenExecutionConfig.Framework = o.framework |
| 121 | } |
| 122 | } |
| 123 | if newCodegenExecutionConfig.Framework == "" { |
| 124 | return errors.E(op, fmt.Errorf("framework %s is not found", o.framework)) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | hasStarterKit := false |
| 129 | for _, f := range allFrameworks { |
| 130 | if f.Name == newCodegenExecutionConfig.Framework && f.HasStarterKit { |
| 131 | hasStarterKit = true |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | // if with-starter-kit flag is set and the same is not available for the framework, return error |
| 136 | if o.withStarterKit && !hasStarterKit { |
| 137 | return errors.E(op, fmt.Errorf("starter kit is not available for framework %s", newCodegenExecutionConfig.Framework)) |
| 138 | } |
| 139 | |
| 140 | // if with-starter-kit flag is not provided, give an option to clone a starterkit |
| 141 | if !o.withStarterKit && hasStarterKit { |
| 142 | shouldCloneStarterKit, err := util.GetYesNoPrompt("Do you also want to clone a starter kit for " + newCodegenExecutionConfig.Framework + "?") |
| 143 | if err != nil { |
no test coverage detected