<commit_before>package service

import (
	"errors"
	"fmt"
	"net/url"
	"path/filepath"
	"strings"

	"github.com/cerana/cerana/acomm"
	"github.com/cerana/cerana/providers/systemd"
	"github.com/coreos/go-systemd/unit"
)

// CreateArgs contains args for creating a new Service.
type CreateArgs struct {
	ID          string            `json:"id"`
	BundleID    uint64            `json:"bundleID"`
	Dataset     string            `json:"dataset"`
	Description string            `json:"description"`
	Cmd         []string          `json:"cmd"`
	Env         map[string]string `json:"env"`
}

// Create creates and starts a new service.
func (p *Provider) Create(req *acomm.Request) (interface{}, *url.URL, error) {
	var args CreateArgs
	if err := req.UnmarshalArgs(&args); err != nil {
		return nil, nil, err
	}
	if args.ID == "" {
		return nil, nil, errors.New("missing arg: id")
	}
	if args.BundleID == 0 {
		return nil, nil, errors.New("missing arg: bundleID")
	}
	if len(args.Cmd) == 0 {
		return nil, nil, errors.New("missing arg: cmd")
	}
	if args.Dataset == "" {
		return nil, nil, errors.New("missing arg: dataset")
	}

	name := serviceName(args.BundleID, args.ID)
	datasetCloneName := filepath.Join(p.config.DatasetCloneDir(), name)
	unitOptions := []*unit.UnitOption{
		{Section: "Unit", Name: "Description", Value: args.Description},
		// TODO: Does cmd get prepended with daisy?
		{Section: "Service", Name: "ExecStart", Value: strings.Join(args.Cmd, " ")},
		{Section: "Service", Name: "Type", Value: "forking"},
		{Section: "Install", Name: "WantedBy", Value: "cerana.Target"},<commit_msg>service - Fix capitalization of WantedBy target<commit_after>package service

import (
	"errors"
	"fmt"
	"net/url"
	"path/filepath"
	"strings"

	"github.com/cerana/cerana/acomm"
	"github.com/cerana/cerana/providers/systemd"
	"github.com/coreos/go-systemd/unit"
)

// CreateArgs contains args for creating a new Service.
type CreateArgs struct {
	ID          string            `json:"id"`
	BundleID    uint64            `json:"bundleID"`
	Dataset     string            `json:"dataset"`
	Description string            `json:"description"`
	Cmd         []string          `json:"cmd"`
	Env         map[string]string `json:"env"`
}

// Create creates and starts a new service.
func (p *Provider) Create(req *acomm.Request) (interface{}, *url.URL, error) {
	var args CreateArgs
	if err := req.UnmarshalArgs(&args); err != nil {
		return nil, nil, err
	}
	if args.ID == "" {
		return nil, nil, errors.New("missing arg: id")
	}
	if args.BundleID == 0 {
		return nil, nil, errors.New("missing arg: bundleID")
	}
	if len(args.Cmd) == 0 {
		return nil, nil, errors.New("missing arg: cmd")
	}
	if args.Dataset == "" {
		return nil, nil, errors.New("missing arg: dataset")
	}

	name := serviceName(args.BundleID, args.ID)
	datasetCloneName := filepath.Join(p.config.DatasetCloneDir(), name)
	unitOptions := []*unit.UnitOption{
		{Section: "Unit", Name: "Description", Value: args.Description},
		// TODO: Does cmd get prepended with daisy?
		{Section: "Service", Name: "ExecStart", Value: strings.Join(args.Cmd, " ")},
		{Section: "Service", Name: "Type", Value: "forking"},
		{Section: "Install", Name: "WantedBy", Value: "cerana.target"},
{'fraction_non_alphanumeric': 0.15869565217391304, 'fraction_numerical': 0.002484472049689441, 'mean_word_length': 3.511204481792717, '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': '2822808', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1083, 'n_words': 284}