func CleanupCmd()

in cmd/cleanup.go [17:48]


func CleanupCmd(fs afero.Fs) *cobra.Command {
	cleanupCmd := &cobra.Command{
		Use:  "cleanup",
		Long: "Delete all fragments",
		Args: func(cmd *cobra.Command, args []string) error {
			return nil
		},
		RunE: func(cmd *cobra.Command, args []string) error {
			fragmentLocation := viper.GetString("fragment_location")

			fragments, err := os.ReadDir(fragmentLocation)
			if err != nil {
				return fmt.Errorf("could not get fragments folder: %w", err)
			}

			for _, f := range fragments {
				ext := filepath.Ext(f.Name())

				if ext == ".yaml" || ext == ".yml" {
					err = fs.Remove(filepath.Join(fragmentLocation, f.Name()))
					if err != nil {
						return fmt.Errorf("could not remove fragment: %w", err)
					}
				}
			}

			return nil
		},
	}

	return cleanupCmd
}