<commit_before>package cli

import (
	"fmt"
	"log"
	"os"
	"strings"
)

// Interface that must be implemented by actions. This is interface is used by the RegisterAction function. The Run
// method of the implementing type will be called if the given route matches it.
type Runner interface {
	Run() error
}

// Create a new router.
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 {
		log.Fatal("errors found during initialization")
	}
	// Find action and parse args.
	node, args := r.findNode(args, true)
	if node != nil && node.action != nil {
		if e := node.action.parseArgs(args); e != nil {
			node.showHelp()
			return e
		}
	} else { // Failed to find node.
		node.showHelp()
		return fmt.Errorf("no route matched")
	}

	return node.action.runner.Run()
}

// Run the arguments from the commandline (aka os.Args) against the registered actions, i.e. try to find a matching
// route and run the according action.
func (r *Router) RunWithArgs() (e error) {
	return r.Run(os.Args[1:]...)<commit_msg>use standardized error for NoRouteError<commit_after>package cli

import (
	"fmt"
	"log"
	"os"
	"strings"
)

// Interface that must be implemented by actions. This is interface is used by the RegisterAction function. The Run
// method of the implementing type will be called if the given route matches it.
type Runner interface {
	Run() error
}

// Create a new router.
func NewRouter() *Router {
	r := &Router{}
	r.root = &routingTreeNode{children: map[string]*routingTreeNode{}}
	return r
}

var NoRouteError = fmt.Errorf("no route matched")

// 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 {
		log.Fatal("errors found during initialization")
	}
	// Find action and parse args.
	node, args := r.findNode(args, true)
	if node != nil && node.action != nil {
		if e := node.action.parseArgs(args); e != nil {
			node.showHelp()
			return e
		}
	} else { // Failed to find node.
		node.showHelp()
		return NoRouteError
	}

	return node.action.runner.Run()
}

// Run the arguments from the commandline (aka os.Args) against the registered actions, i.e. try to find a matching
// route and run the according action.
func (r *Router) RunWithArgs() (e error) {
	return r.Run(os.Args[1:]...)
{'fraction_non_alphanumeric': 0.12052368117058145, 'fraction_numerical': 0.0007701193685021178, 'mean_word_length': 3.541958041958042, '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': '3569430', 'n_tokens_mistral': 836, 'n_tokens_neox': 810, 'n_words': 320}