<commit_before>package cli

import (
	"fmt"
	"os"
	"sort"
	"strings"
)

// The basic datastructure used in cli. Actions are added for different paths to a router via the "Register" and
// "RegisterFunc" methods. These actions can be executed using the "Run" and "RunWithArgs" methods.
type Router struct {
	root *routingTreeNode

	initFailed bool
}

// Create a new router that will be used to register and run the actions of the application.
func NewRouter() *Router {
	r := &Router{}
	r.root = &routingTreeNode{children: map[string]*routingTreeNode{}}
	return r
}

// Run the given arguments against the registered actions, i.e. try to find a matching route and run the according
// action.
func (r *Router) Run(args ...string) (e error) {
	if r.initFailed {
		logger.Fatal("errors found during initialization")
	}
	// Find action and parse args.
	node, args := r.findNode(args, true)<commit_msg>add simple initializer for router<commit_after>package cli

import (
	"fmt"
	"os"
	"sort"
	"strings"
)

// The basic datastructure used in cli. Actions are added for different paths to a router via the "Register" and
// "RegisterFunc" methods. These actions can be executed using the "Run" and "RunWithArgs" methods.
type Router struct {
	root *routingTreeNode

	initFailed bool
}

func New(routes ...func(*Router) error) (*Router, error) {
	router := NewRouter()
	for _, route := range routes {
		if err := route(router); err != nil {
			return nil, err
		}
	}
	return router, nil
}

// Create a new router that will be used to register and run the actions of the application.
func NewRouter() *Router {
	r := &Router{}
	r.root = &routingTreeNode{children: map[string]*routingTreeNode{}}
	return r
}

// Run the given arguments against the registered actions, i.e. try to find a matching route and run the according
// action.
func (r *Router) Run(args ...string) (e error) {
	if r.initFailed {
		logger.Fatal("errors found during initialization")
	}
	// Find action and parse args.
	node, args := r.findNode(args, true)
{'fraction_non_alphanumeric': 0.10797424467558198, 'fraction_numerical': 0.0, 'mean_word_length': 3.9029126213592233, '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': '3772261', 'n_tokens_mistral': 624, 'n_tokens_neox': 617, 'n_words': 256}