<commit_before>package main

import (
	"errors"
	"flag"
	"fmt"
	"strconv"
)

type TerminalClient struct {
	flags    *flag.FlagSet
	client   Client
	commands map[string]Command
}

type Command func() error

func NewTerminalClient(flags *flag.FlagSet, client Client) *TerminalClient {
	c := &TerminalClient{flags, client, make(map[string]Command)}
	c.commands["deploy"] = c.deployCmd
	c.commands["run"] = c.runCmd
	c.commands["list"] = c.listCmd
	c.commands["set"] = c.setCmd
	c.commands["help"] = c.helpCmd
	return c
}

func (c *TerminalClient) Run() error {
	cmdName := c.flags.Arg(0)
	if cmdName == "" {
		cmdName = "help"
	}
	cmd, ok := c.commands[cmdName]
	if !ok {
		fmt.Printf("Unknown command '%s'\n", cmdName)
		c.helpCmd()
		return nil
	}
	return cmd()
}

func (c *TerminalClient) helpCmd() error {
	fmt.Printf("usage: camus -mode [server|client] command args...\n\n")
	fmt.Printf("Available commands\n")
	for name, _ := range c.commands {
		fmt.Printf("  %s\n", name)
	}
	return nil
}

func (c *TerminalClient) deployCmd() error {
	_, err := c.client.Build()
	if err != nil {
		return err
	}

	deployId, err := c.client.Push()
	if err != nil {
		return err
	}
	fmt.Printf("Deployed '%s'\n", deployId)
	return nil
}

func (c *TerminalClient) runCmd() error {
	deployId := c.flags.Arg(1)
	if deployId == "" {
		return errors.New("Missing deploy id")
	}
	port, err := c.client.Run(deployId)
	if err != nil {
		return err
	}<commit_msg>Sort command names in help.<commit_after>package main

import (
	"errors"
	"flag"
	"fmt"
	"sort"
	"strconv"
)

type TerminalClient struct {
	flags    *flag.FlagSet
	client   Client
	commands map[string]Command
}

type Command func() error

func NewTerminalClient(flags *flag.FlagSet, client Client) *TerminalClient {
	c := &TerminalClient{flags, client, make(map[string]Command)}
	c.commands["deploy"] = c.deployCmd
	c.commands["run"] = c.runCmd
	c.commands["list"] = c.listCmd
	c.commands["set"] = c.setCmd
	c.commands["help"] = c.helpCmd
	return c
}

func (c *TerminalClient) Run() error {
	cmdName := c.flags.Arg(0)
	if cmdName == "" {
		cmdName = "help"
	}
	cmd, ok := c.commands[cmdName]
	if !ok {
		fmt.Printf("Unknown command '%s'\n", cmdName)
		c.helpCmd()
		return nil
	}
	return cmd()
}

func (c *TerminalClient) helpCmd() error {
	fmt.Printf("usage: camus -mode [server|client] command args...\n\n")
	fmt.Printf("Available commands\n")
	cmdNames := []string{}
	for name, _ := range c.commands {
		cmdNames = append(cmdNames, name)
	}
	sort.StringSlice(cmdNames).Sort()
	for _, name := range cmdNames {
		fmt.Printf("  %s\n", name)
	}
	return nil
}

func (c *TerminalClient) deployCmd() error {
	_, err := c.client.Build()
	if err != nil {
		return err
	}

	deployId, err := c.client.Push()
	if err != nil {
		return err
	}
	fmt.Printf("Deployed '%s'\n", deployId)
	return nil
}

func (c *TerminalClient) runCmd() error {
	deployId := c.flags.Arg(1)
	if deployId == "" {
		return errors.New("Missing deploy id")
	}
	port, err := c.client.Run(deployId)
	if err != nil {
		return err
	}
{'fraction_non_alphanumeric': 0.16342668863261944, 'fraction_numerical': 0.0013179571663920922, 'mean_word_length': 3.8343949044585988, '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': '1157838', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1155, 'n_words': 285}