<commit_before>package main

import (
	"fmt"
	"os"
	"text/template"
	"unicode"

	"github.com/gonuts/commander"
	"github.com/gonuts/flag"
)

func generate() *commander.Command {
	cmd := &commander.Command{
		Run:       doGenerate,
		UsageLine: "generate [options]",
		Short:     "Generates a gobot library skeleton",
		Long: `
Generates a gobot library skeleton.

ex:
 $ gobot generate myProject
`,
		Flag: *flag.NewFlagSet("gobot-generate", flag.ExitOnError),
	}
	return cmd
}

type Generate struct {
	Name string
}

func doGenerate(cmd *commander.Command, args []string) error {
	if len(args) == 0 {
		fmt.Println(cmd.Long)
		return nil
	}
	pwd, _ := os.Getwd()
	dir := fmt.Sprintf("%s/gobot-%s", pwd, args[0])
	fmt.Println("Creating", dir)
	err := os.MkdirAll(dir, 0700)
	if err != nil {
		fmt.Println(err)
		err = nil
	}

	a := []rune(args[0])
	a[0] = unicode.ToUpper(a[0])
	s := string(a)

	name := Generate{Name: s}

	adaptor, _ := template.New("").Parse(adaptor())
	file_location := fmt.Sprintf("%s/%s_adaptor.go", dir, args[0])
	fmt.Println("Creating", file_location)
	f, err := os.Create(file_location)
	if err != nil {
		fmt.Println(err)
		err = nil
	}
	adaptor.Execute(f, name)
	f.Close()

	file_location = fmt.Sprintf("%s/%s_driver.go", dir, args[0])
	fmt.Println("Creating", file_location)
	f, err = os.Create(file_location)
	if err != nil {
		fmt.Println(err)
		err = nil
	}
	driver, _ := template.New("").Parse(driver())
	driver.Execute(f, name)
	return f.Close()
}

func adaptor() string {
	return `package gobot{{ .Name }}

import (
	"github.com/hybridgroup/gobot"
)

type {{ .Name }}Adaptor struct {
	gobot.Adaptor
}

func (me *{{ .Name }}Adaptor) Connect() {
}

func (me *{{ .Name }}Adaptor) Disconnect() {
}
`
}

func driver() string {
	return `package gobot{{ .Name }}

import (
	"github.com/hybridgroup/gobot"
)

type {{ .Name }}Driver struct {
	gobot.Driver
	{{ .Name }}Adaptor *{{ .Name }}Adaptor
}

func New{{ .Name }}(adaptor *{{ .Name }}Adaptor) *{{ .Name }}Driver {
	d := new({{ .Name }}Driver)
	d.Events = make(map[string]chan interface{})
	d.{{ .Name }}Adaptor = adaptor
	d.Commands = []string{}
	return d
}

func (me *{{ .Name }}Driver) StartDriver() {
	gobot.Every(sd.Interval, func() {
		me.handleMessageEvents()
	})
}

func (me *{{ .Name }}Driver) handleMessageEvents() {
}
`
}<commit_msg>Update generator<commit_after>package main

import (
	"fmt"
	"github.com/gonuts/commander"
	"github.com/gonuts/flag"
	"os"
	"text/template"
	"unicode"
)

func generate() *commander.Command {
	cmd := &commander.Command{
		Run:       doGenerate,
		UsageLine: "generate [options]",
		Short:     "Generates a Gobot library skeleton",
		Long: `
Generates a Gobot library skeleton.

ex:
 $ gobot generate myProject
`,
		Flag: *flag.NewFlagSet("gobot-generate", flag.ExitOnError),
	}
	return cmd
}

type Generate struct {
	Name      string
	UpperName string
}

