github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/runners/refresh/refresh.go (about) 1 package refresh 2 3 import ( 4 "github.com/ActiveState/cli/internal/analytics" 5 "github.com/ActiveState/cli/internal/config" 6 "github.com/ActiveState/cli/internal/errs" 7 "github.com/ActiveState/cli/internal/locale" 8 "github.com/ActiveState/cli/internal/logging" 9 "github.com/ActiveState/cli/internal/output" 10 "github.com/ActiveState/cli/internal/primer" 11 "github.com/ActiveState/cli/internal/prompt" 12 "github.com/ActiveState/cli/internal/runbits/findproject" 13 "github.com/ActiveState/cli/internal/runbits/rationalize" 14 "github.com/ActiveState/cli/internal/runbits/runtime" 15 "github.com/ActiveState/cli/pkg/platform/authentication" 16 "github.com/ActiveState/cli/pkg/platform/model" 17 "github.com/ActiveState/cli/pkg/platform/runtime/setup" 18 "github.com/ActiveState/cli/pkg/platform/runtime/target" 19 "github.com/ActiveState/cli/pkg/project" 20 "github.com/ActiveState/cli/pkg/projectfile" 21 ) 22 23 type Params struct { 24 Namespace *project.Namespaced 25 } 26 27 type primeable interface { 28 primer.Auther 29 primer.Prompter 30 primer.Outputer 31 primer.Configurer 32 primer.SvcModeler 33 primer.Analyticer 34 } 35 36 type Refresh struct { 37 auth *authentication.Auth 38 prompt prompt.Prompter 39 out output.Outputer 40 svcModel *model.SvcModel 41 config *config.Instance 42 analytics analytics.Dispatcher 43 } 44 45 func New(prime primeable) *Refresh { 46 return &Refresh{ 47 prime.Auth(), 48 prime.Prompt(), 49 prime.Output(), 50 prime.SvcModel(), 51 prime.Config(), 52 prime.Analytics(), 53 } 54 } 55 56 func (r *Refresh) Run(params *Params) error { 57 logging.Debug("Refresh %v", params.Namespace) 58 59 proj, err := findproject.FromInputByPriority("", params.Namespace, r.config, r.prompt) 60 if err != nil { 61 if errs.Matches(err, &projectfile.ErrorNoDefaultProject{}) { 62 return locale.WrapError(err, "err_use_default_project_does_not_exist") 63 } 64 return rationalize.ErrNoProject 65 } 66 67 rti, err := runtime.SolveAndUpdate(r.auth, r.out, r.analytics, proj, nil, target.TriggerRefresh, r.svcModel, r.config, runtime.OptMinimalUI) 68 if err != nil { 69 return locale.WrapError(err, "err_refresh_runtime_new", "Could not update runtime for this project.") 70 } 71 72 execDir := setup.ExecDir(rti.Target().Dir()) 73 r.out.Print(output.Prepare( 74 locale.Tr("refresh_project_statement", proj.NamespaceString(), proj.Dir(), execDir), 75 &struct { 76 Namespace string `json:"namespace"` 77 Path string `json:"path"` 78 Executables string `json:"executables"` 79 }{ 80 proj.NamespaceString(), 81 proj.Dir(), 82 execDir, 83 })) 84 85 return nil 86 }