From c05892c1659dd6529582f01d579c9d4b85aff4f6 Mon Sep 17 00:00:00 2001 From: mitchell Date: Thu, 19 Oct 2023 15:31:16 -0400 Subject: [PATCH] Pass around prime prompt and output instead of using globals. Also renamed the package from the previous commit. --- cmd/state/main.go | 7 +++---- internal/constraints/constraints.go | 10 ++++++---- internal/events/cmdcall/cmdcall.go | 3 ++- internal/globaldefault/default.go | 6 ++++-- .../commitmediator.go} | 8 +++++--- .../projectmigration/projectmigration.go | 15 ++------------- internal/runbits/refresh.go | 4 +++- internal/runbits/requirements/requirements.go | 2 +- internal/runbits/runtime/runtime.go | 6 ++++-- internal/runners/activate/activate.go | 8 ++++---- internal/runners/checkout/checkout.go | 6 +++++- internal/runners/commit/commit.go | 6 +++++- internal/runners/cve/cve.go | 15 +++++++++------ internal/runners/cve/report.go | 14 ++++++++------ internal/runners/exec/exec.go | 8 ++++++-- internal/runners/export/env.go | 5 ++++- internal/runners/export/export.go | 1 + internal/runners/export/recipe.go | 16 +++++++++------- internal/runners/hello/hello_example.go | 12 ++++++++---- internal/runners/history/history.go | 8 ++++++-- internal/runners/initialize/init.go | 17 ++++++++++------- internal/runners/languages/languages.go | 7 +++++-- internal/runners/packages/import.go | 2 +- internal/runners/packages/info.go | 13 ++++++++----- internal/runners/packages/list.go | 11 +++++++---- internal/runners/packages/search.go | 19 +++++++++++-------- internal/runners/platforms/list.go | 15 +++++++++------ internal/runners/prepare/prepare.go | 10 +++++++--- internal/runners/projects/projects.go | 13 ++++++++----- internal/runners/pull/pull.go | 2 +- internal/runners/refresh/refresh.go | 2 +- internal/runners/reset/reset.go | 2 +- internal/runners/revert/revert.go | 2 +- internal/runners/run/run.go | 8 ++++++-- internal/runners/shell/shell.go | 6 +++--- internal/runners/show/show.go | 16 ++++++++++------ internal/runners/swtch/switch.go | 6 +++++- internal/runners/use/show.go | 9 ++++++--- internal/runners/use/use.go | 8 ++++---- internal/scriptrun/scriptrun.go | 7 +++++-- .../test/integration/scriptrun_test.go | 14 +++++++------- pkg/cmdlets/checker/checker.go | 11 ++++++----- pkg/platform/runtime/target/target.go | 16 ++++++++++------ pkg/project/expander.go | 4 ++-- pkg/project/namespace.go | 4 ++-- pkg/project/project.go | 17 ++++++++++++++--- pkg/project/project_test.go | 2 +- pkg/projectfile/projectfile.go | 2 +- scripts/ci/parallelize/parallelize.go | 11 +++++------ 49 files changed, 252 insertions(+), 164 deletions(-) rename internal/runbits/{commitid/commitid.go => commitmediator/commitmediator.go} (74%) diff --git a/cmd/state/main.go b/cmd/state/main.go index 7fdf0ef3a2..5402184d0a 100644 --- a/cmd/state/main.go +++ b/cmd/state/main.go @@ -33,7 +33,6 @@ import ( _ "github.com/ActiveState/cli/internal/prompt" // Sets up survey defaults "github.com/ActiveState/cli/internal/rollbar" "github.com/ActiveState/cli/internal/runbits/panics" - "github.com/ActiveState/cli/internal/runbits/projectmigration" "github.com/ActiveState/cli/internal/subshell" "github.com/ActiveState/cli/internal/svcctl" cmdletErrors "github.com/ActiveState/cli/pkg/cmdlets/errors" @@ -212,13 +211,13 @@ func run(args []string, isInteractive bool, cfg *config.Instance, out output.Out // Set up prompter prompter := prompt.New(isInteractive, an) - projectmigration.Register(prompter, out) - // Set up conditional, which accesses a lot of primer data sshell := subshell.New(cfg) - conditional := constraints.NewPrimeConditional(auth, pj, sshell.Shell()) + conditional := constraints.NewPrimeConditional(auth, pj, sshell.Shell(), prompter, out) project.RegisterConditional(conditional) + project.RegisterPrompt(prompter) + project.RegisterOutput(out) project.RegisterExpander("mixin", project.NewMixin(auth).Expander) project.RegisterExpander("secrets", project.NewSecretPromptingExpander(secretsapi.Get(), prompter, cfg, auth)) diff --git a/internal/constraints/constraints.go b/internal/constraints/constraints.go index 6e5886a7dd..b20861d85f 100644 --- a/internal/constraints/constraints.go +++ b/internal/constraints/constraints.go @@ -12,8 +12,10 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/multilog" + "github.com/ActiveState/cli/internal/output" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/rtutils/ptr" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/projectfile" "github.com/ActiveState/cli/pkg/sysinfo" @@ -81,10 +83,10 @@ type projectable interface { Path() string Dir() string URL() string - LegacyCommitID() string // for commitid.GetCompatible + LegacyCommitID() string // for commitmediator.Get } -func NewPrimeConditional(auth *authentication.Auth, pj projectable, subshellName string) *Conditional { +func NewPrimeConditional(auth *authentication.Auth, pj projectable, subshellName string, prompter prompt.Prompter, out output.Outputer) *Conditional { var ( pjOwner string pjName string @@ -99,7 +101,7 @@ func NewPrimeConditional(auth *authentication.Auth, pj projectable, subshellName pjName = pj.Name() pjNamespace = pj.NamespaceString() pjURL = pj.URL() - commitID, err := commitid.GetCompatible(pj) + commitID, err := commitmediator.Get(pj, prompter, out) if err != nil { multilog.Error("Unable to get local commit: %v", errs.JoinMessage(err)) } diff --git a/internal/events/cmdcall/cmdcall.go b/internal/events/cmdcall/cmdcall.go index 1c27f7f04c..709f5177b4 100644 --- a/internal/events/cmdcall/cmdcall.go +++ b/internal/events/cmdcall/cmdcall.go @@ -20,6 +20,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.Prompter } // CmdCall manages dependencies for the handling of events triggered by command @@ -41,7 +42,7 @@ func New(p primeable, cmdList string) *CmdCall { subshell: p.Subshell(), cmdList: cmdList, p: p, - scriptrun: scriptrun.New(p.Auth(), p.Output(), p.Subshell(), p.Project(), p.Config(), p.Analytics(), p.SvcModel()), + scriptrun: scriptrun.New(p.Auth(), p.Output(), p.Subshell(), p.Project(), p.Config(), p.Analytics(), p.SvcModel(), p.Prompt()), } } diff --git a/internal/globaldefault/default.go b/internal/globaldefault/default.go index 5e412dfc01..65094aa636 100644 --- a/internal/globaldefault/default.go +++ b/internal/globaldefault/default.go @@ -10,6 +10,8 @@ import ( "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/multilog" "github.com/ActiveState/cli/internal/osutils" + "github.com/ActiveState/cli/internal/output" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/subshell" "github.com/ActiveState/cli/internal/subshell/sscommon" "github.com/ActiveState/cli/internal/svcctl" @@ -63,7 +65,7 @@ func Prepare(cfg DefaultConfigurer, shell subshell.SubShell) error { } // SetupDefaultActivation sets symlinks in the global bin directory to the currently activated runtime -func SetupDefaultActivation(subshell subshell.SubShell, cfg DefaultConfigurer, runtime *runtime.Runtime, proj *project.Project) error { +func SetupDefaultActivation(subshell subshell.SubShell, cfg DefaultConfigurer, runtime *runtime.Runtime, proj *project.Project, prompter prompt.Prompter, out output.Outputer) error { logging.Debug("Setting up globaldefault") if err := Prepare(cfg, subshell); err != nil { return locale.WrapError(err, "err_globaldefault_prepare", "Could not prepare environment.") @@ -79,7 +81,7 @@ func SetupDefaultActivation(subshell subshell.SubShell, cfg DefaultConfigurer, r return locale.WrapError(err, "err_globaldefault_rtenv", "Could not construct runtime environment variables") } - target := target.NewProjectTargetCache(proj, storage.GlobalBinDir(), nil, target.TriggerActivate) + target := target.NewProjectTargetCache(proj, storage.GlobalBinDir(), nil, target.TriggerActivate, prompter, out) execInit := executors.New(BinDir()) if err := execInit.Apply(svcctl.NewIPCSockPathFromGlobals().String(), target, env, exes); err != nil { return locale.WrapError(err, "err_globaldefault_fw", "Could not set up forwarders") diff --git a/internal/runbits/commitid/commitid.go b/internal/runbits/commitmediator/commitmediator.go similarity index 74% rename from internal/runbits/commitid/commitid.go rename to internal/runbits/commitmediator/commitmediator.go index e65fa04384..01f9757e0e 100644 --- a/internal/runbits/commitid/commitid.go +++ b/internal/runbits/commitmediator/commitmediator.go @@ -1,7 +1,9 @@ -package commitid +package commitmediator import ( "github.com/ActiveState/cli/internal/errs" + "github.com/ActiveState/cli/internal/output" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits/projectmigration" "github.com/ActiveState/cli/pkg/localcommit" "github.com/go-openapi/strfmt" @@ -17,11 +19,11 @@ type projecter interface { // GetCompatible returns the given project's commit ID in either the new format (commit file), or // the old format (activestate.yaml). // If you require the commit file, use localcommit.Get(). -func GetCompatible(proj projecter) (strfmt.UUID, error) { +func Get(proj projecter, prompter prompt.Prompter, out output.Outputer) (strfmt.UUID, error) { if commitID, err := localcommit.Get(proj.Dir()); err == nil { return commitID, nil } else if localcommit.IsFileDoesNotExistError(err) { - if migrated, err := projectmigration.PromptAndMigrate(proj); err == nil && migrated { + if migrated, err := projectmigration.PromptAndMigrate(proj, prompter, out); err == nil && migrated { return localcommit.Get(proj.Dir()) } else if err != nil { return "", errs.Wrap(err, "Could not prompt and/or migrate project") diff --git a/internal/runbits/projectmigration/projectmigration.go b/internal/runbits/projectmigration/projectmigration.go index ca82c5d478..95f9b41c5e 100644 --- a/internal/runbits/projectmigration/projectmigration.go +++ b/internal/runbits/projectmigration/projectmigration.go @@ -23,22 +23,11 @@ type promptable interface { Confirm(title, message string, defaultChoice *bool) (bool, error) } -var prompt promptable -var out output.Outputer var declined bool -func Register(prompt_ promptable, out_ output.Outputer) { - prompt = prompt_ - out = out_ -} - -func PromptAndMigrate(proj projecter) (bool, error) { - if prompt == nil || out == nil { - return false, errs.New("projectmigration.Register() has not been called") - } - +func PromptAndMigrate(proj projecter, prompt promptable, out output.Outputer) (bool, error) { if declined { - return false, nil + return false, nil // already declined; do not prompt again } defaultChoice := false diff --git a/internal/runbits/refresh.go b/internal/runbits/refresh.go index b7d569b4a4..3938b30b76 100644 --- a/internal/runbits/refresh.go +++ b/internal/runbits/refresh.go @@ -4,6 +4,7 @@ import ( "github.com/ActiveState/cli/internal/analytics" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/rtutils" "github.com/ActiveState/cli/internal/runbits/buildscript" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -24,12 +25,13 @@ func RefreshRuntime( changed bool, trigger target.Trigger, svcm *model.SvcModel, + prompter prompt.Prompter, ) (rerr error) { _, err := buildscript.Sync(proj, &commitID, out, auth) if err != nil { return locale.WrapError(err, "err_update_build_script") } - target := target.NewProjectTarget(proj, nil, trigger) + target := target.NewProjectTarget(proj, nil, trigger, prompter, out) isCached := true rt, err := runtime.New(target, an, svcm, auth) if err != nil { diff --git a/internal/runbits/requirements/requirements.go b/internal/runbits/requirements/requirements.go index f89281cd54..83f353cc0b 100644 --- a/internal/runbits/requirements/requirements.go +++ b/internal/runbits/requirements/requirements.go @@ -299,7 +299,7 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ } // refresh or install runtime - err = runbits.RefreshRuntime(r.Auth, r.Output, r.Analytics, pj, commitID, true, trigger, r.SvcModel) + err = runbits.RefreshRuntime(r.Auth, r.Output, r.Analytics, pj, commitID, true, trigger, r.SvcModel, r.Prompt) if err != nil { return err } diff --git a/internal/runbits/runtime/runtime.go b/internal/runbits/runtime/runtime.go index 35c712d43e..0daf02fb86 100644 --- a/internal/runbits/runtime/runtime.go +++ b/internal/runbits/runtime/runtime.go @@ -4,6 +4,7 @@ import ( "github.com/ActiveState/cli/internal/analytics" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/rtutils" "github.com/ActiveState/cli/internal/runbits" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -25,10 +26,11 @@ func NewFromProject( an analytics.Dispatcher, svcModel *model.SvcModel, out output.Outputer, - auth *authentication.Auth) (_ *rt.Runtime, rerr error) { + auth *authentication.Auth, + prompter prompt.Prompter) (_ *rt.Runtime, rerr error) { defer rationalizeError(auth, proj, &rerr) - rti, err := rt.New(target.NewProjectTarget(proj, nil, trigger), an, svcModel, auth) + rti, err := rt.New(target.NewProjectTarget(proj, nil, trigger, prompter, out), an, svcModel, auth) if err == nil { return rti, nil } diff --git a/internal/runners/activate/activate.go b/internal/runners/activate/activate.go index 357595dd09..ac48bd8939 100644 --- a/internal/runners/activate/activate.go +++ b/internal/runners/activate/activate.go @@ -22,7 +22,7 @@ import ( "github.com/ActiveState/cli/internal/process" "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits/activation" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/runbits/findproject" "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/internal/subshell" @@ -175,7 +175,7 @@ func (r *Activate) Run(params *ActivateParams) (rerr error) { } } - rt, err := runtime.NewFromProject(proj, target.TriggerActivate, r.analytics, r.svcModel, r.out, r.auth) + rt, err := runtime.NewFromProject(proj, target.TriggerActivate, r.analytics, r.svcModel, r.out, r.auth, r.prompt) if err != nil { return locale.WrapError(err, "err_could_not_activate_venv", "Could not activate project") } @@ -183,7 +183,7 @@ func (r *Activate) Run(params *ActivateParams) (rerr error) { venv := virtualenvironment.New(rt) if setDefault { - err := globaldefault.SetupDefaultActivation(r.subshell, r.config, rt, proj) + err := globaldefault.SetupDefaultActivation(r.subshell, r.config, rt, proj, r.prompt, r.out) if err != nil { return locale.WrapError(err, "err_activate_default", "Could not make your project always available for use.") } @@ -195,7 +195,7 @@ func (r *Activate) Run(params *ActivateParams) (rerr error) { } } - commitID, err := commitid.GetCompatible(proj) + commitID, err := commitmediator.Get(proj, r.prompt, r.out) if err != nil { return errs.Wrap(err, "Unable to get local commit") } diff --git a/internal/runners/checkout/checkout.go b/internal/runners/checkout/checkout.go index 2f5b18fec8..7705ec927a 100644 --- a/internal/runners/checkout/checkout.go +++ b/internal/runners/checkout/checkout.go @@ -8,6 +8,7 @@ import ( "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/internal/subshell" "github.com/ActiveState/cli/pkg/cmdlets/checker" @@ -36,6 +37,7 @@ type primeable interface { primer.Configurer primer.SvcModeler primer.Analyticer + primer.Prompter } type Checkout struct { @@ -46,6 +48,7 @@ type Checkout struct { config *config.Instance subshell subshell.SubShell analytics analytics.Dispatcher + prompt prompt.Prompter } func NewCheckout(prime primeable) *Checkout { @@ -57,6 +60,7 @@ func NewCheckout(prime primeable) *Checkout { prime.Config(), prime.Subshell(), prime.Analytics(), + prime.Prompt(), } } @@ -77,7 +81,7 @@ func (u *Checkout) Run(params *Params) (rerr error) { return locale.WrapError(err, "err_project_frompath") } - rti, err := runtime.NewFromProject(proj, target.TriggerCheckout, u.analytics, u.svcModel, u.out, u.auth) + rti, err := runtime.NewFromProject(proj, target.TriggerCheckout, u.analytics, u.svcModel, u.out, u.auth, u.prompt) if err != nil { return locale.WrapError(err, "err_checkout_runtime_new", "Could not checkout this project.") } diff --git a/internal/runners/commit/commit.go b/internal/runners/commit/commit.go index 092adb3236..9e606a015c 100644 --- a/internal/runners/commit/commit.go +++ b/internal/runners/commit/commit.go @@ -5,6 +5,7 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits/buildscript" "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -20,6 +21,7 @@ type primeable interface { primer.Auther primer.Analyticer primer.SvcModeler + primer.Prompter } type Commit struct { @@ -28,6 +30,7 @@ type Commit struct { auth *authentication.Auth analytics analytics.Dispatcher svcModel *model.SvcModel + prompt prompt.Prompter } func New(p primeable) *Commit { @@ -37,6 +40,7 @@ func New(p primeable) *Commit { auth: p.Auth(), analytics: p.Analytics(), svcModel: p.SvcModel(), + prompt: p.Prompt(), } } @@ -54,7 +58,7 @@ func (c *Commit) Run() error { } trigger := target.TriggerCommit - rti, err := runtime.NewFromProject(c.proj, trigger, c.analytics, c.svcModel, c.out, c.auth) + rti, err := runtime.NewFromProject(c.proj, trigger, c.analytics, c.svcModel, c.out, c.auth, c.prompt) if err != nil { return locale.WrapInputError( err, "err_commit_runtime_new", diff --git a/internal/runners/cve/cve.go b/internal/runners/cve/cve.go index b01c469649..a75489ac95 100644 --- a/internal/runners/cve/cve.go +++ b/internal/runners/cve/cve.go @@ -7,7 +7,8 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" medmodel "github.com/ActiveState/cli/pkg/platform/api/mediator/model" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -15,9 +16,10 @@ import ( ) type Cve struct { - proj *project.Project - auth *authentication.Auth - out output.Outputer + proj *project.Project + auth *authentication.Auth + out output.Outputer + prompt prompt.Prompter } type outputData struct { @@ -47,10 +49,11 @@ type primeable interface { primer.Projecter primer.Auther primer.Outputer + primer.Prompter } func NewCve(prime *primer.Values) *Cve { - return &Cve{prime.Project(), prime.Auth(), prime.Output()} + return &Cve{prime.Project(), prime.Auth(), prime.Output(), prime.Prompt()} } func (c *Cve) Run() error { @@ -66,7 +69,7 @@ func (c *Cve) Run() error { ) } - commitID, err := commitid.GetCompatible(c.proj) + commitID, err := commitmediator.Get(c.proj, c.prompt, c.out) if err != nil { return errs.Wrap(err, "Could not get local commit") } diff --git a/internal/runners/cve/report.go b/internal/runners/cve/report.go index d6923eba97..424af7bae5 100644 --- a/internal/runners/cve/report.go +++ b/internal/runners/cve/report.go @@ -9,7 +9,8 @@ import ( "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" medmodel "github.com/ActiveState/cli/pkg/platform/api/mediator/model" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -17,9 +18,10 @@ import ( ) type Report struct { - proj *project.Project - auth *authentication.Auth - out output.Outputer + proj *project.Project + auth *authentication.Auth + out output.Outputer + prompt prompt.Prompter } type ReportInfo struct { @@ -29,7 +31,7 @@ type ReportInfo struct { } func NewReport(prime primeable) *Report { - return &Report{prime.Project(), prime.Auth(), prime.Output()} + return &Report{prime.Project(), prime.Auth(), prime.Output(), prime.Prompt()} } type ReportParams struct { @@ -102,7 +104,7 @@ func (r *Report) fetchVulnerabilities(namespaceOverride project.Namespaced) (*me commitID = namespaceOverride.CommitID.String() } else { var err error - commitUUID, err := commitid.GetCompatible(r.proj) + commitUUID, err := commitmediator.Get(r.proj, r.prompt, r.out) if err != nil { return nil, errs.Wrap(err, "Unable to get local commit") } diff --git a/internal/runners/exec/exec.go b/internal/runners/exec/exec.go index bb0b174ead..000eac33e9 100644 --- a/internal/runners/exec/exec.go +++ b/internal/runners/exec/exec.go @@ -21,6 +21,7 @@ import ( "github.com/ActiveState/cli/internal/multilog" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/rtutils" "github.com/ActiveState/cli/internal/runbits" "github.com/ActiveState/cli/internal/scriptfile" @@ -44,6 +45,7 @@ type Exec struct { cfg projectfile.ConfigGetter analytics analytics.Dispatcher svcModel *model.SvcModel + prompt prompt.Prompter } type primeable interface { @@ -54,6 +56,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.Prompter } type Params struct { @@ -69,6 +72,7 @@ func New(prime primeable) *Exec { prime.Config(), prime.Analytics(), prime.SvcModel(), + prime.Prompt(), } } @@ -100,7 +104,7 @@ func (s *Exec) Run(params *Params, args ...string) (rerr error) { // as there is no head rtTarget = target.NewCustomTarget("", "", "", params.Path, trigger, true) } else { - rtTarget = target.NewProjectTarget(proj, nil, trigger) + rtTarget = target.NewProjectTarget(proj, nil, trigger, s.prompt, s.out) } projectNamespace = proj.NamespaceString() } else { @@ -117,7 +121,7 @@ func (s *Exec) Run(params *Params, args ...string) (rerr error) { } projectDir = filepath.Dir(proj.Source().Path()) projectNamespace = proj.NamespaceString() - rtTarget = target.NewProjectTarget(proj, nil, trigger) + rtTarget = target.NewProjectTarget(proj, nil, trigger, s.prompt, s.out) } s.out.Notice(locale.Tl("operating_message", "", projectNamespace, projectDir)) diff --git a/internal/runners/export/env.go b/internal/runners/export/env.go index 0ede33afb1..eedfe30391 100644 --- a/internal/runners/export/env.go +++ b/internal/runners/export/env.go @@ -4,6 +4,7 @@ import ( "github.com/ActiveState/cli/internal/analytics" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -17,6 +18,7 @@ type Env struct { svcModel *model.SvcModel auth *authentication.Auth project *project.Project + prompt prompt.Prompter } func NewEnv(prime primeable) *Env { @@ -26,6 +28,7 @@ func NewEnv(prime primeable) *Env { prime.SvcModel(), prime.Auth(), prime.Project(), + prime.Prompt(), } } @@ -39,7 +42,7 @@ func (e *Env) Run() error { e.project.Dir()), ) - rt, err := runtime.NewFromProject(e.project, target.TriggerActivate, e.analytics, e.svcModel, e.out, e.auth) + rt, err := runtime.NewFromProject(e.project, target.TriggerActivate, e.analytics, e.svcModel, e.out, e.auth, e.prompt) if err != nil { return locale.WrapError(err, "err_export_new_runtime", "Could not initialize runtime") } diff --git a/internal/runners/export/export.go b/internal/runners/export/export.go index 34e425b46a..aa2df448ef 100644 --- a/internal/runners/export/export.go +++ b/internal/runners/export/export.go @@ -13,6 +13,7 @@ type primeable interface { primer.Projecter primer.Analyticer primer.SvcModeler + primer.Prompter } type Export struct{} diff --git a/internal/runners/export/recipe.go b/internal/runners/export/recipe.go index 14b276e987..189f2208d6 100644 --- a/internal/runners/export/recipe.go +++ b/internal/runners/export/recipe.go @@ -8,7 +8,8 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" "github.com/ActiveState/cli/pkg/sysinfo" @@ -18,10 +19,11 @@ import ( type Recipe struct { output.Outputer *project.Project + prompt.Prompter } func NewRecipe(prime primeable) *Recipe { - return &Recipe{prime.Output(), prime.Project()} + return &Recipe{prime.Output(), prime.Project(), prime.Prompt()} } type RecipeParams struct { @@ -34,7 +36,7 @@ type RecipeParams struct { func (r *Recipe) Run(params *RecipeParams) error { logging.Debug("Execute") - data, err := recipeData(r.Project, params.CommitID, params.Platform) + data, err := recipeData(r.Project, params.CommitID, params.Platform, r.Prompter, r.Outputer) if err != nil { return err } @@ -51,10 +53,10 @@ func (r *Recipe) Run(params *RecipeParams) error { return nil } -func recipeData(proj *project.Project, commitID, platform string) ([]byte, error) { +func recipeData(proj *project.Project, commitID, platform string, prompter prompt.Prompter, out output.Outputer) ([]byte, error) { cid := strfmt.UUID(commitID) - r, err := fetchRecipe(proj, cid, platform) + r, err := fetchRecipe(proj, cid, platform, prompter, out) if err != nil { return nil, err } @@ -72,7 +74,7 @@ func beautifyJSON(d []byte) ([]byte, error) { return out.Bytes(), nil } -func fetchRecipe(proj *project.Project, commitID strfmt.UUID, platform string) (string, error) { +func fetchRecipe(proj *project.Project, commitID strfmt.UUID, platform string, prompter prompt.Prompter, out output.Outputer) (string, error) { if platform == "" { platform = sysinfo.OS().String() } @@ -83,7 +85,7 @@ func fetchRecipe(proj *project.Project, commitID strfmt.UUID, platform string) ( if commitID == "" { var err error - commitID, err = commitid.GetCompatible(proj) + commitID, err = commitmediator.Get(proj, prompter, out) if err != nil { return "", errs.Wrap(err, "Unable to get local commit") } diff --git a/internal/runners/hello/hello_example.go b/internal/runners/hello/hello_example.go index 91b0de3461..517850a804 100644 --- a/internal/runners/hello/hello_example.go +++ b/internal/runners/hello/hello_example.go @@ -14,8 +14,9 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" @@ -26,6 +27,7 @@ type primeable interface { primer.Outputer primer.Auther primer.Projecter + primer.Prompter } // RunParams defines the parameters needed to execute a given runner. These @@ -49,6 +51,7 @@ func NewRunParams() *RunParams { type Hello struct { out output.Outputer project *project.Project + prompt prompt.Prompter } // New contains the scope in which an instance of Hello is constructed from an @@ -57,6 +60,7 @@ func New(p primeable) *Hello { return &Hello{ out: p.Output(), project: p.Project(), + prompt: p.Prompt(), } } @@ -116,7 +120,7 @@ func (h *Hello) Run(params *RunParams) (rerr error) { } // Grab data from the platform. - commitMsg, err := currentCommitMessage(h.project) + commitMsg, err := currentCommitMessage(h.project, h.prompt, h.out) if err != nil { err = errs.Wrap( err, "Cannot get commit message", @@ -140,12 +144,12 @@ func (h *Hello) Run(params *RunParams) (rerr error) { // is obtained. Since it is a sort of construction function that has some // complexity, it is helpful to provide localized error context. Secluding this // sort of logic is helpful to keep the subhandlers clean. -func currentCommitMessage(proj *project.Project) (string, error) { +func currentCommitMessage(proj *project.Project, prompter prompt.Prompter, out output.Outputer) (string, error) { if proj == nil { return "", errs.New("Cannot determine which project to use") } - commitId, err := commitid.GetCompatible(proj) + commitId, err := commitmediator.Get(proj, prompter, out) if err != nil { return "", errs.Wrap(err, "Cannot determine which commit to use") } diff --git a/internal/runners/history/history.go b/internal/runners/history/history.go index 2beaa9107b..906aa51290 100644 --- a/internal/runners/history/history.go +++ b/internal/runners/history/history.go @@ -5,7 +5,8 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/cmdlets/commit" "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/model" @@ -16,17 +17,20 @@ import ( type primeable interface { primer.Projecter primer.Outputer + primer.Prompter } type History struct { project *project.Project out output.Outputer + prompt prompt.Prompter } func NewHistory(prime primeable) *History { return &History{ prime.Project(), prime.Output(), + prime.Prompt(), } } @@ -39,7 +43,7 @@ func (h *History) Run(params *HistoryParams) error { } h.out.Notice(locale.Tl("operating_message", "", h.project.NamespaceString(), h.project.Dir())) - localCommitID, err := commitid.GetCompatible(h.project) + localCommitID, err := commitmediator.Get(h.project, h.prompt, h.out) if err != nil { return errs.Wrap(err, "Unable to get local commit") } diff --git a/internal/runners/initialize/init.go b/internal/runners/initialize/init.go index e1617e26b8..ab7cfff947 100644 --- a/internal/runners/initialize/init.go +++ b/internal/runners/initialize/init.go @@ -16,8 +16,9 @@ import ( "github.com/ActiveState/cli/internal/osutils" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -42,6 +43,7 @@ type Initialize struct { out output.Outputer analytics analytics.Dispatcher svcModel *model.SvcModel + prompt prompt.Prompter } type primeable interface { @@ -50,18 +52,19 @@ type primeable interface { primer.Outputer primer.Analyticer primer.SvcModeler + primer.Prompter } // New returns a prepared ptr to Initialize instance. func New(prime primeable) *Initialize { - return &Initialize{prime.Auth(), prime.Config(), prime.Output(), prime.Analytics(), prime.SvcModel()} + return &Initialize{prime.Auth(), prime.Config(), prime.Output(), prime.Analytics(), prime.SvcModel(), prime.Prompt()} } // inferLanguage tries to infer a reasonable default language from the project currently in use // (i.e. `state use show`). // Error handling is not necessary because it's an input error to not include a language to // `state init`. We're just trying to infer one as a convenience to the user. -func inferLanguage(config projectfile.ConfigGetter) (string, string, bool) { +func inferLanguage(config projectfile.ConfigGetter, prompter prompt.Prompter, out output.Outputer) (string, string, bool) { defaultProjectDir := config.GetString(constants.GlobalDefaultPrefname) if defaultProjectDir == "" { return "", "", false @@ -70,7 +73,7 @@ func inferLanguage(config projectfile.ConfigGetter) (string, string, bool) { if err != nil { return "", "", false } - commitID, err := commitid.GetCompatible(defaultProj) + commitID, err := commitmediator.Get(defaultProj, prompter, out) if err != nil { multilog.Error("Unable to get local commit: %v", errs.JoinMessage(err)) return "", "", false @@ -124,7 +127,7 @@ func (r *Initialize) Run(params *RunParams) (rerr error) { languageVersion = langParts[1] } } else { - languageName, languageVersion, inferred = inferLanguage(r.config) + languageName, languageVersion, inferred = inferLanguage(r.config, r.prompt, r.out) } if languageName == "" { @@ -250,7 +253,7 @@ func (r *Initialize) Run(params *RunParams) (rerr error) { return locale.WrapError(err, "err_init_push", "Failed to push to the newly created Platform project at {{.V0}}", namespace.String()) } - err = runbits.RefreshRuntime(r.auth, r.out, r.analytics, proj, commitID, true, target.TriggerInit, r.svcModel) + err = runbits.RefreshRuntime(r.auth, r.out, r.analytics, proj, commitID, true, target.TriggerInit, r.svcModel, r.prompt) if err != nil { logging.Debug("Deleting remotely created project due to runtime setup error") err2 := model.DeleteProject(namespace.Owner, namespace.Project, r.auth) @@ -263,7 +266,7 @@ func (r *Initialize) Run(params *RunParams) (rerr error) { projectfile.StoreProjectMapping(r.config, namespace.String(), filepath.Dir(proj.Source().Path())) - projectTarget := target.NewProjectTarget(proj, nil, "").Dir() + projectTarget := target.NewProjectTarget(proj, nil, "", r.prompt, r.out).Dir() executables := setup.ExecDir(projectTarget) r.out.Print(output.Prepare( diff --git a/internal/runners/languages/languages.go b/internal/runners/languages/languages.go index 49539004ec..c0cda7bb57 100644 --- a/internal/runners/languages/languages.go +++ b/internal/runners/languages/languages.go @@ -6,7 +6,8 @@ import ( "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" ) @@ -15,6 +16,7 @@ import ( type Languages struct { out output.Outputer project *project.Project + prompt prompt.Prompter } // NewLanguages prepares a list execution context for use. @@ -22,6 +24,7 @@ func NewLanguages(prime primeable) *Languages { return &Languages{ prime.Output(), prime.Project(), + prime.Prompt(), } } @@ -31,7 +34,7 @@ func (l *Languages) Run() error { return locale.NewInputError("err_no_project") } - commitID, err := commitid.GetCompatible(l.project) + commitID, err := commitmediator.Get(l.project, l.prompt, l.out) if err != nil { return errs.AddTips( locale.WrapError( diff --git a/internal/runners/packages/import.go b/internal/runners/packages/import.go index 943d39f105..552879be0f 100644 --- a/internal/runners/packages/import.go +++ b/internal/runners/packages/import.go @@ -139,7 +139,7 @@ func (i *Import) Run(params *ImportRunParams) error { return locale.WrapError(err, "err_commit_changeset", "Could not commit import changes") } - return runbits.RefreshRuntime(i.auth, i.out, i.analytics, i.proj, commitID, true, target.TriggerImport, i.svcModel) + return runbits.RefreshRuntime(i.auth, i.out, i.analytics, i.proj, commitID, true, target.TriggerImport, i.svcModel, i.Prompter) } func removeRequirements(conf Confirmer, project *project.Project, params *ImportRunParams, reqs []*gqlModel.Requirement) error { diff --git a/internal/runners/packages/info.go b/internal/runners/packages/info.go index ea0370d5c6..859ab613e3 100644 --- a/internal/runners/packages/info.go +++ b/internal/runners/packages/info.go @@ -8,6 +8,7 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/pkg/platform/api/inventory/inventory_models" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" @@ -22,15 +23,17 @@ type InfoRunParams struct { // Info manages the information execution context. type Info struct { - out output.Outputer - proj *project.Project + out output.Outputer + proj *project.Project + prompt prompt.Prompter } // NewInfo prepares an information execution context for use. func NewInfo(prime primeable) *Info { return &Info{ - out: prime.Output(), - proj: prime.Project(), + out: prime.Output(), + proj: prime.Project(), + prompt: prime.Prompt(), } } @@ -38,7 +41,7 @@ func NewInfo(prime primeable) *Info { func (i *Info) Run(params InfoRunParams, nstype model.NamespaceType) error { logging.Debug("ExecuteInfo") - language, err := targetedLanguage(params.Language, i.proj) + language, err := targetedLanguage(params.Language, i.proj, i.prompt, i.out) if err != nil { return locale.WrapError(err, fmt.Sprintf("%s_err_cannot_obtain_language", nstype)) diff --git a/internal/runners/packages/list.go b/internal/runners/packages/list.go index 6992d5dbbd..630093f9eb 100644 --- a/internal/runners/packages/list.go +++ b/internal/runners/packages/list.go @@ -13,7 +13,8 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" ) @@ -29,6 +30,7 @@ type ListRunParams struct { type List struct { out output.Outputer project *project.Project + prompt prompt.Prompter } // NewList prepares a list execution context for use. @@ -36,6 +38,7 @@ func NewList(prime primeable) *List { return &List{ out: prime.Output(), project: prime.Project(), + prompt: prime.Prompt(), } } @@ -61,7 +64,7 @@ func (l *List) Run(params ListRunParams, nstype model.NamespaceType) error { return locale.WrapError(err, fmt.Sprintf("%s_err_cannot_obtain_commit", nstype)) } default: - commit, err = targetFromProjectFile(l.project) + commit, err = targetFromProjectFile(l.project, l.prompt, l.out) if err != nil { return locale.WrapError(err, fmt.Sprintf("%s_err_cannot_obtain_commit", nstype)) } @@ -104,12 +107,12 @@ func targetFromProject(projectString string) (*strfmt.UUID, error) { return branch.CommitID, nil } -func targetFromProjectFile(proj *project.Project) (*strfmt.UUID, error) { +func targetFromProjectFile(proj *project.Project, prompter prompt.Prompter, out output.Outputer) (*strfmt.UUID, error) { logging.Debug("commit from project file") if proj == nil { return nil, locale.NewInputError("err_no_project") } - commit, err := commitid.GetCompatible(proj) + commit, err := commitmediator.Get(proj, prompter, out) if err != nil { return nil, errs.Wrap(err, "Unable to get local commit") } diff --git a/internal/runners/packages/search.go b/internal/runners/packages/search.go index 5280e0208c..11c05a47f9 100644 --- a/internal/runners/packages/search.go +++ b/internal/runners/packages/search.go @@ -9,7 +9,8 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" ) @@ -23,15 +24,17 @@ type SearchRunParams struct { // Search manages the searching execution context. type Search struct { - out output.Outputer - proj *project.Project + out output.Outputer + proj *project.Project + prompt prompt.Prompter } // NewSearch prepares a searching execution context for use. func NewSearch(prime primeable) *Search { return &Search{ - out: prime.Output(), - proj: prime.Project(), + out: prime.Output(), + proj: prime.Project(), + prompt: prime.Prompt(), } } @@ -39,7 +42,7 @@ func NewSearch(prime primeable) *Search { func (s *Search) Run(params SearchRunParams, nstype model.NamespaceType) error { logging.Debug("ExecuteSearch") - language, err := targetedLanguage(params.Language, s.proj) + language, err := targetedLanguage(params.Language, s.proj, s.prompt, s.out) if err != nil { return locale.WrapError(err, fmt.Sprintf("%s_err_cannot_obtain_language", nstype)) } @@ -67,7 +70,7 @@ func (s *Search) Run(params SearchRunParams, nstype model.NamespaceType) error { return nil } -func targetedLanguage(languageOpt string, proj *project.Project) (string, error) { +func targetedLanguage(languageOpt string, proj *project.Project, prompter prompt.Prompter, out output.Outputer) (string, error) { if languageOpt != "" { return languageOpt, nil } @@ -78,7 +81,7 @@ func targetedLanguage(languageOpt string, proj *project.Project) (string, error) ) } - commitID, err := commitid.GetCompatible(proj) + commitID, err := commitmediator.Get(proj, prompter, out) if err != nil { return "", errs.Wrap(err, "Unable to get local commit") } diff --git a/internal/runners/platforms/list.go b/internal/runners/platforms/list.go index b29c06b1b9..d740d1de11 100644 --- a/internal/runners/platforms/list.go +++ b/internal/runners/platforms/list.go @@ -5,7 +5,8 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" "github.com/go-openapi/strfmt" @@ -13,15 +14,17 @@ import ( // List manages the listing execution context. type List struct { - out output.Outputer - proj *project.Project + out output.Outputer + proj *project.Project + prompt prompt.Prompter } // NewList prepares a list execution context for use. func NewList(prime primeable) *List { return &List{ - out: prime.Output(), - proj: prime.Project(), + out: prime.Output(), + proj: prime.Project(), + prompt: prime.Prompt(), } } @@ -33,7 +36,7 @@ func (l *List) Run() error { return locale.NewInputError("err_no_project") } - commitID, err := commitid.GetCompatible(l.proj) + commitID, err := commitmediator.Get(l.proj, l.prompt, l.out) if err != nil { return errs.Wrap(err, "Unable to get local commit") } diff --git a/internal/runners/prepare/prepare.go b/internal/runners/prepare/prepare.go index f9e6f4f139..3298f7dd19 100644 --- a/internal/runners/prepare/prepare.go +++ b/internal/runners/prepare/prepare.go @@ -20,7 +20,8 @@ import ( "github.com/ActiveState/cli/internal/osutils/autostart" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/subshell" "github.com/ActiveState/cli/pkg/platform/model" rt "github.com/ActiveState/cli/pkg/platform/runtime" @@ -37,6 +38,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.Prompter } // Prepare manages the prepare execution context. @@ -46,6 +48,7 @@ type Prepare struct { cfg *config.Instance analytics analytics.Dispatcher svcModel *model.SvcModel + prompt prompt.Prompter } // New prepares a prepare execution context for use. @@ -55,6 +58,7 @@ func New(prime primeable) *Prepare { subshell: prime.Subshell(), cfg: prime.Config(), analytics: prime.Analytics(), + prompt: prime.Prompt(), } } @@ -74,7 +78,7 @@ func (r *Prepare) resetExecutors() error { return errs.Wrap(err, "Could not get project from its directory") } - commitID, err := commitid.GetCompatible(proj) + commitID, err := commitmediator.Get(proj, r.prompt, r.out) if err != nil { return errs.Wrap(err, "Unable to get local commit") } @@ -87,7 +91,7 @@ func (r *Prepare) resetExecutors() error { return errs.Wrap(err, "Could not initialize runtime for project.") } - if err := globaldefault.SetupDefaultActivation(r.subshell, r.cfg, run, proj); err != nil { + if err := globaldefault.SetupDefaultActivation(r.subshell, r.cfg, run, proj, r.prompt, r.out); err != nil { return errs.Wrap(err, "Failed to rewrite the executors.") } diff --git a/internal/runners/projects/projects.go b/internal/runners/projects/projects.go index fcd85476f4..34266f974e 100644 --- a/internal/runners/projects/projects.go +++ b/internal/runners/projects/projects.go @@ -7,6 +7,7 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/multilog" "github.com/ActiveState/cli/internal/output" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/runtime/setup" @@ -23,12 +24,12 @@ type projectWithOrg struct { Executables []string `json:"executables,omitempty"` } -func newProjectWithOrg(name, org string, checkouts []string) projectWithOrg { +func newProjectWithOrg(name, org string, checkouts []string, prompter prompt.Prompter, out output.Outputer) projectWithOrg { p := projectWithOrg{Name: name, Organization: org, LocalCheckouts: checkouts} for _, checkout := range checkouts { var execDir string if proj, err := project.FromPath(checkout); err == nil { - projectTarget := target.NewProjectTarget(proj, nil, "") + projectTarget := target.NewProjectTarget(proj, nil, "", prompter, out) execDir = setup.ExecDir(projectTarget.Dir()) } else { multilog.Error("Unable to get project %s from checkout: %v", checkout, err) @@ -98,6 +99,7 @@ type Projects struct { auth *authentication.Auth out output.Outputer config configGetter + prompt prompt.Prompter } type primeable interface { @@ -112,14 +114,15 @@ func NewParams() *Params { } func NewProjects(prime primeable) *Projects { - return newProjects(prime.Auth(), prime.Output(), prime.Config()) + return newProjects(prime.Auth(), prime.Output(), prime.Config(), prime.Prompt()) } -func newProjects(auth *authentication.Auth, out output.Outputer, config configGetter) *Projects { +func newProjects(auth *authentication.Auth, out output.Outputer, config configGetter, prompter prompt.Prompter) *Projects { return &Projects{ auth, out, config, + prompter, } } @@ -133,7 +136,7 @@ func (r *Projects) Run(params *Params) error { multilog.Error("Invalid project namespace stored to config mapping: %s", namespace) continue } - projects = append(projects, newProjectWithOrg(ns.Project, ns.Owner, checkouts)) + projects = append(projects, newProjectWithOrg(ns.Project, ns.Owner, checkouts, r.prompt, r.out)) } sort.SliceStable(projects, func(i, j int) bool { diff --git a/internal/runners/pull/pull.go b/internal/runners/pull/pull.go index 7d0a96872e..aabce3ba87 100644 --- a/internal/runners/pull/pull.go +++ b/internal/runners/pull/pull.go @@ -172,7 +172,7 @@ func (p *Pull) Run(params *PullParams) error { }) } - err = runbits.RefreshRuntime(p.auth, p.out, p.analytics, p.project, *resultingCommit, true, target.TriggerPull, p.svcModel) + err = runbits.RefreshRuntime(p.auth, p.out, p.analytics, p.project, *resultingCommit, true, target.TriggerPull, p.svcModel, p.prompt) if err != nil { return locale.WrapError(err, "err_pull_refresh", "Could not refresh runtime after pull") } diff --git a/internal/runners/refresh/refresh.go b/internal/runners/refresh/refresh.go index 05361977cb..5e9b7e4ddd 100644 --- a/internal/runners/refresh/refresh.go +++ b/internal/runners/refresh/refresh.go @@ -63,7 +63,7 @@ func (r *Refresh) Run(params *Params) error { return locale.WrapError(err, "err_refresh_cannot_load_project", "Cannot load project to update runtime for") } - rti, err := runtime.NewFromProject(proj, target.TriggerRefresh, r.analytics, r.svcModel, r.out, r.auth) + rti, err := runtime.NewFromProject(proj, target.TriggerRefresh, r.analytics, r.svcModel, r.out, r.auth, r.prompt) if err != nil { return locale.WrapInputError(err, "err_refresh_runtime_new", "Could not update runtime for this project.") } diff --git a/internal/runners/reset/reset.go b/internal/runners/reset/reset.go index f64ac2cd6d..45f315faa1 100644 --- a/internal/runners/reset/reset.go +++ b/internal/runners/reset/reset.go @@ -105,7 +105,7 @@ func (r *Reset) Run(params *Params) error { return errs.Wrap(err, "Unable to set local commit") } - err = runbits.RefreshRuntime(r.auth, r.out, r.analytics, r.project, commitID, true, target.TriggerReset, r.svcModel) + err = runbits.RefreshRuntime(r.auth, r.out, r.analytics, r.project, commitID, true, target.TriggerReset, r.svcModel, r.prompt) if err != nil { return locale.WrapError(err, "err_refresh_runtime") } diff --git a/internal/runners/revert/revert.go b/internal/runners/revert/revert.go index f2e345a29a..353d3cdb21 100644 --- a/internal/runners/revert/revert.go +++ b/internal/runners/revert/revert.go @@ -134,7 +134,7 @@ func (r *Revert) Run(params *Params) error { locale.T("tip_private_project_auth")) } - err = runbits.RefreshRuntime(r.auth, r.out, r.analytics, r.project, revertCommit.CommitID, true, target.TriggerRevert, r.svcModel) + err = runbits.RefreshRuntime(r.auth, r.out, r.analytics, r.project, revertCommit.CommitID, true, target.TriggerRevert, r.svcModel, r.prompt) if err != nil { return locale.WrapError(err, "err_refresh_runtime") } diff --git a/internal/runners/run/run.go b/internal/runners/run/run.go index 6037ee2042..8a156774c3 100644 --- a/internal/runners/run/run.go +++ b/internal/runners/run/run.go @@ -10,6 +10,7 @@ import ( "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/scriptrun" "github.com/ActiveState/cli/internal/subshell" "github.com/ActiveState/cli/pkg/cmdlets/checker" @@ -27,6 +28,7 @@ type Run struct { cfg *config.Instance svcModel *model.SvcModel analytics analytics.Dispatcher + prompt prompt.Prompter } type primeable interface { @@ -37,6 +39,7 @@ type primeable interface { primer.Configurer primer.SvcModeler primer.Analyticer + primer.Prompter } // New constructs a new instance of Run. @@ -49,6 +52,7 @@ func New(prime primeable) *Run { prime.Config(), prime.SvcModel(), prime.Analytics(), + prime.Prompt(), } } @@ -71,7 +75,7 @@ func (r *Run) Run(name string, args []string) error { r.out.Notice(output.Title(locale.Tl("run_script_title", "Running Script: [ACTIONABLE]{{.V0}}[/RESET]", name))) if authentication.LegacyGet().Authenticated() { - checker.RunCommitsBehindNotifier(r.proj, r.out) + checker.RunCommitsBehindNotifier(r.proj, r.prompt, r.out) } script := r.proj.ScriptByName(name) @@ -79,7 +83,7 @@ func (r *Run) Run(name string, args []string) error { return locale.NewInputError("error_state_run_unknown_name", "", name) } - scriptrunner := scriptrun.New(r.auth, r.out, r.subshell, r.proj, r.cfg, r.analytics, r.svcModel) + scriptrunner := scriptrun.New(r.auth, r.out, r.subshell, r.proj, r.cfg, r.analytics, r.svcModel, r.prompt) if !script.Standalone() && scriptrunner.NeedsActivation() { if err := scriptrunner.PrepareVirtualEnv(); err != nil { return locale.WrapError(err, "err_script_run_preparevenv", "Could not prepare virtual environment.") diff --git a/internal/runners/shell/shell.go b/internal/runners/shell/shell.go index 2905afa269..082778ce76 100644 --- a/internal/runners/shell/shell.go +++ b/internal/runners/shell/shell.go @@ -11,7 +11,7 @@ import ( "github.com/ActiveState/cli/internal/process" "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits/activation" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/runbits/findproject" "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/internal/subshell" @@ -72,7 +72,7 @@ func (u *Shell) Run(params *Params) error { return locale.WrapError(err, "err_shell_cannot_load_project") } - commitID, err := commitid.GetCompatible(proj) + commitID, err := commitmediator.Get(proj, u.prompt, u.out) if err != nil { return errs.Wrap(err, "Unable to get local commit") } @@ -81,7 +81,7 @@ func (u *Shell) Run(params *Params) error { return locale.NewInputError("err_shell_commit_id_mismatch") } - rti, err := runtime.NewFromProject(proj, target.TriggerShell, u.analytics, u.svcModel, u.out, u.auth) + rti, err := runtime.NewFromProject(proj, target.TriggerShell, u.analytics, u.svcModel, u.out, u.auth, u.prompt) if err != nil { return locale.WrapInputError(err, "err_shell_runtime_new", "Could not start a shell/prompt for this project.") } diff --git a/internal/runners/show/show.go b/internal/runners/show/show.go index 9c75bfad51..8fa2f18df6 100644 --- a/internal/runners/show/show.go +++ b/internal/runners/show/show.go @@ -14,7 +14,8 @@ import ( "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/secrets" "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" secretsapi "github.com/ActiveState/cli/pkg/platform/api/secrets" @@ -37,6 +38,7 @@ type Show struct { out output.Outputer conditional *constraints.Conditional auth *authentication.Auth + prompt prompt.Prompter } type auther interface { @@ -48,6 +50,7 @@ type primeable interface { primer.Outputer primer.Conditioner primer.Auther + primer.Prompter } type RuntimeDetails struct { @@ -131,6 +134,7 @@ func New(prime primeable) *Show { prime.Output(), prime.Conditional(), prime.Auth(), + prime.Prompt(), } } @@ -193,7 +197,7 @@ func (s *Show) Run(params Params) error { return locale.WrapError(err, "err_show_scripts", "Could not parse scripts") } - commitID, err = commitid.GetCompatible(s.project) + commitID, err = commitmediator.Get(s.project, s.prompt, s.out) if err != nil { return errs.Wrap(err, "Unable to get local commit") } @@ -206,7 +210,7 @@ func (s *Show) Run(params Params) error { } } - projectTarget = target.NewProjectTarget(s.project, nil, "").Dir() + projectTarget = target.NewProjectTarget(s.project, nil, "", s.prompt, s.out).Dir() } remoteProject, err := model.LegacyFetchProjectByName(owner, projectName) @@ -230,7 +234,7 @@ func (s *Show) Run(params Params) error { return locale.WrapError(err, "err_show_langauges", "Could not retrieve language information") } - commit, err := commitsData(owner, projectName, branchName, commitID, s.project, s.auth) + commit, err := commitsData(owner, projectName, branchName, commitID, s.project, s.auth, s.prompt, s.out) if err != nil { return locale.WrapError(err, "err_show_commit", "Could not get commit information") } @@ -361,7 +365,7 @@ func visibilityData(owner, project string, remoteProject *mono_models.Project) s return locale.T("public") } -func commitsData(owner, project, branchName string, commitID strfmt.UUID, localProject *project.Project, auth auther) (string, error) { +func commitsData(owner, project, branchName string, commitID strfmt.UUID, localProject *project.Project, auth auther, prompter prompt.Prompter, out output.Outputer) (string, error) { latestCommit, err := model.BranchCommitID(owner, project, branchName) if err != nil { return "", locale.WrapError(err, "err_show_get_latest_commit", "Could not get latest commit ID") @@ -385,7 +389,7 @@ func commitsData(owner, project, branchName string, commitID strfmt.UUID, localP if err != nil { return "", locale.WrapError(err, "err_show_commits_behind", "Could not determine number of commits behind latest") } - localCommitID, err := commitid.GetCompatible(localProject) + localCommitID, err := commitmediator.Get(localProject, prompter, out) if err != nil { return "", errs.Wrap(err, "Unable to get local commit") } diff --git a/internal/runners/swtch/switch.go b/internal/runners/swtch/switch.go index 1f63120613..1117e311fc 100644 --- a/internal/runners/swtch/switch.go +++ b/internal/runners/swtch/switch.go @@ -7,6 +7,7 @@ import ( "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits" "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" @@ -23,6 +24,7 @@ type Switch struct { project *project.Project analytics analytics.Dispatcher svcModel *model.SvcModel + prompt prompt.Prompter } type SwitchParams struct { @@ -36,6 +38,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.Prompter } type identifier interface { @@ -74,6 +77,7 @@ func New(prime primeable) *Switch { project: prime.Project(), analytics: prime.Analytics(), svcModel: prime.SvcModel(), + prompt: prime.Prompt(), } } @@ -115,7 +119,7 @@ func (s *Switch) Run(params SwitchParams) error { return errs.Wrap(err, "Unable to set local commit") } - err = runbits.RefreshRuntime(s.auth, s.out, s.analytics, s.project, identifier.CommitID(), false, target.TriggerSwitch, s.svcModel) + err = runbits.RefreshRuntime(s.auth, s.out, s.analytics, s.project, identifier.CommitID(), false, target.TriggerSwitch, s.svcModel, s.prompt) if err != nil { return locale.WrapError(err, "err_refresh_runtime") } diff --git a/internal/runners/use/show.go b/internal/runners/use/show.go index 057e0ce667..1c1e9fe0af 100644 --- a/internal/runners/use/show.go +++ b/internal/runners/use/show.go @@ -6,6 +6,7 @@ import ( "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/pkg/platform/runtime/setup" "github.com/ActiveState/cli/pkg/platform/runtime/target" "github.com/ActiveState/cli/pkg/project" @@ -13,14 +14,16 @@ import ( ) type Show struct { - out output.Outputer - cfg *config.Instance + out output.Outputer + cfg *config.Instance + prompt prompt.Prompter } func NewShow(prime primeable) *Show { return &Show{ prime.Output(), prime.Config(), + prime.Prompt(), } } @@ -38,7 +41,7 @@ func (s *Show) Run() error { return locale.WrapError(err, "err_use_show_get_project", "Could not get your project.") } - projectTarget := target.NewProjectTarget(proj, nil, "") + projectTarget := target.NewProjectTarget(proj, nil, "", s.prompt, s.out) executables := setup.ExecDir(projectTarget.Dir()) s.out.Print(output.Prepare( diff --git a/internal/runners/use/use.go b/internal/runners/use/use.go index b266d15ec8..2e4019c4c8 100644 --- a/internal/runners/use/use.go +++ b/internal/runners/use/use.go @@ -12,7 +12,7 @@ import ( "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/prompt" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/runbits/findproject" "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/internal/subshell" @@ -77,7 +77,7 @@ func (u *Use) Run(params *Params) error { return locale.WrapInputError(err, "err_use_cannot_find_local_project", "Local project cannot be found.") } - commitID, err := commitid.GetCompatible(proj) + commitID, err := commitmediator.Get(proj, u.prompt, u.out) if err != nil { return errs.Wrap(err, "Unable to get local commit") } @@ -86,12 +86,12 @@ func (u *Use) Run(params *Params) error { return locale.NewInputError("err_use_commit_id_mismatch") } - rti, err := runtime.NewFromProject(proj, target.TriggerUse, u.analytics, u.svcModel, u.out, u.auth) + rti, err := runtime.NewFromProject(proj, target.TriggerUse, u.analytics, u.svcModel, u.out, u.auth, u.prompt) if err != nil { return locale.WrapError(err, "err_use_runtime_new", "Cannot use this project.") } - if err := globaldefault.SetupDefaultActivation(u.subshell, u.config, rti, proj); err != nil { + if err := globaldefault.SetupDefaultActivation(u.subshell, u.config, rti, proj, u.prompt, u.out); err != nil { return locale.WrapError(err, "err_use_default", "Could not setup your project for use.") } diff --git a/internal/scriptrun/scriptrun.go b/internal/scriptrun/scriptrun.go index 70b90c4e24..6e6280907d 100644 --- a/internal/scriptrun/scriptrun.go +++ b/internal/scriptrun/scriptrun.go @@ -14,6 +14,7 @@ import ( "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/process" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/rtutils" "github.com/ActiveState/cli/internal/runbits" "github.com/ActiveState/cli/internal/scriptfile" @@ -35,13 +36,14 @@ type ScriptRun struct { cfg *config.Instance analytics analytics.Dispatcher svcModel *model.SvcModel + prompt prompt.Prompter venvPrepared bool venvExePath string } // New returns a pointer to a prepared instance of ScriptRun. -func New(auth *authentication.Auth, out output.Outputer, subs subshell.SubShell, proj *project.Project, cfg *config.Instance, analytics analytics.Dispatcher, svcModel *model.SvcModel) *ScriptRun { +func New(auth *authentication.Auth, out output.Outputer, subs subshell.SubShell, proj *project.Project, cfg *config.Instance, analytics analytics.Dispatcher, svcModel *model.SvcModel, prompter prompt.Prompter) *ScriptRun { return &ScriptRun{ auth, out, @@ -50,6 +52,7 @@ func New(auth *authentication.Auth, out output.Outputer, subs subshell.SubShell, cfg, analytics, svcModel, + prompter, false, @@ -67,7 +70,7 @@ func (s *ScriptRun) NeedsActivation() bool { // PrepareVirtualEnv sets up the relevant runtime and prepares the environment. func (s *ScriptRun) PrepareVirtualEnv() (rerr error) { - rt, err := runtime.New(target.NewProjectTarget(s.project, nil, target.TriggerScript), s.analytics, s.svcModel, s.auth) + rt, err := runtime.New(target.NewProjectTarget(s.project, nil, target.TriggerScript, s.prompt, s.out), s.analytics, s.svcModel, s.auth) switch { case err == nil: break diff --git a/internal/scriptrun/test/integration/scriptrun_test.go b/internal/scriptrun/test/integration/scriptrun_test.go index c38fef9be6..92de8633fa 100644 --- a/internal/scriptrun/test/integration/scriptrun_test.go +++ b/internal/scriptrun/test/integration/scriptrun_test.go @@ -74,7 +74,7 @@ scripts: cfg, err := config.New() require.NoError(t, err) defer func() { require.NoError(t, cfg.Close()) }() - scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil) + scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil, nil, nil) err = scriptRun.Run(proj.ScriptByName("run"), []string{}) assert.NoError(t, err, "No error occurred") } @@ -113,7 +113,7 @@ func (suite *ScriptRunSuite) TestEnvIsSet() { defer func() { require.NoError(t, cfg.Close()) }() out := capturer.CaptureOutput(func() { - scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil) + scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil, nil, nil) err = scriptRun.Run(proj.ScriptByName("run"), nil) assert.NoError(t, err, "Error: "+errs.JoinMessage(err)) }) @@ -157,7 +157,7 @@ scripts: defer func() { require.NoError(t, cfg.Close()) }() out := outputhelper.NewCatcher() - scriptRun := scriptrun.New(authentication.LegacyGet(), out, subshell.New(cfg), proj, cfg, blackhole.New(), nil) + scriptRun := scriptrun.New(authentication.LegacyGet(), out, subshell.New(cfg), proj, cfg, blackhole.New(), nil, nil, nil) fmt.Println(proj.ScriptByName("run")) err = scriptRun.Run(proj.ScriptByName("run"), nil) assert.NoError(t, err, "No error occurred") @@ -185,7 +185,7 @@ scripts: require.NoError(t, err) defer func() { require.NoError(t, cfg.Close()) }() - scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil) + scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil, nil, nil) err = scriptRun.Run(nil, nil) assert.Error(t, err, "Error occurred") } @@ -213,7 +213,7 @@ scripts: require.NoError(t, err) defer func() { require.NoError(t, cfg.Close()) }() - scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil) + scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil, nil, nil) err = scriptRun.Run(proj.ScriptByName("run"), nil) assert.Error(t, err, "Error occurred") } @@ -263,7 +263,7 @@ scripts: require.NoError(t, err) // Run the command. - scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil) + scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil, nil, nil) err = scriptRun.Run(proj.ScriptByName("run"), nil) assert.NoError(t, err, "No error occurred") @@ -356,7 +356,7 @@ func captureExecCommand(t *testing.T, tmplCmdName, cmdName string, cmdArgs []str defer func() { require.NoError(t, cfg.Close()) }() outStr, outErr := osutil.CaptureStdout(func() { - scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil) + scriptRun := scriptrun.New(authentication.LegacyGet(), outputhelper.NewCatcher(), subshell.New(cfg), proj, cfg, blackhole.New(), nil, nil, nil) err = scriptRun.Run(proj.ScriptByName(cmdName), cmdArgs) }) require.NoError(t, outErr, "error capturing stdout") diff --git a/pkg/cmdlets/checker/checker.go b/pkg/cmdlets/checker/checker.go index 28ba6bebe4..650b17b29d 100644 --- a/pkg/cmdlets/checker/checker.go +++ b/pkg/cmdlets/checker/checker.go @@ -15,7 +15,8 @@ import ( "github.com/ActiveState/cli/internal/multilog" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/profile" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/updater" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" @@ -23,8 +24,8 @@ import ( // RunCommitsBehindNotifier checks for the commits behind count based on the // provided project and displays the results to the user in a helpful manner. -func RunCommitsBehindNotifier(p *project.Project, out output.Outputer) { - count, err := CommitsBehind(p) +func RunCommitsBehindNotifier(p *project.Project, prompter prompt.Prompter, out output.Outputer) { + count, err := CommitsBehind(p, prompter, out) if err != nil { if errors.Is(err, model.ErrCommitCountUnknowable) { out.Notice(output.Title(locale.Tr("runtime_update_notice_unknown_count"))) @@ -42,7 +43,7 @@ func RunCommitsBehindNotifier(p *project.Project, out output.Outputer) { } } -func CommitsBehind(p *project.Project) (int, error) { +func CommitsBehind(p *project.Project, prompter prompt.Prompter, out output.Outputer) (int, error) { if p.IsHeadless() { return 0, nil } @@ -56,7 +57,7 @@ func CommitsBehind(p *project.Project) (int, error) { return 0, locale.NewError("err_latest_commit", "Latest commit ID is nil") } - commitID, err := commitid.GetCompatible(p) + commitID, err := commitmediator.Get(p, prompter, out) if err != nil { return 0, errs.Wrap(err, "Unable to get local commit") } diff --git a/pkg/platform/runtime/target/target.go b/pkg/platform/runtime/target/target.go index 82c710f393..a6d3c1404c 100644 --- a/pkg/platform/runtime/target/target.go +++ b/pkg/platform/runtime/target/target.go @@ -11,7 +11,9 @@ import ( "github.com/ActiveState/cli/internal/installation/storage" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/multilog" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/output" + "github.com/ActiveState/cli/internal/prompt" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/project" "github.com/go-openapi/strfmt" ) @@ -63,18 +65,20 @@ type ProjectTarget struct { cacheDir string customCommit *strfmt.UUID trigger Trigger + prompt.Prompter + output.Outputer } -func NewProjectTarget(pj *project.Project, customCommit *strfmt.UUID, trigger Trigger) *ProjectTarget { +func NewProjectTarget(pj *project.Project, customCommit *strfmt.UUID, trigger Trigger, prompter prompt.Prompter, out output.Outputer) *ProjectTarget { runtimeCacheDir := storage.CachePath() if pj.Cache() != "" { runtimeCacheDir = pj.Cache() } - return &ProjectTarget{pj, runtimeCacheDir, customCommit, trigger} + return &ProjectTarget{pj, runtimeCacheDir, customCommit, trigger, prompter, out} } -func NewProjectTargetCache(pj *project.Project, cacheDir string, customCommit *strfmt.UUID, trigger Trigger) *ProjectTarget { - return &ProjectTarget{pj, cacheDir, customCommit, trigger} +func NewProjectTargetCache(pj *project.Project, cacheDir string, customCommit *strfmt.UUID, trigger Trigger, prompter prompt.Prompter, out output.Outputer) *ProjectTarget { + return &ProjectTarget{pj, cacheDir, customCommit, trigger, prompter, out} } func (p *ProjectTarget) Dir() string { @@ -88,7 +92,7 @@ func (p *ProjectTarget) CommitUUID() strfmt.UUID { if p.customCommit != nil { return *p.customCommit } - commitID, err := commitid.GetCompatible(p.Project) + commitID, err := commitmediator.Get(p.Project, p.Prompter, p.Outputer) if err != nil { multilog.Error("Unable to get local commit: %v", errs.JoinMessage(err)) return "" diff --git a/pkg/project/expander.go b/pkg/project/expander.go index 39cf8f33aa..38daee496f 100644 --- a/pkg/project/expander.go +++ b/pkg/project/expander.go @@ -12,7 +12,7 @@ import ( "github.com/ActiveState/cli/internal/language" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/osutils" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/rxutils" "github.com/ActiveState/cli/internal/scriptfile" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -238,7 +238,7 @@ func ProjectExpander(_ string, name string, _ string, isFunction bool, ctx *Expa case "url": return project.URL(), nil case "commit": - commitID, err := commitid.GetCompatible(project) + commitID, err := commitmediator.Get(project, pPrompt, pOut) if err != nil { return "", errs.Wrap(err, "Unable to get local commit") } diff --git a/pkg/project/namespace.go b/pkg/project/namespace.go index d67a5ea718..2599c4cbce 100644 --- a/pkg/project/namespace.go +++ b/pkg/project/namespace.go @@ -8,7 +8,7 @@ import ( "github.com/ActiveState/cli/internal/fileutils" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/multilog" - "github.com/ActiveState/cli/internal/runbits/commitid" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/projectfile" "github.com/go-openapi/strfmt" ) @@ -153,7 +153,7 @@ func NameSpaceForConfig(configFile string) *Namespaced { Project: prj.Name(), } - commitID, err := commitid.GetCompatible(prj) + commitID, err := commitmediator.Get(prj, pPrompt, pOut) if err != nil { multilog.Error("Unable to get local commit: %v", errs.JoinMessage(err)) } diff --git a/pkg/project/project.go b/pkg/project/project.go index 2004ea0faa..c7e96b0736 100644 --- a/pkg/project/project.go +++ b/pkg/project/project.go @@ -19,6 +19,7 @@ import ( "github.com/ActiveState/cli/internal/multilog" "github.com/ActiveState/cli/internal/osutils" "github.com/ActiveState/cli/internal/output" + "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/pkg/localcommit" secretsapi "github.com/ActiveState/cli/pkg/platform/api/secrets" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -30,6 +31,8 @@ import ( type Build map[string]string var pConditional *constraints.Conditional +var pPrompt prompt.Prompter +var pOut output.Outputer var normalizeRx *regexp.Regexp func init() { @@ -46,6 +49,14 @@ func RegisterConditional(conditional *constraints.Conditional) { pConditional = conditional } +func RegisterPrompt(prompter prompt.Prompter) { + pPrompt = prompter +} + +func RegisterOutput(out output.Outputer) { + pOut = out +} + // Project covers the platform structure type Project struct { projectfile *projectfile.Project @@ -216,7 +227,7 @@ func (p *Project) ProjectDir() string { return p.Dir() } -// LegacyCommitID is for use by commitid.GetCompatible() ONLY. +// LegacyCommitID is for use by commitmediator.Get() ONLY. func (p *Project) LegacyCommitID() string { return p.projectfile.LegacyCommitID() } @@ -251,8 +262,8 @@ func (p *Project) Namespace() *Namespaced { commitID, err := localcommit.Get(p.Dir()) if err != nil { if !localcommit.IsFileDoesNotExistError(err) { - // Note: cannot use commitid.GetCompatible() because this is called by main before analytics - // and a prompt are set up. + // Note: cannot use commitmediator.Get() because this is called by main before analytics + // and a prompt and output are set up. commitID = strfmt.UUID(p.projectfile.LegacyCommitID()) } else { multilog.Error("Unable to get local commit: %v", errs.JoinMessage(err)) diff --git a/pkg/project/project_test.go b/pkg/project/project_test.go index b8c3ae4b63..09719f3981 100644 --- a/pkg/project/project_test.go +++ b/pkg/project/project_test.go @@ -46,7 +46,7 @@ func (suite *ProjectTestSuite) BeforeTest(suiteName, testName string) { cfg, err := config.New() suite.Require().NoError(err) - project.RegisterConditional(constraints.NewPrimeConditional(nil, suite.project, subshell.New(cfg).Shell())) + project.RegisterConditional(constraints.NewPrimeConditional(nil, suite.project, subshell.New(cfg).Shell()), nil, nil) } func (suite *ProjectTestSuite) TestGet() { diff --git a/pkg/projectfile/projectfile.go b/pkg/projectfile/projectfile.go index 8278ab9da3..37f0de8212 100644 --- a/pkg/projectfile/projectfile.go +++ b/pkg/projectfile/projectfile.go @@ -558,7 +558,7 @@ func (p *Project) Path() string { return p.path } -// LegacyCommitID is for use by commitid.GetCompatible() ONLY. +// LegacyCommitID is for use by commitmediator.Get() ONLY. // It returns a pre-migrated project's commit ID from activestate.yaml. func (p *Project) LegacyCommitID() string { return p.parsedURL.LegacyCommitID diff --git a/scripts/ci/parallelize/parallelize.go b/scripts/ci/parallelize/parallelize.go index 24360ace9a..361afecc4a 100644 --- a/scripts/ci/parallelize/parallelize.go +++ b/scripts/ci/parallelize/parallelize.go @@ -35,7 +35,7 @@ func main() { } func run() error { - if len(os.Args) <= 1{ + if len(os.Args) <= 1 { return errs.New("Must provide single argument with JSON blob, or [job ] to check the results of a job.") } @@ -104,7 +104,7 @@ func runJob(job Job) { return } - cond := constraints.NewPrimeConditional(nil, pj, "") + cond := constraints.NewPrimeConditional(nil, pj, "", nil, nil) run, err := cond.Eval(job.If) if err != nil { failure("Could not evaluate conditonal: %s, error: %s\n", job.If, errs.JoinMessage(err)) @@ -120,8 +120,7 @@ func runJob(job Job) { return } - - code, _, err := exeutils.Execute(job.Args[0] + osutils.ExeExt, job.Args[1:], func(cmd *exec.Cmd) error { + code, _, err := exeutils.Execute(job.Args[0]+osutils.ExeExt, job.Args[1:], func(cmd *exec.Cmd) error { cmd.Stdout = outfile cmd.Stderr = outfile cmd.Env = append(job.Env, os.Environ()...) @@ -136,14 +135,14 @@ func runJob(job Job) { func readJob(id string) error { jobfile := filepath.Join(jobDir(), fmt.Sprintf("%s.out", id)) - if ! fileutils.FileExists(jobfile) { + if !fileutils.FileExists(jobfile) { return errs.New("Job does not exist: %s", jobfile) } contents := strings.Split(string(fileutils.ReadFileUnsafe(jobfile)), "\n") code, err := strconv.Atoi(contents[len(contents)-1]) if err != nil { - return errs.Wrap(err,"Expected last line to be the exit code, instead found: %s", contents[len(contents)-1]) + return errs.Wrap(err, "Expected last line to be the exit code, instead found: %s", contents[len(contents)-1]) } fmt.Println(strings.Join(contents[0:(len(contents)-2)], "\n"))