-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5de990a
commit b6484e8
Showing
7 changed files
with
333 additions
and
56 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package delete | ||
|
||
import ( | ||
"github.com/dream11/odin/cmd" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var deleteCmd = &cobra.Command{ | ||
Use: "delete", | ||
Short: "Delete resources", | ||
Long: `Delete resources`, | ||
} | ||
|
||
func init() { | ||
cmd.RootCmd.AddCommand(deleteCmd) | ||
} |
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,63 @@ | ||
package delete | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/dream11/odin/internal/service" | ||
"github.com/dream11/odin/pkg/constant" | ||
environment "github.com/dream11/odin/proto/gen/go/dream11/od/environment/v1" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var name string | ||
|
||
var environmentClient = service.Environment{} | ||
|
||
var environmentCmd = &cobra.Command{ | ||
Use: "environment", | ||
Short: "Delete environment", | ||
Long: `Delete environment`, | ||
Args: func(cmd *cobra.Command, args []string) error { | ||
return cobra.NoArgs(cmd, args) | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
execute(cmd) | ||
}, | ||
} | ||
|
||
func init() { | ||
environmentCmd.Flags().StringVar(&name, "name", "", "name of the env") | ||
deleteCmd.AddCommand(environmentCmd) | ||
} | ||
|
||
func execute(cmd *cobra.Command) { | ||
ctx := cmd.Context() | ||
response, err := environmentClient.DeleteEnvironment(&ctx, &environment.DeleteEnvironmentRequest{ | ||
EnvName: name, | ||
}) | ||
|
||
if err != nil { | ||
log.Fatal("Failed to delete environment ", err) | ||
} | ||
|
||
outputFormat, err := cmd.Flags().GetString("output") | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
writeOutput(response, outputFormat) | ||
} | ||
|
||
func writeOutput(response *environment.DeleteEnvironmentResponse, format string) { | ||
|
||
switch format { | ||
case constant.TEXT: | ||
fmt.Print(response.Message) | ||
case constant.JSON: | ||
output, _ := json.Marshal(response) | ||
fmt.Print(string(output)) | ||
default: | ||
log.Fatal("Unknown output format: ", format) | ||
} | ||
} |
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
Oops, something went wrong.