Add preflight command and run alias
This commit is contained in:
@@ -25,37 +25,11 @@ type processResult struct {
|
||||
func runProcess(inv commandkit.Invocation, input processInput) commandkit.Outcome {
|
||||
loaded, err := loadProcessInputs(inv.Context, input, inv.ReportingMode())
|
||||
if err != nil {
|
||||
if canceled := inv.Context.Err(); canceled != nil && !errors.Is(err, canceled) {
|
||||
err = errors.Join(err, canceled)
|
||||
}
|
||||
var loadErr *ck.LoadError
|
||||
if errors.As(err, &loadErr) {
|
||||
_, explanation := ckconfig.AdaptDiagnostics("Application configuration:\n", loadErr.Sources(), loadErr.Diagnostics())
|
||||
if inv.Context.Err() == nil && ckconfig.ClassifyConfigurationError(err) == commandkit.OutcomeUsage {
|
||||
return commandkit.Usage(loadErr.Error(), explanation.Details...).WithCause(err)
|
||||
}
|
||||
return commandkit.Failure(loadErr.Error(), explanation.Details...).WithCause(err)
|
||||
}
|
||||
var secretsErr *bootstrapError
|
||||
if errors.As(err, &secretsErr) {
|
||||
return commandkit.Failure(secretsErr.Error()).WithCause(err)
|
||||
}
|
||||
var runtimeErr *runtimePreparationError
|
||||
if errors.As(err, &runtimeErr) {
|
||||
return commandkit.Failure(err.Error()).WithCause(err)
|
||||
}
|
||||
if inv.Context.Err() != nil || appconfig.IsAssetError(err) {
|
||||
return commandkit.Failure("Could not prepare processing.").WithCause(err)
|
||||
}
|
||||
return commandkit.Usage(err.Error()).WithCause(err)
|
||||
return acquisitionOutcome(inv, err)
|
||||
}
|
||||
prepared, err := prepareProcess(inv.Context, input, loaded, inv.Reporter().Output())
|
||||
if err != nil {
|
||||
var selection *preflight.SelectionError
|
||||
if inv.Context.Err() == nil && errors.As(err, &selection) {
|
||||
return commandkit.Usage(err.Error()).WithCause(err)
|
||||
}
|
||||
return commandkit.Failure(err.Error()).WithCause(err)
|
||||
return preparationOutcome(inv, err)
|
||||
}
|
||||
defer prepared.Prepared.Output.Close()
|
||||
var warningsMu sync.Mutex
|
||||
@@ -110,3 +84,37 @@ func (p *preparedProcess) DebugPath() string {
|
||||
}
|
||||
return p.Prepared.Debug.Path()
|
||||
}
|
||||
|
||||
func acquisitionOutcome(inv commandkit.Invocation, err error) commandkit.Outcome {
|
||||
if canceled := inv.Context.Err(); canceled != nil && !errors.Is(err, canceled) {
|
||||
err = errors.Join(err, canceled)
|
||||
}
|
||||
var loadErr *ck.LoadError
|
||||
if errors.As(err, &loadErr) {
|
||||
_, explanation := ckconfig.AdaptDiagnostics("Application configuration:\n", loadErr.Sources(), loadErr.Diagnostics())
|
||||
if inv.Context.Err() == nil && ckconfig.ClassifyConfigurationError(err) == commandkit.OutcomeUsage {
|
||||
return commandkit.Usage(loadErr.Error(), explanation.Details...).WithCause(err)
|
||||
}
|
||||
return commandkit.Failure(loadErr.Error(), explanation.Details...).WithCause(err)
|
||||
}
|
||||
var secretsErr *bootstrapError
|
||||
if errors.As(err, &secretsErr) {
|
||||
return commandkit.Failure(secretsErr.Error()).WithCause(err)
|
||||
}
|
||||
var runtimeErr *runtimePreparationError
|
||||
if errors.As(err, &runtimeErr) {
|
||||
return commandkit.Failure(err.Error()).WithCause(err)
|
||||
}
|
||||
if inv.Context.Err() != nil || appconfig.IsAssetError(err) {
|
||||
return commandkit.Failure("Could not prepare processing.").WithCause(err)
|
||||
}
|
||||
return commandkit.Usage(err.Error()).WithCause(err)
|
||||
}
|
||||
|
||||
func preparationOutcome(inv commandkit.Invocation, err error) commandkit.Outcome {
|
||||
var selection *preflight.SelectionError
|
||||
if inv.Context.Err() == nil && errors.As(err, &selection) {
|
||||
return commandkit.Usage(err.Error()).WithCause(err)
|
||||
}
|
||||
return commandkit.Failure(err.Error()).WithCause(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user