Files
esctl/cmd/api.go

101 lines
2.4 KiB
Go
Raw Normal View History

/*
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",
2026-06-23 14:02:40 +02:00
Usage: "api access and documentation",
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",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "pager",
Usage: "external viewer program (default:internal)",
Destination: &conf.Pager,
Aliases: []string{"p"},
Sources: cli.EnvVars("PAGER", "ES_JSON_PAGER"),
},
},
Action: func(ctx context.Context, cmd *cli.Command) error {
return es.ApiRepl(conf)
},
}
}