Skip to content

Commit

Permalink
Merge pull request superfly#1530 from ndarilek/remove-destroy
Browse files Browse the repository at this point in the history
Rename some deletion commands to `destroy` for consistency
  • Loading branch information
ndarilek authored Jan 12, 2023
2 parents be13c02 + 1bf1fd3 commit 938dbc8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@ import (
"github.com/superfly/flyctl/iostreams"
)

func newRemove() *cobra.Command {
func newDestroy() *cobra.Command {
const (
short = "Remove a Fly machine"
short = "Destroy a Fly machine"
long = short + "\n"

usage = "remove <id>"
usage = "destroy <id>"
)

cmd := command.New(usage, short, long, runMachineRemove,
cmd := command.New(usage, short, long, runMachineDestroy,
command.RequireSession,
command.LoadAppNameIfPresent,
)

cmd.Aliases = []string{"rm"}
cmd.Aliases = []string{"remove", "rm"}

flag.Add(
cmd,
Expand All @@ -45,7 +45,7 @@ func newRemove() *cobra.Command {
return cmd
}

func runMachineRemove(ctx context.Context) (err error) {
func runMachineDestroy(ctx context.Context) (err error) {
var (
appName = app.NameFromContext(ctx)
out = iostreams.FromContext(ctx).Out
Expand Down
2 changes: 1 addition & 1 deletion internal/command/machine/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func New() *cobra.Command {
cmd.AddCommand(
newKill(),
newList(),
newRemove(),
newDestroy(),
newRun(),
newStart(),
newStop(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@ import (
"github.com/superfly/flyctl/internal/prompt"
)

func newDelete() *cobra.Command {
func newDestroy() *cobra.Command {
const (
long = `Delete a volume Requires the volume's ID
long = `Destroy a volume Requires the volume's ID
number to operate. This can be found through the volumes list command`

short = "Delete a volume from the app"
short = "Destroy a volume"
)

cmd := command.New("delete <id>", short, long, runDelete,
cmd := command.New("destroy <id>", short, long, runDestroy,
command.RequireSession,
)
cmd.Args = cobra.ExactArgs(1)
cmd.Aliases = []string{"delete", "rm"}

flag.Add(cmd,
flag.Yes(),
Expand All @@ -34,7 +35,7 @@ number to operate. This can be found through the volumes list command`
return cmd
}

func runDelete(ctx context.Context) error {
func runDestroy(ctx context.Context) error {
var (
io = iostreams.FromContext(ctx)
colorize = io.ColorScheme()
Expand All @@ -46,7 +47,7 @@ func runDelete(ctx context.Context) error {
const msg = "Deleting a volume is not reversible."
fmt.Fprintln(io.ErrOut, colorize.Red(msg))

switch confirmed, err := prompt.Confirm(ctx, "Are you sure you want to delete this volume?"); {
switch confirmed, err := prompt.Confirm(ctx, "Are you sure you want to destroy this volume?"); {
case err == nil:
if !confirmed {
return nil
Expand All @@ -60,10 +61,10 @@ func runDelete(ctx context.Context) error {

data, err := client.DeleteVolume(ctx, volID)
if err != nil {
return fmt.Errorf("failed deleting volume: %w", err)
return fmt.Errorf("failed destroying volume: %w", err)
}

fmt.Fprintf(io.Out, "Deleted volume %s from %s\n", volID, data.Name)
fmt.Fprintf(io.Out, "Destroyed volume %s from %s\n", volID, data.Name)

return nil
}
2 changes: 1 addition & 1 deletion internal/command/volumes/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func New() *cobra.Command {
cmd.AddCommand(
newCreate(),
newList(),
newDelete(),
newDestroy(),
newExtend(),
newShow(),
snapshots.New(),
Expand Down

0 comments on commit 938dbc8

Please sign in to comment.