46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
package app
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
// ArtifactsList lists effective artifact sources.
|
|
func ArtifactsList(ctx context.Context, args []string, out io.Writer) error {
|
|
fs := flag.NewFlagSet("artifacts list", flag.ContinueOnError)
|
|
fs.SetOutput(io.Discard)
|
|
var flags commonConfigFlags
|
|
var remote bool
|
|
addCommonConfigFlags(fs, &flags)
|
|
fs.BoolVar(&remote, "remote", false, "inspect remote publish availability")
|
|
if err := parseSessionAwareFlags("artifacts list", fs, args, &flags.sessionID); err != nil {
|
|
return err
|
|
}
|
|
if strings.TrimSpace(flags.sessionID) == "" {
|
|
return fmt.Errorf("artifacts list: session_id is required")
|
|
}
|
|
cfg, store, locks, m, cleanup, err := loadHelperContext(ctx, flags, remote)
|
|
if err != nil {
|
|
return fmt.Errorf("artifacts list: %w", err)
|
|
}
|
|
defer cleanup()
|
|
catalog, err := buildHelperArtifactCatalog(cfg, m)
|
|
if err != nil {
|
|
return fmt.Errorf("artifacts list: %w", err)
|
|
}
|
|
publishedRemoteState := map[string]string{}
|
|
if remote && store != nil {
|
|
current := inspectRemoteCurrentState(ctx, cfg, store)
|
|
if current.Err != nil {
|
|
publishedRemoteState = unresolvedRemotePublishedOutputAvailability(cfg, catalog, "remote=error")
|
|
} else {
|
|
publishedRemoteState = remotePublishedOutputAvailabilityForCurrent(ctx, cfg, store, catalog, current.State)
|
|
}
|
|
}
|
|
writeArtifactList(out, cfg, catalog, locks, publishedRemoteState)
|
|
return nil
|
|
}
|