actions.go 3.45 KB
Newer Older
bryanl's avatar
bryanl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// Copyright 2018 The ksonnet authors
//
//
//    Licensed under the Apache License, Version 2.0 (the "License");
//    you may not use this file except in compliance with the License.
//    You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
//    Unless required by applicable law or agreed to in writing, software
//    distributed under the License is distributed on an "AS IS" BASIS,
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//    See the License for the specific language governing permissions and
//    limitations under the License.

bryanl's avatar
bryanl committed
16
package clicmd
bryanl's avatar
bryanl committed
17

bryanl's avatar
bryanl committed
18
import (
bryanl's avatar
bryanl committed
19
	"github.com/ksonnet/ksonnet/pkg/actions"
bryanl's avatar
bryanl committed
20 21
	"github.com/pkg/errors"
)
bryanl's avatar
bryanl committed
22 23 24 25

type initName int

const (
bryanl's avatar
bryanl committed
26
	actionApply initName = iota
bryanl's avatar
bryanl committed
27
	actionComponentList
bryanl's avatar
bryanl committed
28
	actionComponentRm
bryanl's avatar
bryanl committed
29 30 31
	actionDelete
	actionDiff
	actionEnvAdd
bryanl's avatar
bryanl committed
32
	actionEnvCurrent
bryanl's avatar
bryanl committed
33 34 35 36 37
	actionEnvDescribe
	actionEnvList
	actionEnvRm
	actionEnvSet
	actionEnvTargets
bryanl's avatar
bryanl committed
38
	actionEnvUpdate
bryanl's avatar
bryanl committed
39
	actionImport
bryanl's avatar
bryanl committed
40
	actionInit
41 42
	actionModuleCreate
	actionModuleList
bryanl's avatar
bryanl committed
43
	actionParamDelete
bryanl's avatar
bryanl committed
44 45 46
	actionParamDiff
	actionParamList
	actionParamSet
bryanl's avatar
bryanl committed
47
	actionParamUnset
bryanl's avatar
bryanl committed
48 49 50 51 52 53 54 55 56 57 58
	actionPkgDescribe
	actionPkgInstall
	actionPkgList
	actionPrototypeDescribe
	actionPrototypeList
	actionPrototypePreview
	actionPrototypeSearch
	actionPrototypeUse
	actionRegistryAdd
	actionRegistryDescribe
	actionRegistryList
59
	actionRegistryUpdate
bryanl's avatar
bryanl committed
60 61
	actionShow
	actionUpgrade
bryanl's avatar
bryanl committed
62
	actionValidate
bryanl's avatar
bryanl committed
63 64
)

bryanl's avatar
bryanl committed
65 66 67 68
type actionFn func(map[string]interface{}) error

var (
	actionFns = map[initName]actionFn{
bryanl's avatar
bryanl committed
69 70 71 72 73
		actionApply:             actions.RunApply,
		actionComponentList:     actions.RunComponentList,
		actionComponentRm:       actions.RunComponentRm,
		actionDelete:            actions.RunDelete,
		actionDiff:              actions.RunDiff,
74 75 76 77 78 79 80
		actionEnvAdd:            actions.RunEnvAdd,
		actionEnvCurrent:        actions.RunEnvCurrent,
		actionEnvDescribe:       actions.RunEnvDescribe,
		actionEnvList:           actions.RunEnvList,
		actionEnvRm:             actions.RunEnvRm,
		actionEnvSet:            actions.RunEnvSet,
		actionEnvTargets:        actions.RunEnvTargets,
bryanl's avatar
bryanl committed
81
		actionEnvUpdate:         actions.RunEnvUpdate,
82 83 84 85 86
		actionImport:            actions.RunImport,
		actionInit:              actions.RunInit,
		actionModuleCreate:      actions.RunModuleCreate,
		actionModuleList:        actions.RunModuleList,
		actionParamDiff:         actions.RunParamDiff,
bryanl's avatar
bryanl committed
87
		actionParamDelete:       actions.RunParamDelete,
bryanl's avatar
bryanl committed
88
		actionParamUnset:        actions.RunParamDelete,
bryanl's avatar
bryanl committed
89 90 91 92 93 94 95 96 97 98 99 100 101
		actionParamList:         actions.RunParamList,
		actionParamSet:          actions.RunParamSet,
		actionPkgDescribe:       actions.RunPkgDescribe,
		actionPkgInstall:        actions.RunPkgInstall,
		actionPkgList:           actions.RunPkgList,
		actionPrototypeDescribe: actions.RunPrototypeDescribe,
		actionPrototypeList:     actions.RunPrototypeList,
		actionPrototypePreview:  actions.RunPrototypePreview,
		actionPrototypeSearch:   actions.RunPrototypeSearch,
		actionPrototypeUse:      actions.RunPrototypeUse,
		actionRegistryAdd:       actions.RunRegistryAdd,
		actionRegistryDescribe:  actions.RunRegistryDescribe,
		actionRegistryList:      actions.RunRegistryList,
102
		actionRegistryUpdate:    actions.RunRegistryUpdate,
bryanl's avatar
bryanl committed
103 104 105
		actionShow:              actions.RunShow,
		actionUpgrade:           actions.RunUpgrade,
		actionValidate:          actions.RunValidate,
bryanl's avatar
bryanl committed
106 107 108 109 110 111
	}
)

func runAction(name initName, args map[string]interface{}) error {
	fn, ok := actionFns[name]
	if !ok {
bryanl's avatar
bryanl committed
112
		return errors.Errorf("invalid action %q", name)
bryanl's avatar
bryanl committed
113 114 115 116
	}

	return fn(args)
}