func doGenerate(cmd *commander.Command, args []string) error {
	if len(args) == 0 {
		fmt.Println(cmd.Long)
		return nil
	}
	pwd, _ := os.Getwd()
	dir := fmt.Sprintf("%s/gobot-%s", pwd, args[0])
	fmt.Println("Creating", dir)
	err := os.MkdirAll(dir, 0700)
	if err != nil {
		fmt.Println(err)
		err = nil
	}

	a := []rune(args[0])
	a[0] = unicode.ToUpper(a[0])
	s := string(a)

	name := Generate{UpperName: s, Name: string(args[0])}

	adaptor, _ := template.New("").Parse(adaptor())
	file_location := fmt.Sprintf("%s/%s_adaptor.go", dir, args[0])
	fmt.Println("Creating", file_location)
	f, err := os.Create(file_location)
	if err != nil {
		fmt.Println(err)
		err = nil
	}
	adaptor.Execute(f, name)
	f.Close()

	driver, _ := template.New("").Parse(driver())
	file_location = fmt.Sprintf("%s/%s_driver.go", dir, args[0])
	fmt.Println("Creating", file_location)
	f, err = os.Create(file_location)
	if err != nil {
		fmt.Println(err)
		err = nil
	}
	driver.Execute(f, name)
	f.Close()

	readme, _ := template.New("").Parse(readme())
	file_location = fmt.Sprintf("%s/README.md", dir)
	fmt.Println("Creating", file_location)
	f, err = os.Create(file_location)
	if err != nil {
		fmt.Println(err)
		err = nil
	}
	readme.Execute(f, name)
	f.Close()

	file_location = fmt.Sprintf("%s/LICENSE", dir)
	fmt.Println("Creating", file_location)
	f, err = os.Create(file_location)
	if err != nil {
		fmt.Println(err)
		err = nil
	}
	f.Close()
	return nil
}

func adaptor() string {
	return `package gobot{{ .UpperName }}

import (
	"github.com/hybridgroup/gobot"
)

type {{ .UpperName }}Adaptor struct {
	gobot.Adaptor
}

func (me *{{ .UpperName }}Adaptor) Connect() bool {
  return true
}

func (me *{{ .UpperName }}Adaptor) Reconnect() bool {
  return true
}

func (me *{{ .Name }}Adaptor) Disconnect() bool {
  return true
}

func (me *{{ .Name }}Adaptor) Finalize() bool {
  return true
}
`
}

func driver() string {
	return `package gobot{{ .UpperName }}

import (
	"github.com/hybridgroup/gobot"
)

type {{ .UpperName }}Driver struct {
	gobot.Driver
	{{ .UpperName }}Adaptor *{{ .UpperName }}Adaptor
}

type {{ .UpperName}}Interface interface {
}

func New{{ .UpperName }}(adaptor *{{ .UpperName }}Adaptor) *{{ .UpperName }}Driver {
	d := new({{ .UpperName }}Driver)
	d.Events = make(map[string]chan interface{})
	d.{{ .UpperName }}Adaptor = adaptor
	d.Commands = []string{}
	return d
}

func (me *{{ .UpperName }}Driver) Start() bool {
	gobot.Every(sd.Interval, func() {
		me.handleMessageEvents()
	})
  return true
}

func (me *{{ .UpperName }}Driver) handleMessageEvents() {
}
`
}

func readme() string {
	return `# Gobot for {{ .Name }}

Gobot (http://gobot.io/) is a library for robotics and physical computing using Go

This repository contains the Gobot adaptor for {{ .Name }}.

For more information about Gobot, check out the github repo at
https://github.com/hybridgroup/gobot

## Installing

    go get path/to/repo/gobot-{{ .Name }}

## Using

    your example code here...

## Connecting

Explain how to connect from the computer to the device here...

## License

Copyright (c) 2014 Your Name Here. See LICENSE for more details
`
}
{'fraction_non_alphanumeric': 0.17381902860944778, 'fraction_numerical': 0.004491017964071856, 'mean_word_length': 3.8925956061838893, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '6135382', 'n_tokens_mistral': 2379, 'n_tokens_neox': 2285, 'n_words': 545}