<commit_before>package main

import (
	"errors"
	"strings"
)

type Directive struct {
	template string
	result   string
	command  string
	tags     []string
}

func ParseDirectives(args []string) ([]Directive, error) {
	args_len := len(args)
	directives := make([]Directive, args_len)
	// for each args, parse into directives
	for i := 0; i < args_len; i = i + 1 {
		// split it into parts
		// 1st part: path to template file
		// 2nd part: path to result file
		// 3nd part: command to execute, optional
		// remaining parts: filter tags
		parts := strings.Split(args[i], ":")
		parts_len := len(parts)
		// check number
		if parts_len < 2 {
			return nil, errors.New("Syntax error")
		}
		for i := 0; i < parts_len; i = i + 1 {
			if len(parts[i]) == 0 {
				return nil, errors.New("Syntax error")
			}
		}
		// register directive
		directives[i] = Directive{
			template: parts[0],
			result:   parts[1],
		}
		if parts_len > 2 {
			directives[i].command = parts[2]
		}
		if parts_len > 3 {
			directives[i].tags = make([]string, parts_len-3)
			for j := 0; j < parts_len-3; j = j + 1 {
				directives[i].tags[j] = parts[3+j]
			}
		}
	}

	return directives, nil
}<commit_msg>parse directive from config file<commit_after>package main

import (
	"io/ioutil"
	"encoding/json"
)

type Template struct {
	Src string
	Dest string
	Cmd string
}

type Directive struct {
	Name string
	Role string
	Status string
	Tags []string
	Rpc-addr string
	Rpc-auth string
	Templates []Template
}

func ParseDirectives(config-file string) (Directive, error) {
	config-json, err := ioutil.ReadFile(config-file)
	if err != nil {
		panic(err)
	}
	var directive Directive
	err = json.Unmarshal(config-json, &directive)
	if err != nil {
		panic(err)
	}
	return directive, nil
}
{'fraction_non_alphanumeric': 0.12805919180421171, 'fraction_numerical': 0.010813887307911212, 'mean_word_length': 3.236144578313253, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 5, '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': '3975488', 'n_tokens_mistral': 692, 'n_tokens_neox': 624, 'n_words': 186}