-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: plan command compiles w/o git, vcs (#1)
* feat: plan command compiles w/o git, vcs * feat: plan command compiles with transformers initialization * feat: Supports ".tar", ".tar.gz", ".tgz", Write plan works
- Loading branch information
1 parent
bd7d83a
commit fcead15
Showing
34 changed files
with
3,742 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,8 @@ | |
# Go workspace file | ||
go.work | ||
|
||
# Goland workspace file | ||
.idea | ||
|
||
# Build output directory | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright IBM Corporation 2021 | ||
* | ||
* 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. | ||
*/ | ||
|
||
package deepcopy | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// DeepCopyInterface can be implemented by types to have custom deep copy logic. | ||
type DeepCopyInterface interface { | ||
DeepCopy() interface{} | ||
} | ||
|
||
// DeepCopy returns a deep copy of x. | ||
// Supports everything except Chan, Func and UnsafePointer. | ||
func DeepCopy(x interface{}) interface{} { | ||
return copyRecursively(reflect.ValueOf(x)).Interface() | ||
} | ||
|
||
func copyRecursively(xV reflect.Value) reflect.Value { | ||
if !xV.IsValid() { | ||
logrus.Debugf("invalid value given to copy recursively value: %+v", xV) | ||
return xV | ||
} | ||
if xV.CanInterface() { | ||
if deepCopyAble, ok := xV.Interface().(DeepCopyInterface); ok { | ||
yV := reflect.ValueOf(deepCopyAble.DeepCopy()) | ||
if !yV.IsValid() { | ||
return xV | ||
} | ||
return yV | ||
} | ||
} | ||
xT := xV.Type() | ||
xK := xV.Kind() | ||
switch xK { | ||
case reflect.Bool, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr, reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128, reflect.String: | ||
return xV | ||
case reflect.Array: | ||
yV := reflect.New(xT).Elem() | ||
for i := 0; i < xV.Len(); i++ { | ||
yV.Index(i).Set(copyRecursively(xV.Index(i))) | ||
} | ||
return yV | ||
case reflect.Slice: | ||
if xK == reflect.Slice && xV.IsNil() { | ||
return xV | ||
} | ||
yV := reflect.MakeSlice(xT, xV.Len(), xV.Cap()) | ||
for i := 0; i < xV.Len(); i++ { | ||
yV.Index(i).Set(copyRecursively(xV.Index(i))) | ||
} | ||
return yV | ||
case reflect.Interface: | ||
if xV.IsNil() { | ||
return xV | ||
} | ||
return copyRecursively(xV.Elem()) | ||
case reflect.Map: | ||
if xV.IsNil() { | ||
return xV | ||
} | ||
yV := reflect.MakeMapWithSize(xT, xV.Len()) | ||
for _, key := range xV.MapKeys() { | ||
yV.SetMapIndex(copyRecursively(key), copyRecursively(xV.MapIndex(key))) | ||
} | ||
return yV | ||
case reflect.Ptr: | ||
if xV.IsNil() { | ||
return xV | ||
} | ||
yV := reflect.New(xV.Elem().Type()) | ||
yV.Elem().Set(copyRecursively(xV.Elem())) | ||
return yV | ||
case reflect.Struct: | ||
yV := reflect.New(xT).Elem() | ||
hasUnsettableFields := false | ||
for i := 0; i < xV.NumField(); i++ { | ||
if !yV.Field(i).CanSet() { | ||
hasUnsettableFields = true | ||
logrus.Debugf("%+v type has unsettable fields, so referencing instead of copying", xT) | ||
break | ||
} | ||
yV.Field(i).Set(copyRecursively(xV.Field(i))) | ||
} | ||
if hasUnsettableFields { | ||
yV.Set(xV) | ||
} | ||
return yV | ||
default: | ||
logrus.Debugf("unsupported for deep copy kind: %+v type: %+v value: %+v", xK, xT, xV) | ||
return xV | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright IBM Corporation 2021 | ||
* | ||
* 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. | ||
*/ | ||
|
||
package common | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// CleanupHook calls the cleanup functions on fatal and panic errors | ||
type CleanupHook struct { | ||
ctxContextFn func() | ||
} | ||
|
||
// NewCleanupHook creates a cleanup hook | ||
func NewCleanupHook(ctxContextFn context.CancelFunc) *CleanupHook { | ||
return &CleanupHook{ctxContextFn} | ||
} | ||
|
||
// Fire calls the clean up | ||
func (hook *CleanupHook) Fire(entry *logrus.Entry) error { | ||
hook.ctxContextFn() | ||
return nil | ||
} | ||
|
||
// Levels returns the levels on which the cleanup hook gets called | ||
func (hook *CleanupHook) Levels() []logrus.Level { | ||
return []logrus.Level{ | ||
logrus.PanicLevel, | ||
logrus.FatalLevel, | ||
} | ||
} |
Oops, something went wrong.