<commit_before>package main

import (
	"fmt"
	"github.com/calmh/mole/ansi"
	"github.com/calmh/mole/table"
	"github.com/jessevdk/go-flags"
	"regexp"
	"strings"
)

type cmdls struct {
	Long bool `short:"l" description:"Long listing"`
}

var lsParser *flags.Parser

func init() {
	cmd := cmdls{}
	lsParser = globalParser.AddCommand("ls", msgLsShort, msgLsLong, &cmd)
}

func (c *cmdls) Usage() string {
	return "[regexp]"
}

func (c *cmdls) Execute(args []string) error {
	setup()

	var re *regexp.Regexp
	var err error
	if len(args) == 1 {
		re, err = regexp.Compile("(?i)" + args[0])
		fatalErr(err)
	}

	cert := certificate()
	cl := NewClient(serverIni.address, cert)
	l := cl.List()

	var rows [][]string
	header := []string{"TUNNEL", "DESCRIPTION", "HOSTS"}
	if c.Long {
		header = append(header, "VER")
	}
	rows = append(rows, header)

	var matched int
	for _, i := range l {
		hosts := strings.Join(i.Hosts, ", ")
		if re == nil || re.MatchString(i.Name) || re.MatchString(i.Description) || re.MatchString(hosts) {
			matched++

			descr := i.Description
			if i.Vpnc {
				descr = descr + ansi.Magenta(" (vpnc)")
			} else if i.OpenConnect {
				descr = descr + ansi.Green(" (opnc)")
			} else if i.Socks {
				descr = descr + ansi.Yellow(" (socks)")
			}

			if hosts == "" {
				hosts = ansi.Faint("(local forward)")
			}

			row := []string{ansi.Bold(ansi.Blue(i.Name)), descr, hosts}
			if c.Long {
				row = append(row, fmt.Sprintf("%d", i.IntVersion))
			}
			rows = append(rows, row)
		}
	}

	// Never prefix table with log stuff
	fmt.Printf(table.Fmt("lllr", rows))

	if matched != len(l) {
		fmt.Printf(ansi.Faint(" - Matched %d out of %d records\n"), matched, len(l))
	}

	return nil
}<commit_msg>mole ls -s<commit_after>package main

import (
	"fmt"
	"github.com/calmh/mole/ansi"
	"github.com/calmh/mole/table"
	"github.com/jessevdk/go-flags"
	"regexp"
	"strings"
)

type cmdls struct {
	Long  bool `short:"l" description:"Long listing"`
	Short bool `short:"s" description:"Short listing (name only)"`
}

var lsParser *flags.Parser

func init() {
	cmd := cmdls{}
	lsParser = globalParser.AddCommand("ls", msgLsShort, msgLsLong, &cmd)
}

func (c *cmdls) Usage() string {
	return "[regexp]"
}

func (c *cmdls) Execute(args []string) error {
	setup()

	var re *regexp.Regexp
	var err error
	if len(args) == 1 {
		re, err = regexp.Compile("(?i)" + args[0])
		fatalErr(err)
	}

	cert := certificate()
	cl := NewClient(serverIni.address, cert)
	l := cl.List()

	var rows [][]string
	header := []string{"TUNNEL", "DESCRIPTION", "HOSTS"}
	if c.Long {
		header = append(header, "VER")
	}
	rows = append(rows, header)

	var matched int
	for _, i := range l {
		hosts := strings.Join(i.Hosts, ", ")
		if re == nil || re.MatchString(i.Name) || re.MatchString(i.Description) || re.MatchString(hosts) {
			if c.Short {
				fmt.Println(i.Name)
			} else {
				matched++
				descr := i.Description
				if i.Vpnc {
					descr = descr + ansi.Magenta(" (vpnc)")
				} else if i.OpenConnect {
					descr = descr + ansi.Green(" (opnc)")
				} else if i.Socks {
					descr = descr + ansi.Yellow(" (socks)")
				}

				if hosts == "" {
					hosts = ansi.Faint("(local forward)")
				}

				row := []string{ansi.Bold(ansi.Blue(i.Name)), descr, hosts}
				if c.Long {
					row = append(row, fmt.Sprintf("%d", i.IntVersion))
				}
				rows = append(rows, row)
			}
		}
	}

	if !c.Short {
		// Never prefix table with log stuff
		fmt.Printf(table.Fmt("lllr", rows))

		if matched != len(l) {
			fmt.Printf(ansi.Faint(" - Matched %d out of %d records\n"), matched, len(l))
		}
	}
	return nil
}
{'fraction_non_alphanumeric': 0.17872102764590897, 'fraction_numerical': 0.001117006422786931, 'mean_word_length': 3.2744630071599046, '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': '611404', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1411, 'n_words': 329}