-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: make plugin more easier to maintain #83
Merged
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
09b7e1c
refactor: add lua vm struct
bytemain 6f462ae
feat: support struct marshal
bytemain 9250116
feat: add more ctx
bytemain 5732fb5
fix: encoding tag map error
bytemain 620e1c0
feat: add logger
bytemain bad1f1e
feat: add debug flag
bytemain a9f4f03
fix: fix decode in mixed struct
bytemain 882bb9a
fix: unmarshal to interface is not work
bytemain 0edeb1d
feat: ctx use marshal
bytemain f99b172
feat: unmarshal hook result
bytemain 4dc97fe
ci: update test cases
bytemain d76a19c
test: streamline encoding unit test
bytemain f4b0631
Merge remote-tracking branch 'origin/main' into refactor/make-plugin-…
bytemain 4f7b5d3
chore: remove print
bytemain 1a98f94
test: add more testcases
bytemain 95afe00
chore: revert hook name enum
bytemain a0feebe
chore: add license
bytemain 92e7071
Merge remote-tracking branch 'origin/main' into refactor/make-plugin-…
bytemain 82d0e17
chore: update log message
bytemain 6617df1
refactor: add plugin module
bytemain f107888
refactor: add a vm file
bytemain cb64f1a
chore: update logger
bytemain 2cae92c
chore: add license
bytemain 29560d5
feat: support marshal nil
bytemain 7061f28
fix: preinstall should work
bytemain 4984ff0
fix: lua checksum
bytemain 37a961c
chore: update code
bytemain f43ddb9
refactor: unmarshal plugin info
bytemain ad6f9e8
chore: some modifications
aooohan 3729e40
mod: remove debug log in encoding func
aooohan 275bcdb
mod: Optimize function calls
aooohan 2d33ebf
bugfix
aooohan c44f873
mod
aooohan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,169 @@ | ||
/* | ||
* Copyright 2024 Han Li and contributors | ||
* | ||
* 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 internal | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type LuaCheckSum struct { | ||
Sha256 string `luai:"sha256"` | ||
Sha512 string `luai:"sha512"` | ||
Sha1 string `luai:"sha1"` | ||
Md5 string `luai:"md5"` | ||
} | ||
|
||
func (c *LuaCheckSum) Checksum() *Checksum { | ||
checksum := &Checksum{} | ||
|
||
if c.Sha256 != "" { | ||
checksum.Value = c.Sha256 | ||
checksum.Type = "sha256" | ||
} else if c.Md5 != "" { | ||
checksum.Value = c.Md5 | ||
checksum.Type = "md5" | ||
} else if c.Sha1 != "" { | ||
checksum.Value = c.Sha1 | ||
checksum.Type = "sha1" | ||
} else if c.Sha512 != "" { | ||
checksum.Value = c.Sha512 | ||
checksum.Type = "sha512" | ||
} else { | ||
return NoneChecksum | ||
} | ||
|
||
return checksum | ||
} | ||
|
||
type AvailableHookCtx struct { | ||
RuntimeVersion string `luai:"runtimeVersion"` | ||
} | ||
|
||
type AvailableHookResultItem struct { | ||
Version string `luai:"version"` | ||
Note string `luai:"note"` | ||
|
||
Addition []*Info `luai:"addition"` | ||
} | ||
|
||
type AvailableHookResult = []*AvailableHookResultItem | ||
|
||
type PreInstallHookCtx struct { | ||
Version string `luai:"version"` | ||
RuntimeVersion string `luai:"runtimeVersion"` | ||
} | ||
|
||
type PreInstallHookResultAdditionItem struct { | ||
Name string `luai:"name"` | ||
Url string `luai:"url"` | ||
|
||
Sha256 string `luai:"sha256"` | ||
Sha512 string `luai:"sha512"` | ||
Sha1 string `luai:"sha1"` | ||
Md5 string `luai:"md5"` | ||
} | ||
|
||
func (i *PreInstallHookResultAdditionItem) Info() *Info { | ||
sum := LuaCheckSum{ | ||
Sha256: i.Sha256, | ||
Sha512: i.Sha512, | ||
Sha1: i.Sha1, | ||
Md5: i.Md5, | ||
} | ||
|
||
return &Info{ | ||
Name: i.Name, | ||
Version: Version(""), | ||
Path: i.Url, | ||
Note: "", | ||
Checksum: sum.Checksum(), | ||
} | ||
} | ||
|
||
type PreInstallHookResult struct { | ||
Version string `luai:"version"` | ||
Url string `luai:"url"` | ||
|
||
Sha256 string `luai:"sha256"` | ||
Sha512 string `luai:"sha512"` | ||
Sha1 string `luai:"sha1"` | ||
Md5 string `luai:"md5"` | ||
|
||
Addition []*PreInstallHookResultAdditionItem `luai:"addition"` | ||
} | ||
|
||
func (i *PreInstallHookResult) Info() (*Info, error) { | ||
if i.Version == "" { | ||
return nil, fmt.Errorf("no version number provided") | ||
} | ||
|
||
sum := LuaCheckSum{ | ||
Sha256: i.Sha256, | ||
Sha512: i.Sha512, | ||
Sha1: i.Sha1, | ||
Md5: i.Md5, | ||
} | ||
|
||
return &Info{ | ||
Name: "", | ||
Version: Version(i.Version), | ||
Path: i.Url, | ||
Note: "", | ||
Checksum: sum.Checksum(), | ||
}, nil | ||
} | ||
|
||
type PreUseHookCtx struct { | ||
RuntimeVersion string `luai:"runtimeVersion"` | ||
Cwd string `luai:"cwd"` | ||
Scope string `luai:"scope"` | ||
Version string `luai:"version"` | ||
PreviousVersion string `luai:"previousVersion"` | ||
InstalledSdks map[string]*Info `luai:"installedSdks"` | ||
} | ||
|
||
type PreUseHookResult struct { | ||
Version string `luai:"version"` | ||
} | ||
|
||
type PostInstallHookCtx struct { | ||
RuntimeVersion string `luai:"runtimeVersion"` | ||
RootPath string `luai:"rootPath"` | ||
SdkInfo map[string]*Info `luai:"sdkInfo"` | ||
} | ||
|
||
type EnvKeysHookCtx struct { | ||
RuntimeVersion string `luai:"runtimeVersion"` | ||
Main *Info `luai:"main"` | ||
// TODO Will be deprecated in future versions | ||
Path string `luai:"path"` | ||
SdkInfo map[string]*Info `luai:"sdkInfo"` | ||
} | ||
|
||
type EnvKeysHookResultItem struct { | ||
Key string `luai:"key"` | ||
Value string `luai:"value"` | ||
} | ||
|
||
type LuaPluginInfo struct { | ||
Name string `luai:"name"` | ||
Author string `luai:"author"` | ||
Version string `luai:"version"` | ||
Description string `luai:"description"` | ||
UpdateUrl string `luai:"updateUrl"` | ||
MinRuntimeVersion string `luai:"minRuntimeVersion"` | ||
} |
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,70 @@ | ||
/* | ||
* Copyright 2024 Han Li and contributors | ||
* | ||
* 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 logger | ||
|
||
import "fmt" | ||
|
||
type LoggerLevel int | ||
|
||
// the smaller the level, the more logs. | ||
const ( | ||
DebugLevel LoggerLevel = iota | ||
InfoLevel | ||
ErrorLevel | ||
) | ||
|
||
var currentLevel = InfoLevel | ||
|
||
func SetLevel(_level LoggerLevel) { | ||
currentLevel = _level | ||
} | ||
|
||
func Log(level LoggerLevel, args ...interface{}) { | ||
if currentLevel <= level { | ||
fmt.Println(args...) | ||
} | ||
} | ||
|
||
func Logf(level LoggerLevel, message string, args ...interface{}) { | ||
if currentLevel <= level { | ||
fmt.Printf(message, args...) | ||
} | ||
} | ||
|
||
func Error(message ...interface{}) { | ||
Log(ErrorLevel, message...) | ||
} | ||
|
||
func Errorf(message string, args ...interface{}) { | ||
Logf(ErrorLevel, message, args...) | ||
} | ||
|
||
func Info(message ...interface{}) { | ||
Log(InfoLevel, message...) | ||
} | ||
|
||
func Infof(message string, args ...interface{}) { | ||
Logf(InfoLevel, message, args...) | ||
} | ||
|
||
func Debug(args ...interface{}) { | ||
Log(DebugLevel, args...) | ||
} | ||
|
||
func Debugf(message string, args ...interface{}) { | ||
Logf(DebugLevel, message, args...) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
only worked when this flag before any subcommand,
related: #88