65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
|
|
"gitea.maximumdirect.net/eric/distributor/internal/app"
|
|
)
|
|
|
|
func inspectCommand(ctx context.Context, args []string, stdout, stderr io.Writer) int {
|
|
if hasHelp(args) {
|
|
printInspectHelp(stdout)
|
|
return exitOK
|
|
}
|
|
flags := flag.NewFlagSet("inspect", flag.ContinueOnError)
|
|
flags.SetOutput(stderr)
|
|
configPath := flags.String("config", "", "path to config file")
|
|
pipelineID := flags.String("pipeline", "", "pipeline id")
|
|
bundlePath := flags.String("bundle", "", "source-root-relative bundle path")
|
|
formatFlag := addFormatFlag(flags)
|
|
if err := flags.Parse(args); err != nil {
|
|
return exitUsage
|
|
}
|
|
format, ok := parseOutputFormat(stderr, "inspect", *formatFlag)
|
|
if !ok {
|
|
return exitUsage
|
|
}
|
|
path, ok := parseOptionalPathArg(stderr, "inspect", flags.Args())
|
|
if !ok {
|
|
return exitUsage
|
|
}
|
|
if !validateInspectModeOK(stderr, "inspect", path, *configPath, *pipelineID, *bundlePath) {
|
|
return exitUsage
|
|
}
|
|
if err := app.Inspect(ctx, app.InspectOptions{
|
|
Path: path,
|
|
ConfigPath: *configPath,
|
|
PipelineID: *pipelineID,
|
|
BundlePath: *bundlePath,
|
|
Stdout: stdout,
|
|
OutputFormat: format,
|
|
}); err != nil {
|
|
return fail(stderr, err)
|
|
}
|
|
return exitOK
|
|
}
|
|
|
|
func printInspectHelp(w io.Writer) {
|
|
fmt.Fprint(w, `Usage:
|
|
distributor inspect [--format text|json] <path>
|
|
distributor inspect --config <path> --pipeline <id> [--bundle <path>] [--format text|json]
|
|
|
|
Options:
|
|
--config <path> Path to config file for configured source inspection
|
|
--pipeline <id> Pipeline id to inspect in config mode
|
|
--bundle <path> Source-root-relative bundle path to inspect
|
|
--format text|json Output format
|
|
|
|
Print a normalized summary of local source bundles or a configured pipeline
|
|
source.
|
|
`)
|
|
}
|