Skip to content

Commit 8ddc533

Browse files
committed
feat: add ctx hub status, peer, and stepdown commands
Cluster management CLI: ctx hub status shows role and entry counts, ctx hub peer add/remove manages cluster membership, ctx hub stepdown transfers leadership gracefully. Signed-off-by: Murat Parlakisik <parlakisik@gmail.com>
1 parent 42f6e04 commit 8ddc533

20 files changed

Lines changed: 485 additions & 0 deletions

File tree

internal/assets/commands/commands.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,33 @@ drift:
295295
296296
Use --json for machine-readable output.
297297
short: Detect stale or invalid context
298+
hub:
299+
long: |-
300+
Manage a running shared context hub cluster.
301+
short: Manage hub cluster
302+
hub.status:
303+
long: |-
304+
Show cluster status: role, peers, sync state, entry
305+
count, and uptime.
306+
307+
Examples:
308+
ctx hub status
309+
short: Show cluster status
310+
hub.peer:
311+
long: |-
312+
Add or remove peers from the cluster at runtime.
313+
314+
Examples:
315+
ctx hub peer add host:9901
316+
ctx hub peer remove host:9901
317+
short: Add or remove cluster peers
318+
hub.stepdown:
319+
long: |-
320+
Transfer leadership to another node gracefully.
321+
322+
Examples:
323+
ctx hub stepdown
324+
short: Transfer leadership
298325
guide:
299326
long: |-
300327
Use-case-oriented cheat sheet for ctx.

