Carry dependencies through operator commands
This commit is contained in:
@@ -47,20 +47,19 @@ func (f commonConfigFlags) sessionOptions() config.SessionLoadOptions {
|
||||
|
||||
// Session dispatches session helper subcommands.
|
||||
func Session(ctx context.Context, args []string, out io.Writer) error {
|
||||
return sessionWithDependencies(ctx, args, out, commandDependencies{
|
||||
newObjectStore: newObjectStoreFromConfigFn,
|
||||
})
|
||||
return sessionWithDependencies(ctx, args, out, commandDependencies{})
|
||||
}
|
||||
|
||||
func sessionWithDependencies(ctx context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
||||
deps = normalizeCommandDependencies(deps)
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("session: expected subcommand: init|validate|status|plan|restore|artifacts|locks")
|
||||
}
|
||||
switch args[0] {
|
||||
case "init":
|
||||
return SessionInit(ctx, args[1:], out)
|
||||
return sessionInitWithDependencies(ctx, args[1:], out, deps)
|
||||
case "validate":
|
||||
return SessionValidate(ctx, args[1:], out)
|
||||
return sessionValidateWithDependencies(ctx, args[1:], out, deps)
|
||||
case "status":
|
||||
return statusWithDependencies(ctx, args[1:], out, deps)
|
||||
case "plan":
|
||||
@@ -68,9 +67,9 @@ func sessionWithDependencies(ctx context.Context, args []string, out io.Writer,
|
||||
case "restore":
|
||||
return Restore(ctx, args[1:], out)
|
||||
case "artifacts":
|
||||
return ArtifactsList(ctx, args[1:], out)
|
||||
return artifactsListWithDependencies(ctx, args[1:], out, deps)
|
||||
case "locks":
|
||||
return SessionLocks(ctx, args[1:], out)
|
||||
return sessionLocksWithDependencies(ctx, args[1:], out, deps)
|
||||
default:
|
||||
return fmt.Errorf("session: unknown subcommand %q", args[0])
|
||||
}
|
||||
@@ -79,32 +78,45 @@ func sessionWithDependencies(ctx context.Context, args []string, out io.Writer,
|
||||
// SessionLocks dispatches session-oriented publish lock list and mutation
|
||||
// helpers.
|
||||
func SessionLocks(ctx context.Context, args []string, out io.Writer) error {
|
||||
return sessionLocksWithDependencies(ctx, args, out, commandDependencies{})
|
||||
}
|
||||
|
||||
func sessionLocksWithDependencies(ctx context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
||||
if len(args) > 0 && !isCLIFlagToken(args[0]) {
|
||||
switch args[0] {
|
||||
case "add":
|
||||
return LocksAdd(ctx, args[1:], out)
|
||||
return locksAddWithDependencies(ctx, args[1:], out, deps)
|
||||
case "remove":
|
||||
return LocksRemove(ctx, args[1:], out)
|
||||
return locksRemoveWithDependencies(ctx, args[1:], out, deps)
|
||||
}
|
||||
}
|
||||
return LocksList(ctx, args, out)
|
||||
return locksListWithDependencies(ctx, args, out, deps)
|
||||
}
|
||||
|
||||
// Artifacts dispatches artifact helper subcommands.
|
||||
func Artifacts(ctx context.Context, args []string, out io.Writer) error {
|
||||
return artifactsWithDependencies(ctx, args, out, commandDependencies{})
|
||||
}
|
||||
|
||||
func artifactsWithDependencies(ctx context.Context, args []string, out io.Writer, deps commandDependencies) error {
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("artifacts: expected subcommand: list")
|
||||
}
|
||||
switch args[0] {
|
||||
case "list":
|
||||
return ArtifactsList(ctx, args[1:], out)
|
||||
return artifactsListWithDependencies(ctx, args[1:], out, deps)
|
||||
default:
|
||||
return fmt.Errorf("artifacts: unknown subcommand %q", args[0])
|
||||
}
|
||||
}
|
||||
|
||||
func loadHelperContext(ctx context.Context, flags commonConfigFlags, needStore bool) (*config.Config, storage.ObjectStore, []artifacts.RemoteLock, *manifest.Manifest, func(), error) {
|
||||
loaded, err := loadCommandConfig(ctx, flags.pipelinePath, flags.campaignPath, flags.campaignFilePath, flags.sessionPath, flags.sessionOptions())
|
||||
return loadHelperContextWithDependencies(ctx, flags, needStore, commandDependencies{})
|
||||
}
|
||||
|
||||
func loadHelperContextWithDependencies(ctx context.Context, flags commonConfigFlags, needStore bool, deps commandDependencies) (*config.Config, storage.ObjectStore, []artifacts.RemoteLock, *manifest.Manifest, func(), error) {
|
||||
deps = normalizeCommandDependencies(deps)
|
||||
loaded, err := loadCommandConfigWithDependencies(ctx, flags.pipelinePath, flags.campaignPath, flags.campaignFilePath, flags.sessionPath, flags.sessionOptions(), deps)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, err
|
||||
}
|
||||
@@ -120,12 +132,12 @@ func loadHelperContext(ctx context.Context, flags commonConfigFlags, needStore b
|
||||
}
|
||||
var store storage.ObjectStore
|
||||
if needStore {
|
||||
store, err = newCommandObjectStore(ctx, cfg, nil)
|
||||
store, err = newCommandObjectStoreWithDependencies(ctx, cfg, nil, deps)
|
||||
if err != nil {
|
||||
return nil, nil, nil, nil, nil, err
|
||||
}
|
||||
} else {
|
||||
store, _ = objectStoreIfConfigured(ctx, cfg)
|
||||
store, _ = objectStoreIfConfiguredWithDependencies(ctx, cfg, deps)
|
||||
}
|
||||
var locks []artifacts.RemoteLock
|
||||
if store != nil {
|
||||
@@ -148,9 +160,7 @@ func loadHelperContext(ctx context.Context, flags commonConfigFlags, needStore b
|
||||
}
|
||||
|
||||
func objectStoreIfConfigured(ctx context.Context, cfg *config.Config) (storage.ObjectStore, error) {
|
||||
return objectStoreIfConfiguredWithDependencies(ctx, cfg, commandDependencies{
|
||||
newObjectStore: newObjectStoreFromConfigFn,
|
||||
})
|
||||
return objectStoreIfConfiguredWithDependencies(ctx, cfg, commandDependencies{})
|
||||
}
|
||||
|
||||
func objectStoreIfConfiguredWithDependencies(ctx context.Context, cfg *config.Config, deps commandDependencies) (storage.ObjectStore, error) {
|
||||
|
||||
Reference in New Issue
Block a user