Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell .help built-in command #245

Merged
merged 1 commit into from
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions internal/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ func (s *Shell) Process(ctx context.Context, line string) (string, error) {
return s.processCluster(ctx, line)
case ".leader":
return s.processLeader(ctx, line)
case ".help":
return s.processHelp(), nil
}
if strings.HasPrefix(strings.ToLower(strings.TrimLeft(line, " ")), ".remove") {
return s.processRemove(ctx, line)
Expand All @@ -92,6 +94,21 @@ func (s *Shell) Process(ctx context.Context, line string) (string, error) {
}
}

func (s *Shell) processHelp() string {
return `
Dqlite shell is a simple interactive prompt for inspecting a dqlite database.
Enter a SQL statement to execute it, or one of the following built-in commands:

.cluster Show the cluster membership
.leader Show the current leader
.remove <address> Remove a node from the cluster
.describe <address> Show the details of a node
.weight <address> <weight> Set the weight of a node
.dump <address> [<database>] Dump the database
.reconfigure <dir> <clusteryaml> Reconfigure the cluster
`[1:]
}

func (s *Shell) processCluster(ctx context.Context, line string) (string, error) {
cli, err := client.FindLeader(ctx, s.store, client.WithDialFunc(s.dial))
if err != nil {
Expand Down