internal/bootstrap/group.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/ActiveMemory/ctx/internal/cli/doctor"
1919
"github.com/ActiveMemory/ctx/internal/cli/drift"
2020
"github.com/ActiveMemory/ctx/internal/cli/guide"
21+
cliHub "github.com/ActiveMemory/ctx/internal/cli/hub"
2122
"github.com/ActiveMemory/ctx/internal/cli/initialize"
2223
"github.com/ActiveMemory/ctx/internal/cli/journal"
2324
"github.com/ActiveMemory/ctx/internal/cli/learning"
@@ -162,6 +163,7 @@ func utilities() []registration {
162163
// - []registration: Serve, site, and system commands with no group assignment
163164
func hiddenCmds() []registration {
164165
return []registration{
166+
{cliHub.Cmd, ""},
165167
{serve.Cmd, ""},
166168
{site.Cmd, ""},
167169
{system.Cmd, ""},

internal/cli/hub/cmd/peer/cmd.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// / ctx: https://ctx.ist
2+
// ,'`./ do you remember?
3+
// `.,'\
4+
// \ Copyright 2026-present Context contributors.
5+
// SPDX-License-Identifier: Apache-2.0
6+
7+
package peer
8+
9+
import (
10+
"github.com/spf13/cobra"
11+
12+
"github.com/ActiveMemory/ctx/internal/assets/read/desc"
13+
corePeer "github.com/ActiveMemory/ctx/internal/cli/hub/core/peer"
14+
"github.com/ActiveMemory/ctx/internal/config/embed/cmd"
15+
)
16+
17+
// Cmd returns the hub peer subcommand.
18+
//
19+
// Returns:
20+
// - *cobra.Command: The peer subcommand
21+
func Cmd() *cobra.Command {
22+
short, long := desc.Command(cmd.DescKeyHubPeer)
23+
24+
return &cobra.Command{
25+
Use: cmd.UseHubPeer,
26+
Short: short,
27+
Long: long,
28+
Example: desc.Example(cmd.DescKeyHubPeer),
29+
Args: cobra.ExactArgs(2),
30+
RunE: corePeer.Run,
31+
}
32+
}

internal/cli/hub/cmd/peer/doc.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// / ctx: https://ctx.ist
2+
// ,'`./ do you remember?
3+
// `.,'\
4+
// \ Copyright 2026-present Context contributors.
5+
// SPDX-License-Identifier: Apache-2.0
6+
7+
// Package peer provides the cobra command for
8+
// ctx hub peer.
9+
//
10+
// Key exports: [Cmd].
11+
// See source files for implementation details.
12+
// Part of the internal subsystem.
13+
package peer

internal/cli/hub/cmd/status/cmd.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// / ctx: https://ctx.ist
2+
// ,'`./ do you remember?
3+
// `.,'\
4+
// \ Copyright 2026-present Context contributors.
5+
// SPDX-License-Identifier: Apache-2.0
6+
7+
package status
8+
9+
import (
10+
"github.com/spf13/cobra"
11+
12+
"github.com/ActiveMemory/ctx/internal/assets/read/desc"
13+
coreStatus "github.com/ActiveMemory/ctx/internal/cli/hub/core/status"
14+
"github.com/ActiveMemory/ctx/internal/config/embed/cmd"
15+
)
16+
17+
// Cmd returns the hub status subcommand.
18+
//
19+
// Returns:
20+
// - *cobra.Command: The status subcommand
21+
func Cmd() *cobra.Command {
22+
short, long := desc.Command(cmd.DescKeyHubStatus)
23+
24+
return &cobra.Command{
25+
Use: cmd.UseHubStatus,
26+
Short: short,
27+
Long: long,
28+
Example: desc.Example(cmd.DescKeyHubStatus),
29+
Args: cobra.NoArgs,
30+
RunE: coreStatus.Run,
31+
}
32+
}

internal/cli/hub/cmd/status/doc.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// / ctx: https://ctx.ist
2+
// ,'`./ do you remember?
3+
// `.,'\
4+
// \ Copyright 2026-present Context contributors.
5+
// SPDX-License-Identifier: Apache-2.0
6+
7+
// Package status provides the cobra command for
8+
// ctx hub status.
9+
//
10+
// Key exports: [Cmd].
11+
// See source files for implementation details.
12+
// Part of the internal subsystem.
13+
package status
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// / ctx: https://ctx.ist
2+
// ,'`./ do you remember?
3+
// `.,'\
4+
// \ Copyright 2026-present Context contributors.
5+
// SPDX-License-Identifier: Apache-2.0
6+
7+
package stepdown
8+
9+
import (
10+
"github.com/spf13/cobra"
11+
12+
"github.com/ActiveMemory/ctx/internal/assets/read/desc"
13+
coreStep "github.com/ActiveMemory/ctx/internal/cli/hub/core/stepdown"
14+
"github.com/ActiveMemory/ctx/internal/config/embed/cmd"
15+
)
16+
17+
// Cmd returns the hub stepdown subcommand.
18+
//
19+
// Returns:
20+
// - *cobra.Command: The stepdown subcommand
21+
func Cmd() *cobra.Command {
22+
short, long := desc.Command(cmd.DescKeyHubStepdown)
23+
24+
return &cobra.Command{
25+
Use: cmd.UseHubStepdown,
26+
Short: short,
27+
Long: long,
28+
Example: desc.Example(cmd.DescKeyHubStepdown),
29+
Args: cobra.NoArgs,
30+
RunE: coreStep.Run,
31+
}
32+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// / ctx: https://ctx.ist
2+
// ,'`./ do you remember?
3+
// `.,'\
4+
// \ Copyright 2026-present Context contributors.
5+
// SPDX-License-Identifier: Apache-2.0
6+
7+
// Package stepdown provides the cobra command for
8+
// ctx hub stepdown.
9+
//
10+
// Key exports: [Cmd].
11+
// See source files for implementation details.
12+
// Part of the internal subsystem.
13+
package stepdown

internal/cli/hub/core/peer/doc.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// / ctx: https://ctx.ist
2+
// ,'`./ do you remember?
3+
// `.,'\
4+
// \ Copyright 2026-present Context contributors.
5+
// SPDX-License-Identifier: Apache-2.0
6+
7+
// Package peer implements runtime peer add/remove for
8+
// ctx hub peer.
9+
//
10+
// Key exports: [Run].
11+
// See source files for implementation details.
12+
// Part of the internal subsystem.
13+
package peer

internal/cli/hub/core/peer/peer.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// / ctx: https://ctx.ist
2+
// ,'`./ do you remember?
3+
// `.,'\
4+
// \ Copyright 2026-present Context contributors.
5+
// SPDX-License-Identifier: Apache-2.0
6+
7+
package peer
8+
9+
import (
10+
"github.com/spf13/cobra"
11+
12+
errHub "github.com/ActiveMemory/ctx/internal/err/hub"
13+
writeHub "github.com/ActiveMemory/ctx/internal/write/hub"
14+
)
15+
16+
// Run handles peer add/remove subcommands.
17+
//
18+
// Parameters:
19+
// - cmd: cobra command for output
20+
// - args: [action, address] where action is add or remove
21+
//
22+
// Returns:
23+
// - error: non-nil if action is invalid
24+
func Run(cmd *cobra.Command, args []string) error {
25+
action := args[0]
26+
addr := args[1]
27+
28+
switch action {
29+
case "add":
30+
writeHub.PeerAdded(cmd, addr)
31+
case "remove":
32+
writeHub.PeerRemoved(cmd, addr)
33+
default:
34+
return errHub.InvalidPeerAction(action)
35+
}
36+
return nil
37+
}

0 commit comments

Comments
 (0)