From 62b0f0e1c26f0978e1daec236ab0c7235cdde091 Mon Sep 17 00:00:00 2001 From: Nathan Rijksen Date: Tue, 9 Feb 2021 14:05:52 -0800 Subject: [PATCH 1/5] Added headless state notifications --- cmd/state/internal/cmdtree/activate.go | 4 +++- cmd/state/internal/cmdtree/cmdtree.go | 18 +++++++++++++++++- internal/constants/constants.go | 3 +++ locale/en-us.yaml | 6 ++++++ test/integration/package_int_test.go | 1 + 5 files changed, 30 insertions(+), 2 deletions(-) diff --git a/cmd/state/internal/cmdtree/activate.go b/cmd/state/internal/cmdtree/activate.go index f17ffc90b6..bdb55bbd6c 100644 --- a/cmd/state/internal/cmdtree/activate.go +++ b/cmd/state/internal/cmdtree/activate.go @@ -14,6 +14,8 @@ import ( "github.com/ActiveState/cli/pkg/project" ) +const activateCmdName = "activate" + func newActivateCommand(prime *primer.Values) *captain.Command { runner := activate.NewActivate(prime) @@ -23,7 +25,7 @@ func newActivateCommand(prime *primer.Values) *captain.Command { } cmd := captain.NewCommand( - "activate", + activateCmdName, "", locale.T("activate_project"), prime.Output(), diff --git a/cmd/state/internal/cmdtree/cmdtree.go b/cmd/state/internal/cmdtree/cmdtree.go index 0c4e0d507d..12f911769c 100644 --- a/cmd/state/internal/cmdtree/cmdtree.go +++ b/cmd/state/internal/cmdtree/cmdtree.go @@ -4,11 +4,14 @@ import ( "github.com/ActiveState/cli/cmd/state/internal/cmdtree/intercepts/cmdcall" "github.com/ActiveState/cli/internal/captain" "github.com/ActiveState/cli/internal/condition" + "github.com/ActiveState/cli/internal/constants" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" + "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/runners/state" secretsapi "github.com/ActiveState/cli/pkg/platform/api/secrets" + "github.com/ActiveState/cli/pkg/project" ) // CmdTree manages a tree of captain.Command instances. @@ -253,7 +256,7 @@ func newStateCommand(globals *globalOptions, prime *primer.Values) *captain.Comm cmdCall := cmdcall.New(prime) - cmd.SetInterceptChain(cmdCall.InterceptExec) + cmd.SetInterceptChain(cmdCall.InterceptExec, interceptAddHeadlessNotify(prime.Output(), prime.Project())) return cmd } @@ -299,3 +302,16 @@ func (a *addCmdAs) deprecatedAlias(aliased *captain.Command, name string) { a.parent.AddChildren(cmd) } + +func interceptAddHeadlessNotify(out output.Outputer, pj *project.Project) captain.InterceptFunc { + return func(next captain.ExecuteFunc) captain.ExecuteFunc { + return func(cmd *captain.Command, args []string) error { + if pj != nil && pj.IsHeadless() && (cmd.Group() == PackagesGroup || cmd.Name() == activateCmdName) { + out.Notice(output.Heading(locale.Tr("headless_notify_title"))) + out.Notice(locale.Tr("headless_notify", pj.URL(), constants.DocumentationURLHeadless)) + } + + return next(cmd, args) + } + } +} diff --git a/internal/constants/constants.go b/internal/constants/constants.go index de835af0db..3fcd614772 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -170,6 +170,9 @@ const PlatformSignupURL = "https://platform.activestate.com" + "/create-account" // DocumentationURL is the url for the state tool documentation const DocumentationURL = "http://docs.activestate.com/platform/state/" +// DocumentationURLHeadless is the documentation URL for headless state docs +const DocumentationURLHeadless = DocumentationURL + "advanced-topics/headless/" + // BugTrackerURL is the URL of our bug tracker const BugTrackerURL = "https://github.com/ActiveState/state-tool/issues" diff --git a/locale/en-us.yaml b/locale/en-us.yaml index 03444da311..184932a936 100644 --- a/locale/en-us.yaml +++ b/locale/en-us.yaml @@ -1638,3 +1638,9 @@ err_activate_platfrom_alternate_branches: - {{.V1}} Type [ACTIONABLE]`state branch switch `[/RESET] to switch to a different branch. +headless_notify_title: + other: Detached State +headless_notify: + other: | + You are currently working in a detached state. Visit [ACTIONABLE]{{.V0}}[/RESET] to create a project from your detached state. + For more information, including how to re-attach to an existing project, visit [ACTIONABLE]{{.V1}}[/RESET]. diff --git a/test/integration/package_int_test.go b/test/integration/package_int_test.go index 670d8956ce..e611044b00 100644 --- a/test/integration/package_int_test.go +++ b/test/integration/package_int_test.go @@ -362,6 +362,7 @@ func (suite *PackageIntegrationTestSuite) TestPackage_headless_operation() { suite.Run("install (update)", func() { cp := ts.Spawn("install", "dateparser@0.7.6") + cp.ExpectLongString("You are currently working in a detached state") cp.ExpectRe("(?:Package updated|project is currently building)", 50*time.Second) cp.Wait() }) From afc3fe7c8d834d0a939288b31d248166e7298984 Mon Sep 17 00:00:00 2001 From: Nathan Rijksen Date: Tue, 9 Feb 2021 14:07:19 -0800 Subject: [PATCH 2/5] Added changelog entry --- changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index ed4619570a..af4fe79e23 100644 --- a/changelog.md +++ b/changelog.md @@ -19,6 +19,8 @@ Available on channel `master` headless projects) ([PR #1198](https://github.com/ActiveState/cli/pull/1198)) - You can now switch between update channels via `state update --set-channel` ([PR #1190](https://github.com/ActiveState/cli/pull/1190)) +- State tool will now provide instructions on how to get out of a detached + state ([PR #1248](https://github.com/ActiveState/cli/pull/1248)) ### Changed From 9c9e32d4989160db190b5ff1de00b289cac972cc Mon Sep 17 00:00:00 2001 From: Nathan Rijksen Date: Tue, 9 Feb 2021 14:10:18 -0800 Subject: [PATCH 3/5] Update changelog link --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index af4fe79e23..70d1fe94f5 100644 --- a/changelog.md +++ b/changelog.md @@ -20,7 +20,7 @@ Available on channel `master` - You can now switch between update channels via `state update --set-channel` ([PR #1190](https://github.com/ActiveState/cli/pull/1190)) - State tool will now provide instructions on how to get out of a detached - state ([PR #1248](https://github.com/ActiveState/cli/pull/1248)) + state ([PR #1249](https://github.com/ActiveState/cli/pull/1249)) ### Changed From 3080b4edd3924c3953b689ab391645b6fe9b6074 Mon Sep 17 00:00:00 2001 From: Nathan Rijksen Date: Mon, 22 Feb 2021 15:00:35 -0800 Subject: [PATCH 4/5] Next version should be 0.26.0 --- version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.txt b/version.txt index af2dabf3ff..4e8f395fa5 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.25.1 +0.26.0 From fd1713118be16c89ef52cd0381c74415ed3531e1 Mon Sep 17 00:00:00 2001 From: Nathan Rijksen Date: Tue, 23 Feb 2021 10:13:05 -0800 Subject: [PATCH 5/5] Integrate Pete's suggestions --- internal/constants/constants.go | 2 +- locale/en-us.yaml | 5 +++-- test/integration/package_int_test.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/constants/constants.go b/internal/constants/constants.go index 896a272782..1450106319 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -171,7 +171,7 @@ const PlatformSignupURL = "https://platform.activestate.com" + "/create-account" const DocumentationURL = "http://docs.activestate.com/platform/state/" // DocumentationURLHeadless is the documentation URL for headless state docs -const DocumentationURLHeadless = DocumentationURL + "advanced-topics/headless/" +const DocumentationURLHeadless = DocumentationURL + "advanced-topics/detached/" // BugTrackerURL is the URL of our bug tracker const BugTrackerURL = "https://github.com/ActiveState/state-tool/issues" diff --git a/locale/en-us.yaml b/locale/en-us.yaml index 38ddd0c19b..6e79daf1ad 100644 --- a/locale/en-us.yaml +++ b/locale/en-us.yaml @@ -1646,5 +1646,6 @@ headless_notify_title: other: Detached State headless_notify: other: | - You are currently working in a detached state. Visit [ACTIONABLE]{{.V0}}[/RESET] to create a project from your detached state. - For more information, including how to re-attach to an existing project, visit [ACTIONABLE]{{.V1}}[/RESET]. + Any changes you make are local only and will not be saved the platform. Visit: [ACTIONABLE]{{.V0}}[/RESET] to create a platform project from this commit. + + For more information, including how to merge these changes into an existing project, visit: [ACTIONABLE]{{.V1}}[/RESET]. diff --git a/test/integration/package_int_test.go b/test/integration/package_int_test.go index e611044b00..5cf36100b3 100644 --- a/test/integration/package_int_test.go +++ b/test/integration/package_int_test.go @@ -362,7 +362,7 @@ func (suite *PackageIntegrationTestSuite) TestPackage_headless_operation() { suite.Run("install (update)", func() { cp := ts.Spawn("install", "dateparser@0.7.6") - cp.ExpectLongString("You are currently working in a detached state") + cp.ExpectLongString("Any changes you make are local only") cp.ExpectRe("(?:Package updated|project is currently building)", 50*time.Second) cp.Wait() })