Finish native completion and retire legacy command machinery
This commit is contained in:
@@ -1,83 +1,14 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||
"gitea.maximumdirect.net/eric/narratio/internal/stage"
|
||||
"go.maximumdirect.net/commandkit"
|
||||
)
|
||||
|
||||
// Plan validates configuration and prints a read-only execution preview.
|
||||
func Plan(ctx context.Context, args []string, out io.Writer) error {
|
||||
return planWithDependencies(ctx, args, out, commandDependencies{})
|
||||
}
|
||||
|
||||
func planWithDependencies(ctx context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
||||
deps = normalizeCommandDependencies(deps)
|
||||
request, err := parseBoundedRunRequest("plan", args, out)
|
||||
if err != nil {
|
||||
if errors.Is(err, flag.ErrHelp) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
flags := request.Config
|
||||
loaded, err := loadCommandConfigWithDependencies(ctx, flags.pipelinePath, flags.campaignPath, flags.campaignFilePath, flags.sessionPath, flags.sessionOptions(), flags.secretsDir.pointer(), deps)
|
||||
if err != nil {
|
||||
return fmt.Errorf("plan: %w", err)
|
||||
}
|
||||
defer func() { _ = loaded.Close() }()
|
||||
cfg := loaded.Config
|
||||
if err := config.Validate(cfg); err != nil {
|
||||
return fmt.Errorf("plan: %w", err)
|
||||
}
|
||||
selectedArtifacts, err := normalizeArtifactSelection(cfg, request.SelectedArtifacts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("plan: %w", err)
|
||||
}
|
||||
effective, err := resolveEffectiveArtifacts(cfg, selectedArtifacts)
|
||||
if err != nil {
|
||||
return fmt.Errorf("plan: %w", err)
|
||||
}
|
||||
input := &executionInput{plan: request.Plan, Force: commandkit.Supplied[bool]{Value: request.Force}}
|
||||
report, err := buildSessionPlan(ctx, cfg, input, selectedArtifacts, effective)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
paths := artifacts.NewLocalStore(cfg.Pipeline.Workspace.Root).SessionPathsFor(cfg.Session.Campaign, cfg.Session.SessionID)
|
||||
if _, err := fmt.Fprintf(out, "narratio session plan: read-only workdir at %s; %s\n", paths.Root, effectiveConfigSummary(cfg)); err != nil {
|
||||
return err
|
||||
}
|
||||
runCount, skipCount := 0, 0
|
||||
for _, entry := range report.Stages {
|
||||
if entry.Action == string(stageActionRun) {
|
||||
runCount++
|
||||
} else {
|
||||
skipCount++
|
||||
}
|
||||
if _, err := fmt.Fprintf(out, "%s: %s\n", entry.Name, entry.Action); err != nil {
|
||||
return err
|
||||
}
|
||||
if entry.Analysis != nil {
|
||||
if err := writeAnalyzePlanDetails(out, entry.Analysis); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
_, err = fmt.Fprintf(out, "totals: run=%d skip=%d\n", runCount, skipCount)
|
||||
return err
|
||||
}
|
||||
|
||||
func cloneManifestForPlan(source *manifest.Manifest, cfg *config.Config) (*manifest.Manifest, error) {
|
||||
if source == nil {
|
||||
created := manifest.New(cfg.Session.SessionID, time.Now().UTC())
|
||||
@@ -125,49 +56,3 @@ func plannedSelfSkipReason(stageName string, cfg *config.Config) string {
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func writeAnalyzePlanDetails(out io.Writer, summary *plannedAnalysis) error {
|
||||
if summary == nil {
|
||||
return nil
|
||||
}
|
||||
if _, err := fmt.Fprintf(out, " targets: %s\n", planStringList(summary.Targets)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprintf(out, " prerequisites: %s\n", planArtifactList(summary.Prerequisites)); err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := fmt.Fprintf(out, " execute: %s\n", planArtifactList(summary.Execute)); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := fmt.Fprintf(out, " reuse: %s\n", planArtifactList(summary.Reuse))
|
||||
return err
|
||||
}
|
||||
|
||||
func planStringList(values []string) string {
|
||||
if len(values) == 0 {
|
||||
return "none"
|
||||
}
|
||||
return strings.Join(values, ", ")
|
||||
}
|
||||
|
||||
func planArtifactList(values []plannedArtifact) string {
|
||||
if len(values) == 0 {
|
||||
return "none"
|
||||
}
|
||||
parts := make([]string, 0, len(values))
|
||||
for _, value := range values {
|
||||
detail := value.Role
|
||||
if value.Reason != "" {
|
||||
detail += ":" + value.Reason
|
||||
}
|
||||
if value.Forced {
|
||||
detail += ":forced"
|
||||
}
|
||||
identity := value.Key
|
||||
if value.Family != "" {
|
||||
identity += fmt.Sprintf("[family=%s character_id=%s]", value.Family, value.CharacterID)
|
||||
}
|
||||
parts = append(parts, fmt.Sprintf("%s(%s)", identity, detail))
|
||||
}
|
||||
return strings.Join(parts, ", ")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user