package cmd import ( "context" "flag" "io" "code.icb4dc0.de/buildr/buildr/internal/config" "code.icb4dc0.de/buildr/buildr/internal/rpc" "code.icb4dc0.de/buildr/buildr/modules" "github.com/spf13/cobra" ) type InitLevel int const ( InitLevelNone InitLevel = iota InitLevelBasic InitLevelBuildRConfig InitLevelParseConfig ) const ( defaultPasswordLength = 32 ) type LevelInitializer interface { InitAt(ctx context.Context, lvl InitLevel) error } type VaultInitConfig struct { PassphraseLength uint `mapstructure:"vault-pw-length"` } func (c *VaultInitConfig) Flags() *flag.FlagSet { fs := flag.NewFlagSet("vault-init", flag.ExitOnError) fs.UintVar( &c.PassphraseLength, "vault.pw-length", defaultPasswordLength, "Length of the passphrase to generate", ) return fs } type BuildrConfigAccessor interface { BuildrConfig() config.Buildr } type AppConfigAccessor interface { AppConfig() AppConfig } type TypeRegistryAccessor interface { TypeRegistry() *modules.TypeRegistry } type ModuleRepositoryAccessor interface { Repository() *modules.Repository } type VaultCommander interface { Init(ctx context.Context, cfg VaultInitConfig) error List(ctx context.Context, writer io.Writer) error Get(ctx context.Context, key string, writer io.Writer) error Set(ctx context.Context, key string, value []byte) error Remove(ctx context.Context, key string) error } type PluginCommander interface { ListPlugins(ctx context.Context, writer io.Writer) error UpdatePlugins(ctx context.Context) error } type ServerCommander interface { ServeAPI(ctx context.Context, cfg *rpc.GrpcConfig) error } type ModuleCommander interface { RunModule(ctx context.Context, cat modules.Category, name string) error } type BootstrapModuleCommander interface { BootstrapModule(ctx context.Context, cat modules.Category, typeName, moduleName string) error } type KnownTasksArgProvider interface { ValidTasksArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) } type KnownModulesArgProvider interface { ValidModulesArgs(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) } type ManCommander interface { DisplayModuleManual(ctx context.Context, pager Pager, cat modules.Category, name string) error DisplayModulesManual(pager Pager) error } type KnownTasksArgProviderFunc func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) func (f KnownTasksArgProviderFunc) ValidTasksArgs( cmd *cobra.Command, args []string, toComplete string, ) ([]string, cobra.ShellCompDirective) { return f(cmd, args, toComplete) } type KnownModulesArgProviderFunc func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) func (f KnownModulesArgProviderFunc) ValidModulesArgs( cmd *cobra.Command, args []string, toComplete string, ) ([]string, cobra.ShellCompDirective) { return f(cmd, args, toComplete) } type AppInitializer interface { Init(ctx context.Context) error } type AppInitializerFunc func(ctx context.Context) error func (f AppInitializerFunc) Init(ctx context.Context) error { return f(ctx) } type EnvCommander interface { PrintPath(ctx context.Context, writer io.Writer) error }