Skip to content

Commit

Permalink
Implement remove alias
Browse files Browse the repository at this point in the history
  • Loading branch information
rerost committed Jun 22, 2019
1 parent 3ad79ce commit ae3a0f5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
23 changes: 23 additions & 0 deletions cmd/remove/alias/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package alias

import (
"context"

"github.com/rerost/es-cli/domain"
"github.com/spf13/cobra"
"github.com/srvc/fail"
)

func NewAliasCommand(ctx context.Context, alis domain.Alias) *cobra.Command {
cmd := &cobra.Command{
Use: "alias",
Short: "unlink alias",
Args: cobra.MinimumNArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
err := alis.Remove(ctx, args[0], args[1:]...)
return fail.Wrap(err)
},
}

return cmd
}
20 changes: 20 additions & 0 deletions cmd/remove/remove.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package remove

import (
"context"

"github.com/rerost/es-cli/cmd/remove/alias"
"github.com/rerost/es-cli/domain"
"github.com/spf13/cobra"
)

func NewRemoveCommand(ctx context.Context, alis domain.Alias) *cobra.Command {
cmd := &cobra.Command{
Use: "remove",
Short: "Remove elasitcsearch resources",
Args: cobra.ExactArgs(1),
}

cmd.AddCommand(alias.NewAliasCommand(ctx, alis))
return cmd
}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/rerost/es-cli/cmd/dump"
"github.com/rerost/es-cli/cmd/get"
"github.com/rerost/es-cli/cmd/list"
"github.com/rerost/es-cli/cmd/remove"
"github.com/rerost/es-cli/cmd/restore"
"github.com/rerost/es-cli/cmd/update"
"github.com/rerost/es-cli/domain"
Expand Down Expand Up @@ -39,6 +40,7 @@ func NewCmdRoot(
restore.NewRestoreCommand(ctx, ind),
get.NewGetCommand(ctx, dtl),
update.NewUpdateCommand(ctx, dtl),
remove.NewRemoveCommand(ctx, alis),
)

return cmd
Expand Down
2 changes: 1 addition & 1 deletion domain/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (a aliasImpl) Add(ctx context.Context, aliasName string, indexNames ...stri
}

func (a aliasImpl) Remove(ctx context.Context, aliasName string, indexNames ...string) error {
err := a.esBaseClient.RemoveAlias(ctx, aliasName)
err := a.esBaseClient.RemoveAlias(ctx, aliasName, indexNames...)
return fail.Wrap(err)
}

Expand Down

0 comments on commit ae3a0f5

Please sign in to comment.