<commit_before>package main

import (
	"fmt"
	"github.com/redneckbeard/quimby"
	"github.com/redneckbeard/gadget/strutil"
	"os"
	"path/filepath"
	"strings"
)

func init() {
	quimby.Add(&Controller{})
}

// Controller provides a command that generates controller files.
type Controller struct {
	*quimby.Flagger
	name string
}

func (c *Controller) Desc() string {
	return "Create a new controller. Camel-cased names will be used unmodified. Other names will be title-cased."
}

func (c *Controller) SetFlags() {
	c.StringVar(&c.name, "name", "", "Name of the controller type to create")
}

func (c *Controller) Run() {
	name := c.name
	if name == "" {
		args := c.FlagSet.Args()
		if len(args) == 0 {
			fmt.Println("You must supply a name for the controller.")
			return
		}
		name = args[0]
	}
	current, _ := os.Getwd()
	path, err := filepath.Rel(
		filepath.Join(os.ExpandEnv("$GOPATH"), "src"),
		filepath.Join(current),
	)
	if err != nil {
		fmt.Println("Projects must be created in the src directory of your GOPATH.")
	}
	createControllerFile(path, name)
}

func createControllerFile(projectName, controllerName string) {
	var filename string
	t := getTemplate("controller.tpl")
	if strutil.IsPascalCase(controllerName) {
		filename = strutil.Snakify(controllerName)
	} else {
		filename = strings.ToLower(controllerName)
		controllerName = strings.Title(controllerName)
	}
	path := filepath.Join(projectName, "controllers", filename + ".go")
	importPath, _ := getImportPath(projectName)
	if f, err := os.Create(path); err != nil {
		fmt.Printf("Unable to create file controllers/%s.go: %s\n", filename, err)
	} else {
		defer f.Close()
		t.Execute(f, map[string]string{
			"name": controllerName,
			"project": importPath,<commit_msg>Fixes controller generator closes redneckbeard/gadget#16<commit_after>package main

import (
	"fmt"
	"github.com/redneckbeard/quimby"
	"github.com/redneckbeard/gadget/strutil"
	"os"
	"path/filepath"
	"strings"
)

func init() {
	quimby.Add(&Controller{})
}

// Controller provides a command that generates controller files.
type Controller struct {
	*quimby.Flagger
	name string
}

func (c *Controller) Desc() string {
	return "Create a new controller. Camel-cased names will be used unmodified. Other names will be title-cased."
}

func (c *Controller) SetFlags() {
	c.StringVar(&c.name, "name", "", "Name of the controller type to create")
}

func (c *Controller) Run() {
	name := c.name
	if name == "" {
		args := c.FlagSet.Args()
		if len(args) == 0 {
			fmt.Println("You must supply a name for the controller.")
			return
		}
		name = args[0]
	}
	current, _ := os.Getwd()
	gopath := filepath.Join(os.ExpandEnv("$GOPATH"), "src")
	if !strings.HasPrefix(current, gopath) {
		fmt.Println("Controllers must be created in a Gadget project directory.")
		return
	}
	createControllerFile(current, name)
}

func createControllerFile(projectName, controllerName string) {
	var filename string
	t := getTemplate("controller.tpl")
	if strutil.IsPascalCase(controllerName) {
		filename = strutil.Snakify(controllerName)
	} else {
		filename = strings.ToLower(controllerName)
		controllerName = strings.Title(controllerName)
	}
	path := filepath.Join(projectName, "controllers", filename + ".go")
	importPath, _ := getImportPath(projectName)
	if f, err := os.Create(path); err != nil {
		fmt.Printf("Unable to create file controllers/%s.go: %s\n", filename, err)
	} else {
		defer f.Close()
		t.Execute(f, map[string]string{
			"name": controllerName,
			"project": importPath,
{'fraction_non_alphanumeric': 0.13911060433295325, 'fraction_numerical': 0.0017103762827822121, 'mean_word_length': 4.448757763975156, 'pattern_counts': {'":': 4, '<': 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': '1829966', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1196, 'n_words': 311}