<commit_before>package cmd

import (
	"context"

	"github.com/jessevdk/go-flags"
	"github.com/pkg/errors"

	"github.com/nerdalize/nerd/pkg/transfer"
	"github.com/nerdalize/nerd/svc"

	"github.com/mitchellh/cli"
)

//DatasetUpload command
type DatasetUpload struct {
	KubeOpts
	TransferOpts
	Name string `long:"name" short:"n" description:"assign a name to the dataset"`

	*command
}

//DatasetUploadFactory creates the command
func DatasetUploadFactory(ui cli.Ui) cli.CommandFactory {
	cmd := &DatasetUpload{}
	cmd.command = createCommand(ui, cmd.Execute, cmd.Description, cmd.Usage, cmd, flags.PassAfterNonOption)
	return func() (cli.Command, error) {
		return cmd, nil
	}
}

//Execute runs the command
func (cmd *DatasetUpload) Execute(args []string) (err error) {
	if len(args) < 1 {
		return errShowUsage(MessageNotEnoughArguments)
	}

	deps, err := NewDeps(cmd.Logger(), cmd.KubeOpts)
	if err != nil {
		return renderConfigError(err, "failed to configure")
	}

	kube := svc.NewKube(deps)
	mgr, sto, sta, err := cmd.TransferOpts.TransferManager(kube)
	if err != nil {
		return errors.Wrap(err, "failed to setup transfer manager")
	}

	ctx := context.Background()
	var h transfer.Handle
	if h, err = mgr.Create(
		ctx,
		cmd.Name,
		*sto,
		*sta,
	); err != nil {
		return errors.Wrap(err, "failed to create transfer handle")
	}

	defer h.Close()

	err = h.Push(ctx, args[0], &progressBarReporter{})
	if err != nil {
		return errors.Wrap(err, "failed to upload dataset")
	}
<commit_msg>delete dataset k8s object when upload fails, fixes #302<commit_after>package cmd

import (
	"context"

	"github.com/jessevdk/go-flags"
	"github.com/pkg/errors"

	"github.com/nerdalize/nerd/pkg/transfer"
	"github.com/nerdalize/nerd/svc"

	"github.com/mitchellh/cli"
)

//DatasetUpload command
type DatasetUpload struct {
	KubeOpts
	TransferOpts
	Name string `long:"name" short:"n" description:"assign a name to the dataset"`

	*command
}

//DatasetUploadFactory creates the command
func DatasetUploadFactory(ui cli.Ui) cli.CommandFactory {
	cmd := &DatasetUpload{}
	cmd.command = createCommand(ui, cmd.Execute, cmd.Description, cmd.Usage, cmd, flags.PassAfterNonOption)
	return func() (cli.Command, error) {
		return cmd, nil
	}
}

//Execute runs the command
func (cmd *DatasetUpload) Execute(args []string) (err error) {
	if len(args) < 1 {
		return errShowUsage(MessageNotEnoughArguments)
	}

	deps, err := NewDeps(cmd.Logger(), cmd.KubeOpts)
	if err != nil {
		return renderConfigError(err, "failed to configure")
	}

	kube := svc.NewKube(deps)
	mgr, sto, sta, err := cmd.TransferOpts.TransferManager(kube)
	if err != nil {
		return errors.Wrap(err, "failed to setup transfer manager")
	}

	ctx := context.Background()
	var h transfer.Handle
	if h, err = mgr.Create(
		ctx,
		cmd.Name,
		*sto,
		*sta,
	); err != nil {
		return errors.Wrap(err, "failed to create transfer handle")
	}

	defer h.Close()

	err = h.Push(ctx, args[0], &progressBarReporter{})
	if err != nil {
		e := mgr.Remove(ctx, h.Name())
		if e != nil {
			return errors.Wrapf(err, "failed to upload dataset: %v", e)
		}
		return errors.Wrap(err, "failed to upload dataset")
	}

{'fraction_non_alphanumeric': 0.1364795918367347, 'fraction_numerical': 0.002551020408163265, 'mean_word_length': 4.272268907563025, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '314035', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1124, 'n_words': 288}