<commit_before>package shell

import (
	"flag"
	"fmt"
	"github.com/peterh/liner"
	"os"
	"pfi/sensorbee/sensorbee/client"
	"strings"
)

// App is the application server of SensorBee.
type App struct {
	historyFn            string
	executeExternalFiles *string
	uri                  string
	commandMap           map[string]Command
}

// SetUpCommands set up application. Commands are initialized with it.
func SetUpCommands(commands []Command) App {
	app := App{
		historyFn:            "/tmp/.sensorbee_liner_history",
		executeExternalFiles: flag.String("file", "", "execute BQL commands from external files"),
		commandMap:           map[string]Command{},
	}
	if len(commands) == 0 {
		return app
	}

	for _, cmd := range commands {
		cmd.Init()
		for _, v := range cmd.Name() {
			app.commandMap[v] = cmd
		}
	}
	return app
}

func (a *App) prompt(line *liner.State) {
	input, err := line.Prompt(promptLineStart)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error reading line: %v", err)
		return
	}

	if input != "" {
		line.AppendHistory(input)

		if input == "exit" {
			fmt.Fprintln(os.Stdout, "SensorBee is closed")
			return
		}

		in := strings.ToLower(strings.Split(input, " ")[0])
		if cmd, ok := a.commandMap[in]; ok {
			status, err := cmd.Input(input)<commit_msg>deal with "exit" command not to distinguish upper/lower case<commit_after>package shell

import (
	"flag"
	"fmt"
	"github.com/peterh/liner"
	"os"
	"pfi/sensorbee/sensorbee/client"
	"strings"
)

// App is the application server of SensorBee.
type App struct {
	historyFn            string
	executeExternalFiles *string
	uri                  string
	commandMap           map[string]Command
}

// SetUpCommands set up application. Commands are initialized with it.
func SetUpCommands(commands []Command) App {
	app := App{
		historyFn:            "/tmp/.sensorbee_liner_history",
		executeExternalFiles: flag.String("file", "", "execute BQL commands from external files"),
		commandMap:           map[string]Command{},
	}
	if len(commands) == 0 {
		return app
	}

	for _, cmd := range commands {
		cmd.Init()
		for _, v := range cmd.Name() {
			app.commandMap[v] = cmd
		}
	}
	return app
}

func (a *App) prompt(line *liner.State) {
	input, err := line.Prompt(promptLineStart)
	if err != nil {
		fmt.Fprintf(os.Stderr, "error reading line: %v", err)
		return
	}

	if input != "" {
		line.AppendHistory(input)

		if strings.ToLower(input) == "exit" {
			fmt.Fprintln(os.Stdout, "SensorBee is closed")
			return
		}

		in := strings.ToLower(strings.Split(input, " ")[0])
		if cmd, ok := a.commandMap[in]; ok {
			status, err := cmd.Input(input)
{'fraction_non_alphanumeric': 0.13465952563121653, 'fraction_numerical': 0.001530221882172915, 'mean_word_length': 3.1573926868044517, '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': '3279307', 'n_tokens_mistral': 948, 'n_tokens_neox': 887, 'n_words': 231}