<commit_before>package cmd

import (
	"fmt"
	"io"
	"os"
	"strings"

	"github.com/ClusterHQ/dvol/pkg/datalayer"
	"github.com/spf13/cobra"
)

var forceRemoveVolume bool

func userIsSure(extraMessage string) bool {
	message := fmt.Sprintf("Are you sure? %s (y/n): ", extraMessage)
	fmt.Print(message)
	var response string
	_, err := fmt.Scanln(&response)
	if err != nil {
		fmt.Println("Error reading response.")
		return false
	}
	response = strings.ToLower(response)
	if response == "y" || response == "yes" {
		return true
	}
	return false
}

func NewCmdRm(out io.Writer) *cobra.Command {
	cmd := &cobra.Command{
		// TODO: Improve the usage string to include a volume name to remove
		Use:   "rm",
		Short: "Destroy a dvol volume",
		Run: func(cmd *cobra.Command, args []string) {
			err := removeVolume(cmd, args, out)
			if err != nil {
				fmt.Fprintln(os.Stderr, err.Error())
				os.Exit(1)
			}
		},
	}
	cmd.Flags().BoolVarP(&forceRemoveVolume, "force", "f", false, "Force remove")
	return cmd
}

func removeVolume(cmd *cobra.Command, args []string, out io.Writer) error {

	if len(args) == 0 {
		return fmt.Errorf("Please specify a volume name.")
	}
	volumeName := args[0]
	if !datalayer.ValidVolumeName(volumeName) {
		return fmt.Errorf("Error: " + volumeName + " is not a valid name")
	}
	if !datalayer.VolumeExists(basePath, volumeName) {
		msg := fmt.Sprintf("Volume '%s' does not exist, cannot remove it", volumeName)
		return fmt.Errorf(msg)
	}
	if forceRemoveVolume || userIsSure("This will remove all containers using the volume") {
		s := fmt.Sprintf("Deleting volume '%s'", volumeName)
		fmt.Fprintln(out, s)
		err := datalayer.RemoveVolume(basePath, volumeName)
		if err != nil {
			return fmt.Errorf("Error removing volume")
		}
	} else {
		fmt.Fprintln(out, "Aborting.")
	}
	return nil
}<commit_msg>Add check for wrong number of arguments.<commit_after>package cmd

import (
	"fmt"
	"io"
	"os"
	"strings"

	"github.com/ClusterHQ/dvol/pkg/datalayer"
	"github.com/spf13/cobra"
)

var forceRemoveVolume bool

func userIsSure(extraMessage string) bool {
	message := fmt.Sprintf("Are you sure? %s (y/n): ", extraMessage)
	fmt.Print(message)
	var response string
	_, err := fmt.Scanln(&response)
	if err != nil {
		fmt.Println("Error reading response.")
		return false
	}
	response = strings.ToLower(response)
	if response == "y" || response == "yes" {
		return true
	}
	return false
}

func NewCmdRm(out io.Writer) *cobra.Command {
	cmd := &cobra.Command{
		// TODO: Improve the usage string to include a volume name to remove
		Use:   "rm",
		Short: "Destroy a dvol volume",
		Run: func(cmd *cobra.Command, args []string) {
			err := removeVolume(cmd, args, out)
			if err != nil {
				fmt.Fprintln(os.Stderr, err.Error())
				os.Exit(1)
			}
		},
	}
	cmd.Flags().BoolVarP(&forceRemoveVolume, "force", "f", false, "Force remove")
	return cmd
}

func removeVolume(cmd *cobra.Command, args []string, out io.Writer) error {

	if len(args) == 0 {
		return fmt.Errorf("Please specify a volume name.")
	}
	if len(args) > 1 {
		return fmt.Errorf("Wrong number of arguments.")
	}
	volumeName := args[0]
	if !datalayer.ValidVolumeName(volumeName) {
		return fmt.Errorf("Error: " + volumeName + " is not a valid name")
	}
	if !datalayer.VolumeExists(basePath, volumeName) {
		msg := fmt.Sprintf("Volume '%s' does not exist, cannot remove it", volumeName)
		return fmt.Errorf(msg)
	}
	if forceRemoveVolume || userIsSure("This will remove all containers using the volume") {
		s := fmt.Sprintf("Deleting volume '%s'", volumeName)
		fmt.Fprintln(out, s)
		err := datalayer.RemoveVolume(basePath, volumeName)
		if err != nil {
			return fmt.Errorf("Error removing volume")
		}
	} else {
		fmt.Fprintln(out, "Aborting.")
	}
	return nil
}
{'fraction_non_alphanumeric': 0.14446227929373998, 'fraction_numerical': 0.0029427501337613697, 'mean_word_length': 3.9919893190921227, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6221722', 'n_tokens_mistral': 1393, 'n_tokens_neox': 1313, 'n_words': 360}