Skip to content

Commit

Permalink
[dubboctl] Optimize content and complete repo logic (#559)
Browse files Browse the repository at this point in the history
fix package
  • Loading branch information
mfordjody authored Jan 24, 2025
1 parent 9935670 commit ad8db46
Show file tree
Hide file tree
Showing 30 changed files with 162 additions and 149 deletions.
9 changes: 5 additions & 4 deletions dubboctl/cmd/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func RepoCmd(_ cli.Context, cmd *cobra.Command, clientFactory ClientFactory) *co
dubboctl repo remove [name]
`,
}

cluster.AddFlags(rc, rootArgs)
addRepoFlags(rc, rArgs)
rc.AddCommand(ad)
Expand All @@ -52,7 +53,7 @@ func addCmd(cmd *cobra.Command, clientFactory ClientFactory) *cobra.Command {
return ac
}

func runAdd(_ *cobra.Command, args []string, clientFactory ClientFactory) (err error) {
func runAdd(cmd *cobra.Command, args []string, clientFactory ClientFactory) (err error) {
if err = util.CreatePath(); err != nil {
return
}
Expand Down Expand Up @@ -96,7 +97,7 @@ func listCmd(cmd *cobra.Command, clientFactory ClientFactory) *cobra.Command {
return lc
}

func runList(_ *cobra.Command, args []string, clientFactory ClientFactory) (err error) {
func runList(cmd *cobra.Command, args []string, clientFactory ClientFactory) (err error) {
client, done := clientFactory()
defer done()

Expand Down Expand Up @@ -124,7 +125,7 @@ func removeCmd(cmd *cobra.Command, clientFactory ClientFactory) *cobra.Command {
return rc
}

func runRemove(_ *cobra.Command, args []string, clientFactory ClientFactory) (err error) {
func runRemove(cmd *cobra.Command, args []string, clientFactory ClientFactory) (err error) {
client, done := clientFactory()
defer done()

Expand All @@ -141,6 +142,6 @@ func runRemove(_ *cobra.Command, args []string, clientFactory ClientFactory) (er
return
}

fmt.Printf("%s Repositories removed", p.name)
fmt.Printf("%s Repositories removed.\n", p.name)
return
}
5 changes: 4 additions & 1 deletion dubboctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"flag"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/cli"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/sdk"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/util"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/validate"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/version"
"github.com/apache/dubbo-kubernetes/operator/cmd/cluster"
Expand All @@ -33,7 +34,9 @@ type ClientFactory func(...sdk.Option) (*sdk.Client, func())

func NewClientFactory(options ...sdk.Option) (*sdk.Client, func()) {
var (
o = []sdk.Option{}
o = []sdk.Option{
sdk.WithRepositoriesPath(util.RepositoriesPath()),
}
)
client := sdk.New(append(o, options...)...)

Expand Down
10 changes: 8 additions & 2 deletions dubboctl/pkg/sdk/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (c *Client) Initialize(dcfg *dubbo.DubboConfig, initialized bool, cmd *cobr
// TODO remove initiallized
f := dubbo.NewDubboConfigWithTemplate(dcfg, initialized)

if err = RunDataDir(f.Root); err != nil {
if err = runDataDir(f.Root); err != nil {
return f, err
}

Expand Down Expand Up @@ -181,7 +181,7 @@ func isEffectivelyEmpty(dir string) (bool, error) {
return true, nil
}

func RunDataDir(root string) error {
func runDataDir(root string) error {
if err := os.MkdirAll(filepath.Join(root, dubbo.DataDir), os.ModePerm); err != nil {
return err
}
Expand Down Expand Up @@ -224,3 +224,9 @@ func RunDataDir(root string) error {
}
return nil
}

func WithRepositoriesPath(path string) Option {
return func(c *Client) {
c.repositoriesPath = path
}
}
4 changes: 2 additions & 2 deletions dubboctl/pkg/sdk/templates_embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package sdk
import (
"archive/zip"
"bytes"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/generate"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/sdk/tpl"
"github.com/apache/dubbo-kubernetes/dubboctl/pkg/util"
)

func newEmbeddedTemplatesFS() util.Filesystem {
archive, err := zip.NewReader(bytes.NewReader(generate.TemplatesZip), int64(len(generate.TemplatesZip)))
archive, err := zip.NewReader(bytes.NewReader(tpl.TemplatesZip), int64(len(tpl.TemplatesZip)))
if err != nil {
panic(err)
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package tpl

import (
"archive/zip"
Expand All @@ -11,10 +11,13 @@ import (
"path/filepath"
)

const templatesPath = "./template"
const (
templatesPath = "dubboctl/pkg/sdk/tpl/default"
generatePath = "dubboctl/pkg/sdk/tpl/zz_filesystem_generated.go"
)

func main() {
f, err := os.OpenFile("../zz_filesystem_generated.go", os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0o644)
f, err := os.OpenFile(generatePath, os.O_TRUNC|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
log.Fatal(err)
}
Expand Down

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion template/template.yaml

This file was deleted.

0 comments on commit ad8db46

Please sign in to comment.