cmd

package
v0.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package cmd is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var RootCmd = &cobra.Command{
	Use:   "scrt",
	Short: "A secret manager for the command-line",
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {

		if cmd == storageCmd {
			return nil
		}

		err := readConfig(cmd)
		if err != nil {
			return err
		}

		if verbose {
			logger = &log.Logger{Handler: cli.Default}
		} else {
			logger = &log.Logger{Handler: discard.Default}
		}
		cmdContext = log.NewContext(
			cmdContext,
			logger,
		)

		if !viper.IsSet(configKeyStorage) {
			for k := range backend.Backends {
				if viper.InConfig(k) {
					viper.Set(configKeyStorage, k)
					break
				}
			}
			if !viper.IsSet(configKeyStorage) {
				return fmt.Errorf("missing storage type")
			}
		}
		if !viper.IsSet(configKeyPassword) {
			return fmt.Errorf("missing password")
		}

		storage := viper.GetString(configKeyStorage)
		factory, ok := backend.Backends[storage]
		if !ok {
			return fmt.Errorf("unknown storage type: %s", storage)
		}

		cmd.FParseErrWhitelist.UnknownFlags = false
		cmd.Flags().AddFlagSet(factory.Flags())
		err = viper.BindPFlags(cmd.Flags())
		if err != nil {
			return err
		}
		err = cmd.ParseFlags(os.Args[1:])
		if err != nil {
			return cmd.FlagErrorFunc()(cmd, err)
		}

		if viper.ConfigFileUsed() != "" {
			logger.
				WithField("path", viper.ConfigFileUsed()).
				Infof("read configuration file")
		}
		settings := make(map[string]interface{})
		for k, v := range viper.AllSettings() {

			if k != configKeyPassword && !reflect.ValueOf(v).IsZero() {
				settings[k] = v
			}
		}
		logger.
			WithFields(fielder{fields: settings}).
			Info("using configuration")

		cmd.SilenceUsage = true

		return nil
	},
}

RootCmd is the root command for scrt.

Functions

This section is empty.

Types

type MockBackend

type MockBackend struct {
	// contains filtered or unexported fields
}

MockBackend is a mock of Backend interface.

func NewMockBackend

func NewMockBackend(ctrl *gomock.Controller) *MockBackend

NewMockBackend creates a new mock instance.

func (*MockBackend) EXPECT

func (m *MockBackend) EXPECT() *MockBackendMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockBackend) Exists

func (m *MockBackend) Exists() (bool, error)

Exists mocks base method.

func (*MockBackend) ExistsContext added in v0.3.3

func (m *MockBackend) ExistsContext(arg0 context.Context) (bool, error)

ExistsContext mocks base method.

func (*MockBackend) Load

func (m *MockBackend) Load() ([]byte, error)

Load mocks base method.

func (*MockBackend) LoadContext added in v0.3.3

func (m *MockBackend) LoadContext(arg0 context.Context) ([]byte, error)

LoadContext mocks base method.

func (*MockBackend) Save

func (m *MockBackend) Save(arg0 []byte) error

Save mocks base method.

func (*MockBackend) SaveContext added in v0.3.3

func (m *MockBackend) SaveContext(arg0 context.Context, arg1 []byte) error

SaveContext mocks base method.

type MockBackendMockRecorder

type MockBackendMockRecorder struct {
	// contains filtered or unexported fields
}

MockBackendMockRecorder is the mock recorder for MockBackend.

func (*MockBackendMockRecorder) Exists

func (mr *MockBackendMockRecorder) Exists() *gomock.Call

Exists indicates an expected call of Exists.

func (*MockBackendMockRecorder) ExistsContext added in v0.3.3

func (mr *MockBackendMockRecorder) ExistsContext(arg0 interface{}) *gomock.Call

ExistsContext indicates an expected call of ExistsContext.

func (*MockBackendMockRecorder) Load

func (mr *MockBackendMockRecorder) Load() *gomock.Call

Load indicates an expected call of Load.

func (*MockBackendMockRecorder) LoadContext added in v0.3.3

func (mr *MockBackendMockRecorder) LoadContext(arg0 interface{}) *gomock.Call

LoadContext indicates an expected call of LoadContext.

func (*MockBackendMockRecorder) Save

func (mr *MockBackendMockRecorder) Save(arg0 interface{}) *gomock.Call

Save indicates an expected call of Save.

func (*MockBackendMockRecorder) SaveContext added in v0.3.3

func (mr *MockBackendMockRecorder) SaveContext(arg0, arg1 interface{}) *gomock.Call

SaveContext indicates an expected call of SaveContext.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL