This is an automated email from the ASF dual-hosted git repository.
zhongxjian pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-kubernetes.git
The following commit(s) were added to refs/heads/master by this push:
new 0d3264cc [dubboctl] Add some additional code comments (#657)
0d3264cc is described below
commit 0d3264cc2ffe2149d73ee92c2b9d06cf797bc3a8
Author: Jian Zhong <[email protected]>
AuthorDate: Sun Mar 23 08:12:42 2025 +0800
[dubboctl] Add some additional code comments (#657)
---
dubboctl/cmd/create.go | 27 +++++++++++++++++++++++----
dubboctl/cmd/image.go | 12 ++++++++----
dubboctl/cmd/repo.go | 10 ++++++++++
3 files changed, 41 insertions(+), 8 deletions(-)
diff --git a/dubboctl/cmd/create.go b/dubboctl/cmd/create.go
index 15661106..c18e8c54 100644
--- a/dubboctl/cmd/create.go
+++ b/dubboctl/cmd/create.go
@@ -31,7 +31,9 @@ import (
)
type createArgs struct {
- dirname string
+ // dirname specifies the name of the custom-created directory.
+ dirname string
+ // language specifies different SDK languages.
language string
template string
}
@@ -99,14 +101,21 @@ func sdkGenerateCmd(cmd *cobra.Command, clientFactory
ClientFactory) *cobra.Comm
}
type createConfig struct {
- Path string
- Runtime string
- Template string
+ // Path Absolute to function source
+ Path string
+ Runtime string
+ Template string
+ // Repo URI (overrides builtin and installed)
Repo string
DirName string
Initialized bool
}
+// newCreateConfig returns a config populated from the current execution
context
+// (args, flags and environment variables)
+// The client constructor function is used to create a transient client for
+// accessing things like the current valid templates list, and uses the
+// current value of the config at time of prompting.
func newCreateConfig(_ *cobra.Command, _ []string, _ ClientFactory) (dcfg
createConfig, err error) {
var absolutePath string
absolutePath = cwd()
@@ -126,17 +135,24 @@ func newCreateConfig(_ *cobra.Command, _ []string, _
ClientFactory) (dcfg create
}
func runCreate(cmd *cobra.Command, args []string, clientFactory ClientFactory)
error {
+ // Create a config based on args. Also uses the newClient to create a
+ // temporary client for completing options such as available runtimes.
dcfg, err := newCreateConfig(cmd, args, clientFactory)
if err != nil {
return err
}
+ // From environment variables, flags, arguments, and user prompts if
--confirm
+ // (in increasing levels of precedence)
dclient, cancel := clientFactory()
defer cancel()
+ // a deeper validation than that which is performed when
+ // instantiating the client with the raw config above.
if err = dcfg.validate(dclient); err != nil {
return err
}
+ // Initialization creation
_, err = dclient.Initialize(&dubbo.DubboConfig{
Root: dcfg.Path,
Name: dcfg.DirName,
@@ -146,6 +162,7 @@ func runCreate(cmd *cobra.Command, args []string,
clientFactory ClientFactory) e
if err != nil {
return err
}
+
fmt.Printf("Custom dubbo %v sdk was successfully created.\n",
dcfg.Runtime)
return nil
}
@@ -185,6 +202,7 @@ func newInvalidRuntimeError(client *sdk.Client, runtime
string) error {
return ErrInvalidRuntime(errors.New(b.String()))
}
+// isValidTemplate determines if the given template is valid for the given
runtime.
func isValidTemplate(client *sdk.Client, runtime, template string) bool {
if !isValidRuntime(client, runtime) {
return false
@@ -201,6 +219,7 @@ func isValidTemplate(client *sdk.Client, runtime, template
string) bool {
return false
}
+// isValidRuntime determines if the given language runtime is a valid choice.
func isValidRuntime(client *sdk.Client, runtime string) bool {
runtimes, err := client.Runtimes()
if err != nil {
diff --git a/dubboctl/cmd/image.go b/dubboctl/cmd/image.go
index da4a586f..e305b9f3 100644
--- a/dubboctl/cmd/image.go
+++ b/dubboctl/cmd/image.go
@@ -64,11 +64,15 @@ func ImageCmd(ctx cli.Context, cmd *cobra.Command,
clientFactory ClientFactory)
}
type hubConfig struct {
- Dockerfile bool
- Builder bool
- Image string
+ Dockerfile bool
+ Builder bool
+ Image string
+ // BuilderImage is the image (name or mapping) to use for building.
Usually
+ // set automatically.
BuilderImage string
- Path string
+ // Path of the application implementation on local disk. Defaults to
current
+ // working directory of the process.
+ Path string
}
type deployConfig struct {
diff --git a/dubboctl/cmd/repo.go b/dubboctl/cmd/repo.go
index e164362d..049f4293 100644
--- a/dubboctl/cmd/repo.go
+++ b/dubboctl/cmd/repo.go
@@ -71,16 +71,26 @@ func addCmd(cmd *cobra.Command, clientFactory
ClientFactory) *cobra.Command {
}
func runAdd(cmd *cobra.Command, args []string, clientFactory ClientFactory)
(err error) {
+ // Adding a repository requires there be a config path structure on disk
if err = util.GetCreatePath(); err != nil {
return
}
+ // Create a client instance which utilizes the given repositories path.
+ // Note that this MAY not be in the config structure if the environment
+ // variable to override said path was provided explicitly.
+ // be created in XDG_CONFIG_HOME/dubbo even if the repo path environment
+ // was set to some other location on disk.
client, done := clientFactory()
defer done()
+ // Preconditions
+ // If not confirming/prompting, assert the args were both provided.
if len(args) != 2 {
return fmt.Errorf("Usage: dubboctl repo add [<name>] [<url>]")
}
+ // Extract Params
+ // Populate a struct with the arguments (if provided).
p := struct {
name string
url string