add API viewer, mv repl subcommand to api (#41)

This commit is contained in:
T. von Dein
2026-06-17 13:11:09 +02:00
parent 072e949147
commit f1ff361c12
14 changed files with 161829 additions and 267 deletions

90
cmd/api.go Normal file
View File

@@ -0,0 +1,90 @@
/*
Copyright © 2026 Thomas von Dein
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cmd
import (
"context"
"codeberg.org/scip/esctl/pkg/cfg"
"codeberg.org/scip/esctl/pkg/es"
"github.com/urfave/cli/v3"
)
func Api(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "api",
Usage: "manage apiuments",
Commands: []*cli.Command{
ApiList(conf),
ApiShow(conf),
ApiRepl(conf),
},
}
}
func ApiList(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "list index of API calls",
UsageText: "list [<pattern>]",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tag",
Usage: "list only operations matching <tag>",
Destination: &conf.Tag,
Aliases: []string{"t"},
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
return es.ApiList(conf, cmd.Args().Get(0))
},
}
}
func ApiShow(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "show",
Aliases: []string{"sh"},
Usage: "show an API doc",
UsageText: "show <pattern> [<verb>]",
Action: func(ctx context.Context, cmd *cli.Command) error {
return es.ApiShow(conf, cmd.Args().Get(0), cmd.Args().Get(1))
},
ShellComplete: func(ctx context.Context, cmd *cli.Command) {
complete(cmd, Capi)
},
}
}
func ApiRepl(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "repl",
Aliases: []string{"shell"},
Usage: "interactive API repl",
Action: func(ctx context.Context, cmd *cli.Command) error {
return es.ApiRepl(conf)
},
}
}

View File

@@ -30,6 +30,7 @@ const (
Cdatastream
Crole
Ccluster
Capi
)
func complete(cmd *cli.Command, what int) {
@@ -58,6 +59,8 @@ func complete(cmd *cli.Command, what int) {
}
case Cdatastream:
list, err = es.DatastreamNames(conf)
case Capi:
list = es.ApiPathNames()
}
if err != nil {

View File

@@ -15,24 +15,3 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package cmd
import (
"context"
"codeberg.org/scip/esctl/pkg/cfg"
"codeberg.org/scip/esctl/pkg/es"
"github.com/urfave/cli/v3"
)
func Repl(conf *cfg.Config) *cli.Command {
return &cli.Command{
Name: "repl",
Aliases: []string{"shell"},
Usage: "interactive API repl",
Action: func(ctx context.Context, cmd *cli.Command) error {
return es.Repl(conf)
},
}
}

View File

@@ -95,12 +95,12 @@ func Main() int {
Snapshot(conf),
Node(conf),
Doc(conf),
Repl(conf),
Version(conf),
Debug(conf),
Roles(conf),
Task(conf),
HelpJsonPath(conf),
Api(conf),
},
Before: func(ctx context.Context, cmd *cli.Command) (context.Context, error) {