<commit_before>// Copyright 2012, The gohg Authors. All rights reserved.
// Use of this source code is governed by a BSD style license
// that can be found in the LICENSE file.

package gohg_lib

func buildCmd(cmd []string, opts []string) []string {
	if opts == nil || len(opts) == 0 {
		return cmd
	}
	fullcmd := make([]string, len(cmd)+len(opts))
	copy(fullcmd, cmd)
	copy(fullcmd[len(cmd):], opts)
	return fullcmd
}<commit_msg>util: added seperate function for command boilerplate code<commit_after>// Copyright 2012, The gohg Authors. All rights reserved.
// Use of this source code is governed by a BSD style license
// that can be found in the LICENSE file.

package gohg_lib

import (
	"fmt"
)

func buildCmd(cmd []string, opts []string) []string {
	if opts == nil || len(opts) == 0 {
		return cmd
	}
	fullcmd := make([]string, len(cmd)+len(opts))
	copy(fullcmd, cmd)
	copy(fullcmd[len(cmd):], opts)
	return fullcmd
}

func command(hgcl *HgClient, cmd string, opts []string) (data []byte, err error) {
	// boilerplate code for all commands

	cmdline := buildCmd(cmd, opts)
	data, hgerr, ret, err := hgcl.run(cmdline)
	if err != nil {
		return nil, fmt.Errorf("from hgcl.run(): %s", err)
	}
	if ret != 0 || hgerr != nil {
		return nil, fmt.Errorf("Status(): returncode=%d\nhgerr:\n%s\n", data, string(hgerr))
	}
	return data, nil
}
{'fraction_non_alphanumeric': 0.1443530291697831, 'fraction_numerical': 0.008227374719521317, 'mean_word_length': 4.166023166023166, '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': '7172816', 'n_tokens_mistral': 483, 'n_tokens_neox': 453, 'n_words': 162}