<commit_before>package main

import (
	"fmt"
	"strings"

	"github.com/1and1/soma/internal/adm"
	"github.com/1and1/soma/lib/proto"
	"github.com/codegangsta/cli"
)

func registerViews(app cli.App) *cli.App {
	app.Commands = append(app.Commands,
		[]cli.Command{
			// views
			{
				Name:  "views",
				Usage: "SUBCOMMANDS for views",
				Subcommands: []cli.Command{
					{
						Name:   "add",
						Usage:  "Register a new view",
						Action: runtime(cmdViewsAdd),
					},
					{
						Name:   "remove",
						Usage:  "Remove an existing view",
						Action: runtime(cmdViewsRemove),
					},
					{
						Name:   "rename",
						Usage:  "Rename an existing view",
						Action: runtime(cmdViewsRename),
					},
					{
						Name:   "list",
						Usage:  "List all registered views",
						Action: runtime(cmdViewsList),
					},
					{
						Name:   "show",
						Usage:  "Show information about a specific view",
						Action: runtime(cmdViewsShow),
					},
				},
			}, // end views
		}...,
	)
	return &app
}

func cmdViewsAdd(c *cli.Context) error {
	if err := adm.VerifySingleArgument(c); err != nil {
		return err
	}

	req := proto.Request{}
	req.View = &proto.View{}
	req.View.Name = c.Args().First()
	if strings.Contains(req.View.Name, `.`) {
		adm.Abort(`Views must not contain the character '.'`)
	}

	if resp, err := adm.PostReqBody(req, `/views/`); err != nil {<commit_msg>Return error instead of aborting<commit_after>package main

import (
	"fmt"
	"strings"

	"github.com/1and1/soma/internal/adm"
	"github.com/1and1/soma/lib/proto"
	"github.com/codegangsta/cli"
)

func registerViews(app cli.App) *cli.App {
	app.Commands = append(app.Commands,
		[]cli.Command{
			// views
			{
				Name:  "views",
				Usage: "SUBCOMMANDS for views",
				Subcommands: []cli.Command{
					{
						Name:   "add",
						Usage:  "Register a new view",
						Action: runtime(cmdViewsAdd),
					},
					{
						Name:   "remove",
						Usage:  "Remove an existing view",
						Action: runtime(cmdViewsRemove),
					},
					{
						Name:   "rename",
						Usage:  "Rename an existing view",
						Action: runtime(cmdViewsRename),
					},
					{
						Name:   "list",
						Usage:  "List all registered views",
						Action: runtime(cmdViewsList),
					},
					{
						Name:   "show",
						Usage:  "Show information about a specific view",
						Action: runtime(cmdViewsShow),
					},
				},
			}, // end views
		}...,
	)
	return &app
}

func cmdViewsAdd(c *cli.Context) error {
	if err := adm.VerifySingleArgument(c); err != nil {
		return err
	}

	req := proto.Request{}
	req.View = &proto.View{}
	req.View.Name = c.Args().First()
	if strings.Contains(req.View.Name, `.`) {
		return fmt.Errorf(`Views must not contain the character '.'`)
	}

	if resp, err := adm.PostReqBody(req, `/views/`); err != nil {
{'fraction_non_alphanumeric': 0.1552772808586762, 'fraction_numerical': 0.0028622540250447226, 'mean_word_length': 2.486284289276808, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3488646', 'n_tokens_mistral': 1251, 'n_tokens_neox': 983, 'n_words': 219}